40
namespace IODeviceJpegSourceManager {
41
namespace IODeviceJpegSourceManager
42
44
#define SOURCE_MANAGER_BUFFER_SIZE 4096
43
45
struct IODeviceJpegSourceManager : public jpeg_source_mgr {
45
JOCTET mBuffer[SOURCE_MANAGER_BUFFER_SIZE];
47
JOCTET mBuffer[SOURCE_MANAGER_BUFFER_SIZE];
49
static boolean fill_input_buffer(j_decompress_ptr cinfo) {
50
IODeviceJpegSourceManager* src = static_cast<IODeviceJpegSourceManager*>(cinfo->src);
51
Q_ASSERT(src->mIODevice);
52
int readSize = src->mIODevice->read((char*)src->mBuffer, SOURCE_MANAGER_BUFFER_SIZE);
54
src->next_input_byte = src->mBuffer;
55
src->bytes_in_buffer = readSize;
58
* JPEG file is broken. We feed the decoder with fake EOI, as specified
59
* in the libjpeg documentation.
61
static JOCTET fakeEOI[2] = { JOCTET(0xFF), JOCTET(JPEG_EOI)};
62
kWarning() << "Image is incomplete";
63
cinfo->src->next_input_byte = fakeEOI;
64
cinfo->src->bytes_in_buffer = 2;
70
static void init_source(j_decompress_ptr cinfo) {
71
fill_input_buffer(cinfo);
75
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
77
while (num_bytes > (long) cinfo->src->bytes_in_buffer) {
78
num_bytes -= (long) cinfo->src->bytes_in_buffer;
79
fill_input_buffer(cinfo);
81
* we assume that fill_input_buffer will never return FALSE, so
82
* suspension need not be handled.
85
cinfo->src->next_input_byte += (size_t) num_bytes;
86
cinfo->src->bytes_in_buffer -= (size_t) num_bytes;
91
static void term_source(j_decompress_ptr) {
95
void setup(j_decompress_ptr cinfo, QIODevice* ioDevice) {
96
Q_ASSERT(!cinfo->src);
97
IODeviceJpegSourceManager* src = (IODeviceJpegSourceManager*)
98
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
99
sizeof(IODeviceJpegSourceManager));
102
src->init_source = init_source;
103
src->fill_input_buffer = fill_input_buffer;
104
src->skip_input_data = skip_input_data;
105
src->resync_to_restart = jpeg_resync_to_restart;
106
src->term_source = term_source;
108
src->mIODevice = ioDevice;
50
static boolean fill_input_buffer(j_decompress_ptr cinfo)
52
IODeviceJpegSourceManager* src = static_cast<IODeviceJpegSourceManager*>(cinfo->src);
53
Q_ASSERT(src->mIODevice);
54
int readSize = src->mIODevice->read((char*)src->mBuffer, SOURCE_MANAGER_BUFFER_SIZE);
56
src->next_input_byte = src->mBuffer;
57
src->bytes_in_buffer = readSize;
60
* JPEG file is broken. We feed the decoder with fake EOI, as specified
61
* in the libjpeg documentation.
63
static JOCTET fakeEOI[2] = { JOCTET(0xFF), JOCTET(JPEG_EOI)};
64
kWarning() << "Image is incomplete";
65
cinfo->src->next_input_byte = fakeEOI;
66
cinfo->src->bytes_in_buffer = 2;
71
static void init_source(j_decompress_ptr cinfo)
73
fill_input_buffer(cinfo);
76
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
79
while (num_bytes > (long) cinfo->src->bytes_in_buffer) {
80
num_bytes -= (long) cinfo->src->bytes_in_buffer;
81
fill_input_buffer(cinfo);
83
* we assume that fill_input_buffer will never return FALSE, so
84
* suspension need not be handled.
87
cinfo->src->next_input_byte += (size_t) num_bytes;
88
cinfo->src->bytes_in_buffer -= (size_t) num_bytes;
92
static void term_source(j_decompress_ptr)
96
void setup(j_decompress_ptr cinfo, QIODevice* ioDevice)
98
Q_ASSERT(!cinfo->src);
99
IODeviceJpegSourceManager* src = (IODeviceJpegSourceManager*)
100
(*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT,
101
sizeof(IODeviceJpegSourceManager));
104
src->init_source = init_source;
105
src->fill_input_buffer = fill_input_buffer;
106
src->skip_input_data = skip_input_data;
107
src->resync_to_restart = jpeg_resync_to_restart;
108
src->term_source = term_source;
110
src->mIODevice = ioDevice;
112
113
} // IODeviceJpegSourceManager namespace
113
114
} // Gwenview namespace