-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJpegDecoder.h
54 lines (41 loc) · 1.41 KB
/
JpegDecoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <jpeglib.h>
namespace DStream
{
class JpegDecoder
{
public:
JpegDecoder();
~JpegDecoder();
JpegDecoder(const JpegDecoder&) = delete;
void operator=(const JpegDecoder&) = delete;
//JCS_GRAYSCALE, JCS_RGB, JCS_YCbCr, or JCS_CMYK.
void setColorSpace(J_COLOR_SPACE space);
void setJpegColorSpace(J_COLOR_SPACE colorSpace);
J_COLOR_SPACE getColorSpace() const;
bool decode(uint8_t* buffer, size_t len, uint8_t*& img, int& width, int& height);
bool decode(const char* path, uint8_t*& img, int& width, int& height);
bool decodeNonAlloc(const char* path, uint8_t* buffer, int& width, int& height);
bool decode(FILE* file, uint8_t*& img, int& width, int& height);
//file streaming reading support
bool init(const char* path, int& width, int& height);
size_t rowSize() { return decInfo.image_width * decInfo.num_components; }
//buffer must have rows*rowSize() space at least!
size_t readRows(int rows, uint8_t* buffer); //return false on end.
bool finish();
bool restart();
bool chromaSubsampled() { return subsampled; }
private:
FILE* file = nullptr;
bool init(int& width, int& height);
bool decode(uint8_t*& img, int& width, int& height);
jpeg_decompress_struct decInfo;
jpeg_error_mgr errMgr;
J_COLOR_SPACE colorSpace = JCS_RGB;
J_COLOR_SPACE jpegColorSpace = JCS_YCbCr;
bool subsampled = false;
};
}