27 const unsigned char *
buffer,
35 const size_t bits_size,
37 const size_t val_size)
39 if (*htblptr ==
NULL) {
40 *htblptr = jpeg_alloc_huff_table((j_common_ptr)dinfo);
43 memcpy((*htblptr)->bits, bits,
min_zz(
sizeof((*htblptr)->bits), bits_size));
44 memcpy((*htblptr)->huffval, val,
min_zz(
sizeof((*htblptr)->huffval), val_size));
47 (*htblptr)->sent_table =
false;
55 static const UINT8 bits_dc_luminance[17] = {
75 static const UINT8 val_dc_luminance[] = {
90 static const UINT8 bits_dc_chrominance[17] = {
110 static const UINT8 val_dc_chrominance[] = {
125 static const UINT8 bits_ac_luminance[17] = {
145 static const UINT8 val_ac_luminance[] = {
146 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61,
147 0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08, 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52,
148 0xd1, 0xf0, 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x25,
149 0x26, 0x27, 0x28, 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44, 0x45,
150 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63, 0x64,
151 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a, 0x83,
152 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
153 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
154 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3,
155 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8,
156 0xe9, 0xea, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
158 static const UINT8 bits_ac_chrominance[17] = {
178 static const UINT8 val_ac_chrominance[] = {
179 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61,
180 0x71, 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91, 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33,
181 0x52, 0xf0, 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34, 0xe1, 0x25, 0xf1, 0x17, 0x18,
182 0x19, 0x1a, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x43, 0x44,
183 0x45, 0x46, 0x47, 0x48, 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5a, 0x63,
184 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7a,
185 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
186 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
187 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca,
188 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
189 0xe8, 0xe9, 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa,
193 &dinfo->dc_huff_tbl_ptrs[0],
195 sizeof(bits_dc_luminance),
197 sizeof(val_dc_luminance));
199 &dinfo->ac_huff_tbl_ptrs[0],
201 sizeof(bits_ac_luminance),
203 sizeof(val_ac_luminance));
205 &dinfo->dc_huff_tbl_ptrs[1],
207 sizeof(bits_dc_chrominance),
209 sizeof(val_dc_chrominance));
211 &dinfo->ac_huff_tbl_ptrs[1],
213 sizeof(bits_ac_chrominance),
215 sizeof(val_ac_chrominance));
219 unsigned char *outBuffer,
224 struct jpeg_decompress_struct dinfo;
225 struct jpeg_error_mgr jerr;
231 dinfo.err = jpeg_std_error(&jerr);
232 jpeg_create_decompress(&dinfo);
234 jpeg_read_header(&dinfo,
true);
235 if (dinfo.dc_huff_tbl_ptrs[0] ==
NULL) {
238 dinfo.out_color_space = JCS_RGB;
239 dinfo.dct_method = JDCT_IFAST;
241 jpeg_start_decompress(&dinfo);
243 size_t rowstride = dinfo.output_width * dinfo.output_components;
244 for (
size_t y = 0;
y < dinfo.output_height;
y++) {
245 jpeg_read_scanlines(&dinfo, (JSAMPARRAY)&outBuffer, 1);
246 outBuffer += rowstride;
248 jpeg_finish_decompress(&dinfo);
250 if (dinfo.output_height >=
height) {
258 jpeg_read_header(&dinfo,
true);
259 if (dinfo.dc_huff_tbl_ptrs[0] ==
NULL) {
263 jpeg_start_decompress(&dinfo);
264 rowstride = dinfo.output_width * dinfo.output_components;
265 for (
size_t y = 0;
y < dinfo.output_height;
y++) {
266 jpeg_read_scanlines(&dinfo, (JSAMPARRAY)&outBuffer, 1);
267 outBuffer += rowstride;
269 jpeg_finish_decompress(&dinfo);
270 jpeg_destroy_decompress(&dinfo);
276 unsigned char *outbuffer,
277 const unsigned char *inBuffer,
282 struct jpeg_compress_struct cinfo;
283 struct jpeg_error_mgr jerr;
284 unsigned char marker[60];
286 cinfo.err = jpeg_std_error(&jerr);
287 jpeg_create_compress(&cinfo);
290 cinfo.image_width =
width;
291 cinfo.image_height =
height;
292 cinfo.input_components = 3;
293 cinfo.in_color_space = JCS_RGB;
295 jpeg_set_defaults(&cinfo);
296 jpeg_set_colorspace(&cinfo, JCS_YCbCr);
298 jpeg_set_quality(&cinfo, quality,
true);
300 cinfo.dc_huff_tbl_ptrs[0]->sent_table =
true;
301 cinfo.dc_huff_tbl_ptrs[1]->sent_table =
true;
302 cinfo.ac_huff_tbl_ptrs[0]->sent_table =
true;
303 cinfo.ac_huff_tbl_ptrs[1]->sent_table =
true;
305 cinfo.comp_info[0].component_id = 0;
306 cinfo.comp_info[0].v_samp_factor = 1;
307 cinfo.comp_info[1].component_id = 1;
308 cinfo.comp_info[2].component_id = 2;
310 cinfo.write_JFIF_header =
false;
312 jpeg_start_compress(&cinfo,
false);
324 jpeg_write_marker(&cinfo, JPEG_APP0, marker, 60);
331 jpeg_write_marker(&cinfo, JPEG_COM, marker, 60);
333 size_t rowstride = cinfo.image_width * cinfo.input_components;
334 for (
size_t y = 0;
y < cinfo.image_height;
y++) {
335 jpeg_write_scanlines(&cinfo, (JSAMPARRAY)&inBuffer, 1);
336 inBuffer += rowstride;
338 jpeg_finish_compress(&cinfo);
339 jpeg_destroy_compress(&cinfo);
344 size_t i, rowstride =
width * 3;
346 for (i = 0; i <
height; i++) {
348 memcpy(&to[i * rowstride], &
from[(i / 2 +
height / 2) * rowstride], rowstride);
351 memcpy(&to[i * rowstride], &
from[(i / 2) * rowstride], rowstride);
358 size_t i, rowstride =
width * 3;
360 for (i = 0; i <
height; i++) {
361 if ((i & 1) == odd) {
362 memcpy(&to[(i / 2 +
height / 2) * rowstride], &
from[i * rowstride], rowstride);
365 memcpy(&to[(i / 2) * rowstride], &
from[i * rowstride], rowstride);
383 sizeof(
unsigned char),
384 "avi.avi_converter_from_mjpeg 1");
397 sizeof(
unsigned char),
398 "avi.avi_converter_from_mjpeg 2");
413 size_t bufsize = *
size;
421 sizeof(
unsigned char),
422 "avi.avi_converter_to_mjpeg 1");
444 sizeof(
unsigned char),
445 "avi.avi_converter_to_mjpeg 1");
486 numbytes -= cinfo->dest->free_in_buffer;
493 cinfo->dest =
MEM_mallocN(
sizeof(*(cinfo->dest)),
"avi.jpegmemdestmgr_build");
499 cinfo->dest->next_output_byte =
buffer;
500 cinfo->dest->free_in_buffer = bufsize;
514 unsigned char *buf = (
unsigned char *)dinfo->src->next_input_byte - 2;
517 WARNMS(dinfo, JWRN_JPEG_EOF);
519 buf[0] = (JOCTET)0xFF;
520 buf[1] = (JOCTET)JPEG_EOI;
522 dinfo->src->next_input_byte = buf;
523 dinfo->src->bytes_in_buffer = 2;
530 if (dinfo->src->bytes_in_buffer < skip_count) {
531 skip_count = dinfo->src->bytes_in_buffer;
534 dinfo->src->next_input_byte += skip_count;
535 dinfo->src->bytes_in_buffer -= skip_count;
540 numbytes -= dinfo->src->bytes_in_buffer;
546 const unsigned char *
buffer,
549 dinfo->src =
MEM_mallocN(
sizeof(*(dinfo->src)),
"avi.jpegmemsrcmgr_build");
554 dinfo->src->resync_to_restart = jpeg_resync_to_restart;
557 dinfo->src->bytes_in_buffer = bufsize;
558 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 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
_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
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_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 jpegmemsrcmgr_skip_input_data(j_decompress_ptr dinfo, long skip_count)
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)
SyclQueue void void size_t num_bytes void
ccl_global float * buffer
void(* MEM_freeN)(void *vmemh)
void *(* MEM_mallocN)(size_t len, const char *str)