libjpeg ycc_rgb_convert memory error
Dec 4, 2008 at 5:54pm UTC
I've been trying to get libjpeg working in my project. So far I have sucsessfully compiled it and it's sample programs, however, I get problems running my own code.
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
FILE* input_file;
JDIMENSION num_scanlines;
int file_index;
djpeg_dest_ptr dest_mgr = NULL;
struct jpeg_decompress_struct cinfo;
struct jpeg_error_mgr jerr;
cinfo.err = jpeg_std_error(&jerr);
jpeg_create_decompress(&cinfo);
if ((input_file = fopen("C:\\OpenGL\\Projects\\Debug\\Data\\testimg.jpg" , "rb" )) == NULL) {
return 10;
}
jpeg_stdio_src(&cinfo, input_file);
jpeg_read_header(&cinfo, TRUE);
jpeg_start_decompress(&cinfo);
JSAMPLE * buffer = new JSAMPLE[cinfo.output_width*cinfo.output_components*cinfo.output_height];
/* Process data */
while (cinfo.output_scanline < cinfo.output_height) {
num_scanlines = jpeg_read_scanlines(&cinfo,(JSAMPARRAY) buffer,cinfo.output_height);
}
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
//END
The runtime error is generated in this function, line marked by a comment
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
METHODDEF(void )
ycc_rgb_convert (j_decompress_ptr cinfo,
JSAMPIMAGE input_buf, JDIMENSION input_row,
JSAMPARRAY output_buf, int num_rows)
{
my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
register int y, cb, cr;
register JSAMPROW outptr;
register JSAMPROW inptr0, inptr1, inptr2;
register JDIMENSION col;
JDIMENSION num_cols = cinfo->output_width;
/* copy these pointers into registers if possible */
register JSAMPLE * range_limit = cinfo->sample_range_limit;
register int * Crrtab = cconvert->Cr_r_tab;
register int * Cbbtab = cconvert->Cb_b_tab;
register INT32 * Crgtab = cconvert->Cr_g_tab;
register INT32 * Cbgtab = cconvert->Cb_g_tab;
SHIFT_TEMPS
while (--num_rows >= 0) {
inptr0 = input_buf[0][input_row];
inptr1 = input_buf[1][input_row];
inptr2 = input_buf[2][input_row];
input_row++;
outptr = *output_buf++;
for (col = 0; col < num_cols; col++) {
y = GETJSAMPLE(inptr0[col]);
cb = GETJSAMPLE(inptr1[col]);
cr = GETJSAMPLE(inptr2[col]);
/* Range-limiting is essential due to noise introduced by DCT losses. */
outptr[RGB_RED] = range_limit[y + Crrtab[cr]];//<-memory access violation here; somthing is wrong with outptr!
outptr[RGB_GREEN] = range_limit[y +
((int ) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
SCALEBITS))];
outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
outptr += RGB_PIXELSIZE;
}
}
}
I have no clue how to solve this problem, any help would be much apprechiated!
Thanks,
Gregor
Topic archived. No new replies allowed.