| 1 |
#ifndef _ANDROID_GRAPHICS_YUV_TO_JPEG_ENCODER_H_ |
| 2 |
#define _ANDROID_GRAPHICS_YUV_TO_JPEG_ENCODER_H_ |
| 3 |
|
| 4 |
#include "SkTypes.h" |
| 5 |
#include "SkStream.h" |
| 6 |
extern "C" { |
| 7 |
#include "jpeglib.h" |
| 8 |
#include "jerror.h" |
| 9 |
} |
| 10 |
|
| 11 |
class YuvToJpegEncoder { |
| 12 |
public: |
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
static YuvToJpegEncoder* create(int pixelFormat, int* strides); |
| 20 |
|
| 21 |
explicit YuvToJpegEncoder(int* strides); |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
bool encode(SkWStream* stream, void* inYuv, int width, |
| 34 |
int height, int* offsets, int jpegQuality); |
| 35 |
|
| 36 |
virtual ~YuvToJpegEncoder() {} |
| 37 |
|
| 38 |
protected: |
| 39 |
int fNumPlanes; |
| 40 |
int* fStrides; |
| 41 |
void setJpegCompressStruct(jpeg_compress_struct* cinfo, int width, |
| 42 |
int height, int quality); |
| 43 |
virtual void configSamplingFactors(jpeg_compress_struct* cinfo) = 0; |
| 44 |
virtual void compress(jpeg_compress_struct* cinfo, |
| 45 |
uint8_t* yuv, int* offsets) = 0; |
| 46 |
}; |
| 47 |
|
| 48 |
class Yuv420SpToJpegEncoder : public YuvToJpegEncoder { |
| 49 |
public: |
| 50 |
explicit Yuv420SpToJpegEncoder(int* strides); |
| 51 |
virtual ~Yuv420SpToJpegEncoder() {} |
| 52 |
|
| 53 |
private: |
| 54 |
void configSamplingFactors(jpeg_compress_struct* cinfo); |
| 55 |
void deinterleaveYuv(uint8_t* yuv, int width, int height, |
| 56 |
uint8_t*& yPlanar, uint8_t*& uPlanar, uint8_t*& vPlanar); |
| 57 |
void deinterleave(uint8_t* vuPlanar, uint8_t* uRows, uint8_t* vRows, |
| 58 |
int rowIndex, int width, int height); |
| 59 |
void compress(jpeg_compress_struct* cinfo, uint8_t* yuv, int* offsets); |
| 60 |
}; |
| 61 |
|
| 62 |
class Yuv422IToJpegEncoder : public YuvToJpegEncoder { |
| 63 |
public: |
| 64 |
explicit Yuv422IToJpegEncoder(int* strides); |
| 65 |
virtual ~Yuv422IToJpegEncoder() {} |
| 66 |
|
| 67 |
private: |
| 68 |
void configSamplingFactors(jpeg_compress_struct* cinfo); |
| 69 |
void compress(jpeg_compress_struct* cinfo, uint8_t* yuv, int* offsets); |
| 70 |
void deinterleave(uint8_t* yuv, uint8_t* yRows, uint8_t* uRows, |
| 71 |
uint8_t* vRows, int rowIndex, int width, int height); |
| 72 |
}; |
| 73 |
|
| 74 |
#endif |