00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef JPEGEncoder_h_DEFINED
00013 #define JPEGEncoder_h_DEFINED
00014
00015 #include <list>
00016 using std::list;
00017 #include <OPENR/ODataFormats.h>
00018 #include <ant.h>
00019
00020 class JPEGEncoder {
00021 public:
00022 JPEGEncoder();
00023 ~JPEGEncoder() {}
00024
00025 bool Init(const antStackRef& ipstack);
00026 bool GetJPEG(OFbkImageVectorData* imageVec,
00027 OFbkImageLayer layer, bool reconstruction,
00028 int quality, byte** jpeg, int* size);
00029 void FreeJPEG(byte* jpeg);
00030
00031
00032 void Save(OFbkImageVectorData* imageVec,
00033 OFbkImageLayer layer, int quality, char* path);
00034
00035 static const int NUM_JPEG_BUF = 4;
00036
00037 private:
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 static const int IMAGE_BUFSIZE = 3*(2*208)*(2*160);
00050 static const int JPEG_BUFSIZE = 64*1024;
00051 byte* Allocate();
00052 void Free(byte* buf);
00053
00054 void ConvertYCbCr(OFbkImageVectorData* imageVec,
00055 OFbkImageLayer layer, byte* image,
00056 int* width, int* height);
00057 void ReconstructAndConvertYCbCr(OFbkImageVectorData* imageVec,
00058 OFbkImageLayer layer, byte* image,
00059 int* width, int* height);
00060
00061 void PutYCbCrPixel(byte* img, int w,
00062 int x, int y, byte ypix, byte cb, byte cr) {
00063 byte* ptr = img + 3 * (w * y + x);
00064 ptr[0] = ypix;
00065 ptr[1] = cb;
00066 ptr[2] = cr;
00067 }
00068
00069 byte ClipRange(int val) {
00070 if (val < 0) { return 0; }
00071 else if (val > 255) { return 255; }
00072 else { return (byte)val; }
00073 }
00074
00075 antStackRef ipstackRef;
00076 byte* pixelInterleavedYCbCr;
00077 antSharedBuffer jpegBuf[NUM_JPEG_BUF];
00078 list<byte*> freeJpegBufList;
00079 };
00080
00081 #endif // JPEGEncoder_h_DEFINED