43 const unsigned char *
buffer,
51 const size_t bits_size,
53 const size_t val_size)
55 if (*htblptr ==
NULL) {
56 *htblptr = jpeg_alloc_huff_table((j_common_ptr)dinfo);
59 memcpy((*htblptr)->bits, bits,
min_zz(
sizeof((*htblptr)->bits), bits_size));
60 memcpy((*htblptr)->huffval, val,
min_zz(
sizeof((*htblptr)->huffval), val_size));
63 (*htblptr)->sent_table =
false;
71 static const UINT8 bits_dc_luminance[17] = {
91 static const UINT8 val_dc_luminance[] = {
106 static const UINT8 bits_dc_chrominance[17] = {
126 static const UINT8 val_dc_chrominance[] = {
141 static const UINT8 bits_ac_luminance[17] = {
161 static const UINT8 val_ac_luminance[] = {
162 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61,
163 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52,
164 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25,
165 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,
166 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64,
167 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83,
168 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
169 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
170 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3,
171 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8,
172 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
174 static const UINT8 bits_ac_chrominance[17] = {
194 static const UINT8 val_ac_chrominance[] = {
195 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61,
196 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33,
197 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18,
198 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44,
199 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63,
200 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
201 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
202 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
203 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca,
204 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
205 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
209 &dinfo->dc_huff_tbl_ptrs[0],
211 sizeof(bits_dc_luminance),
213 sizeof(val_dc_luminance));
215 &dinfo->ac_huff_tbl_ptrs[0],
217 sizeof(bits_ac_luminance),
219 sizeof(val_ac_luminance));
221 &dinfo->dc_huff_tbl_ptrs[1],
223 sizeof(bits_dc_chrominance),
225 sizeof(val_dc_chrominance));
227 &dinfo->ac_huff_tbl_ptrs[1],
229 sizeof(bits_ac_chrominance),
231 sizeof(val_ac_chrominance));
235 unsigned char *outBuffer,
240 struct jpeg_decompress_struct dinfo;
241 struct jpeg_error_mgr jerr;
247 dinfo.err = jpeg_std_error(&jerr);
248 jpeg_create_decompress(&dinfo);
250 jpeg_read_header(&dinfo,
true);
251 if (dinfo.dc_huff_tbl_ptrs[0] ==
NULL) {
254 dinfo.out_color_space = JCS_RGB;
255 dinfo.dct_method = JDCT_IFAST;
257 jpeg_start_decompress(&dinfo);
259 size_t rowstride = dinfo.output_width * dinfo.output_components;
260 for (
size_t y = 0;
y < dinfo.output_height;
y++) {
261 jpeg_read_scanlines(&dinfo, (JSAMPARRAY)&outBuffer, 1);
262 outBuffer += rowstride;
264 jpeg_finish_decompress(&dinfo);
266 if (dinfo.output_height >=
height) {
274 jpeg_read_header(&dinfo,
true);
275 if (dinfo.dc_huff_tbl_ptrs[0] ==
NULL) {
279 jpeg_start_decompress(&dinfo);
280 rowstride = dinfo.output_width * dinfo.output_components;
281 for (
size_t y = 0;
y < dinfo.output_height;
y++) {
282 jpeg_read_scanlines(&dinfo, (JSAMPARRAY)&outBuffer, 1);
283 outBuffer += rowstride;
285 jpeg_finish_decompress(&dinfo);
286 jpeg_destroy_decompress(&dinfo);
292 unsigned char *outbuffer,
293 const unsigned char *inBuffer,
298 struct jpeg_compress_struct cinfo;
299 struct jpeg_error_mgr jerr;
300 unsigned char marker[60];
302 cinfo.err = jpeg_std_error(&jerr);
303 jpeg_create_compress(&cinfo);
306 cinfo.image_width =
width;
307 cinfo.image_height =
height;
308 cinfo.input_components = 3;
309 cinfo.in_color_space = JCS_RGB;
311 jpeg_set_defaults(&cinfo);
312 jpeg_set_colorspace(&cinfo, JCS_YCbCr);
314 jpeg_set_quality(&cinfo, quality,
true);
316 cinfo.dc_huff_tbl_ptrs[0]->sent_table =
true;
317 cinfo.dc_huff_tbl_ptrs[1]->sent_table =
true;
318 cinfo.ac_huff_tbl_ptrs[0]->sent_table =
true;
319 cinfo.ac_huff_tbl_ptrs[1]->sent_table =
true;
321 cinfo.comp_info[0].component_id = 0;
322 cinfo.comp_info[0].v_samp_factor = 1;
323 cinfo.comp_info[1].component_id = 1;
324 cinfo.comp_info[2].component_id = 2;
326 cinfo.write_JFIF_header =
false;
328 jpeg_start_compress(&cinfo,
false);
340 jpeg_write_marker(&cinfo, JPEG_APP0, marker, 60);
347 jpeg_write_marker(&cinfo, JPEG_COM, marker, 60);
349 size_t rowstride = cinfo.image_width * cinfo.input_components;
350 for (
size_t y = 0;
y < cinfo.image_height;
y++) {
351 jpeg_write_scanlines(&cinfo, (JSAMPARRAY)&inBuffer, 1);
352 inBuffer += rowstride;
354 jpeg_finish_compress(&cinfo);
355 jpeg_destroy_compress(&cinfo);
360 size_t i, rowstride =
width * 3;
362 for (i = 0; i <
height; i++) {
364 memcpy(&to[i * rowstride], &
from[(i / 2 +
height / 2) * rowstride], rowstride);
367 memcpy(&to[i * rowstride], &
from[(i / 2) * rowstride], rowstride);
374 size_t i, rowstride =
width * 3;
376 for (i = 0; i <
height; i++) {
377 if ((i & 1) == odd) {
378 memcpy(&to[(i / 2 +
height / 2) * rowstride], &
from[i * rowstride], rowstride);
381 memcpy(&to[(i / 2) * rowstride], &
from[i * rowstride], rowstride);
399 sizeof(
unsigned char),
400 "avi.avi_converter_from_mjpeg 1");
413 sizeof(
unsigned char),
414 "avi.avi_converter_from_mjpeg 2");
429 size_t bufsize = *
size;
437 sizeof(
unsigned char),
438 "avi.avi_converter_to_mjpeg 1");
460 sizeof(
unsigned char),
461 "avi.avi_converter_to_mjpeg 1");
502 numbytes -= cinfo->dest->free_in_buffer;
509 cinfo->dest =
MEM_mallocN(
sizeof(*(cinfo->dest)),
"avi.jpegmemdestmgr_build");
515 cinfo->dest->next_output_byte =
buffer;
516 cinfo->dest->free_in_buffer = bufsize;
530 unsigned char *buf = (
unsigned char *)dinfo->src->next_input_byte - 2;
533 WARNMS(dinfo, JWRN_JPEG_EOF);
535 buf[0] = (JOCTET)0xFF;
536 buf[1] = (JOCTET)JPEG_EOI;
538 dinfo->src->next_input_byte = buf;
539 dinfo->src->bytes_in_buffer = 2;
546 if (dinfo->src->bytes_in_buffer < skipcnt) {
547 skipcnt = dinfo->src->bytes_in_buffer;
550 dinfo->src->next_input_byte += skipcnt;
551 dinfo->src->bytes_in_buffer -= skipcnt;
556 numbytes -= dinfo->src->bytes_in_buffer;
562 const unsigned char *
buffer,
565 dinfo->src =
MEM_mallocN(
sizeof(*(dinfo->src)),
"avi.jpegmemsrcmgr_build");
570 dinfo->src->resync_to_restart = jpeg_resync_to_restart;
573 dinfo->src->bytes_in_buffer = bufsize;
574 dinfo->src->next_input_byte =
buffer;
MINLINE size_t min_zz(size_t a, size_t b)
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei width
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei height
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
void * imb_alloc_pixels(unsigned int x, unsigned int y, unsigned int channels, size_t typesize, const char *name)
Read Guarded memory(de)allocation.
void * avi_converter_to_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, size_t *size)
static int Decode_JPEG(unsigned char *inBuffer, unsigned char *outBuffer, unsigned int width, unsigned int height, size_t bufsize)
static void jpegmemdestmgr_init_destination(j_compress_ptr cinfo)
static void jpegmemdestmgr_term_destination(j_compress_ptr cinfo)
static boolean jpegmemsrcmgr_fill_input_buffer(j_decompress_ptr dinfo)
static void jpegmemsrcmgr_term_source(j_decompress_ptr dinfo)
static boolean jpegmemdestmgr_empty_output_buffer(j_compress_ptr cinfo)
static void jpegmemdestmgr_build(j_compress_ptr cinfo, unsigned char *buffer, size_t bufsize)
static void Compress_JPEG(int quality, unsigned char *outbuffer, const unsigned char *inBuffer, int width, int height, size_t bufsize)
static void std_huff_tables(j_decompress_ptr dinfo)
static void jpegmemsrcmgr_skip_input_data(j_decompress_ptr dinfo, long skipcnt)
static void jpegmemsrcmgr_build(j_decompress_ptr dinfo, const unsigned char *buffer, size_t bufsize)
static void jpegmemsrcmgr_init_source(j_decompress_ptr dinfo)
static void add_huff_table(j_decompress_ptr dinfo, JHUFF_TBL **htblptr, const UINT8 *bits, const size_t bits_size, const UINT8 *val, const size_t val_size)
static void interlace(unsigned char *to, unsigned char *from, int width, int height)
static void deinterlace(int odd, unsigned char *to, unsigned char *from, int width, int height)
void * avi_converter_from_mjpeg(AviMovie *movie, int stream, unsigned char *buffer, const size_t *size)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)