00001 #ifndef Impala_Core_VideoSet_ExportFrames_h
00002 #define Impala_Core_VideoSet_ExportFrames_h
00003
00004 #include "Persistency/ImageArchiveRepository.h"
00005 #include "Persistency/FrameRepository.h"
00006 #include "Core/Array/ImageArchiveMemory.h"
00007 #include "Core/Array/WritePng.h"
00008 #include "Core/Array/WriteJpg.h"
00009 #include "Core/Array/Scale.h"
00010 #include "Core/VideoSet/Reporter.h"
00011
00012 namespace Impala
00013 {
00014 namespace Core
00015 {
00016 namespace VideoSet
00017 {
00018
00019
00020 class ExportFrames : public Listener
00021 {
00022 public:
00023
00024 ExportFrames(Reporter* reporter, CmdOptions& options)
00025 {
00026 mReporter = reporter;
00027 mSplitArchive = false;
00028 if (options.GetNrArg() > 2)
00029 if (options.GetArg(2) == "split")
00030 mSplitArchive = true;
00031 mJpg = false;
00032 if (options.GetNrArg() > 3)
00033 if (options.GetArg(3) == "jpg")
00034 mJpg = true;
00035 mScale = 1.0;
00036 if (options.GetNrArg() > 4)
00037 mScale = atof(options.GetArg(4));
00038 ILOG_INFO("scale = " << mScale);
00039 if (options.GetNrArg() > 5)
00040 Core::Array::gWriteJpgQuality = atol(options.GetArg(5));
00041 mBuf = 0;
00042 if (mSplitArchive)
00043 {
00044 mReporter->SetReportArray(false);
00045 mBufSize = 10000000;
00046 mBuf = new char[mBufSize];
00047 }
00048 }
00049
00050 virtual
00051 ~ExportFrames()
00052 {
00053 if (mBuf)
00054 delete mBuf;
00055 }
00056
00057 virtual void
00058 HandleNewFrame(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00059 {
00060 HandleNewFrame(vs, fileId, src, Geometry::Rectangle(), "");
00061 }
00062
00063 virtual void
00064 HandleNewFrame(VideoSet* vs, int fileId, Stream::RgbDataSrc* src,
00065 Geometry::Rectangle rect, String anno)
00066 {
00067 typedef Array::Array2dVec3UInt8 ArrayT;
00068 ArrayT* im = Array::ArrayCreate<ArrayT>
00069 (src->FrameWidth(), src->FrameHeight(), 0, 0, src->DataPtr(), true);
00070 if (mSplitArchive)
00071 {
00072 size_t nrBytes = 0;
00073 if (mJpg)
00074 {
00075 ArrayT* sc = 0;
00076 Array::Scale(sc, im, mScale, mScale, Geometry::NEAREST, true);
00077 Array::WriteJpgToMemory(sc, mBuf, mBufSize, &nrBytes);
00078 delete sc;
00079 }
00080 else
00081 {
00082 Array::WritePngToMemory(im, mBuf, mBufSize, &nrBytes);
00083 }
00084 Array::Array2dScalarUInt8* data =
00085 Array::MakeFromData<Array::Array2dScalarUInt8>((UInt8*) mBuf,
00086 nrBytes, 1);
00087 mImList.push_back(data);
00088 }
00089 else
00090 {
00091 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00092 String fName = vs->GetFilePathFrames(fileId, src->FrameNr(),
00093 ".png", true, false);
00094 if (fName.empty())
00095 {
00096 ILOG_ERROR("HandleNewFrame : Empty filename");
00097 }
00098 else
00099 {
00100 Array::WritePng(im, fName, vs->GetDatabase());
00101 }
00102 #else // REPOSITORY_USED
00103 String container = vs->GetContainerFile(fileId);
00104 Persistency::FrameLocator loc(vs->GetLocator(), container,
00105 src->FrameNr(), ".png");
00106 Persistency::FrameRepository().Add(loc, im);
00107 #endif // REPOSITORY_USED
00108 }
00109 delete im;
00110 }
00111
00112 virtual void
00113 HandleDoneFile(VideoSet* vs, int fileId, Stream::RgbDataSrc* src)
00114 {
00115 if (!mSplitArchive)
00116 return;
00117
00118 String fName = (mJpg) ? "images_jpg.raw" : "images.raw";
00119 #ifndef REPOSITORY_USED // Here comes the deprecated stuff
00120 fName = vs->GetFilePathFrames(fileId, fName, true, false);
00121 Array::WriteRawListVar(mImList, fName, vs->GetDatabase(), true, true);
00122 #else // REPOSITORY_USED
00123 String container = vs->GetContainerFile(fileId);
00124 Persistency::ImageArchiveLocator loc(vs->GetLocator(), true, container,
00125 fName, 0);
00126 Array::ImageArchiveMemory wrapper(&mImList);
00127 Persistency::ImageArchiveRepository().Add(loc, &wrapper);
00128 #endif // REPOSITORY_USED
00129 Array::ArrayListDelete(&mImList);
00130 }
00131
00132 private:
00133
00134 Reporter* mReporter;
00135 bool mSplitArchive;
00136 bool mJpg;
00137 double mScale;
00138 int mBufSize;
00139 char* mBuf;
00140 std::vector<Array::Array2dScalarUInt8*> mImList;
00141
00142 ILOG_VAR_DEC;
00143 };
00144
00145 ILOG_VAR_INIT(ExportFrames, Impala.Core.VideoSet);
00146
00147 }
00148 }
00149 }
00150
00151 #endif