This is my function:
Code:
int JPEG_read_file_rgb2hsv( unsigned char ** image_buffer, struct jpeg_decompress_struct * cDecompresInfo)
{
JSAMPARRAY rows_buffer; // Output row rows_buffer
int row_stride_len;
// @TODO: row_stride_len
row_stride_len = 512;//*cDecompresInfo.output_width * cDecompresInfo.output_components;
rows_buffer = (*(*cDecompresInfo).mem->alloc_sarray)
((j_common_ptr) &*cDecompresInfo, JPOOL_IMAGE, row_stride_len, 1);
// 6) Initiate image_buffer
size_t counter=0;
size_t raw_size = row_stride_len;
printf("raw size:%d\n",row_stride_len*
((*cDecompresInfo).output_height));
*image_buffer = (unsigned char*) malloc( row_stride_len*
((*cDecompresInfo).output_height) );
/******************************
RGB 2 HSV
******************************/
float R, G, B, H, S, V,min, max, delta;
H=S=V=0;
int t;
while ((*cDecompresInfo).output_scanline < (*cDecompresInfo).output_height) {
(void) jpeg_read_scanlines(&*cDecompresInfo, rows_buffer, 1);
for( t=0; t<row_stride_len ; t=t+3)
{
R=(float) rows_buffer[0][t];
G=(float) rows_buffer[0][t+1];
B=(float) rows_buffer[0][t+2];
min = (B < G) ? ((R < B) ? R : B) : (R < G ? R : G);
max = (B > G) ? ((R > B) ? R : B) : (R > G ? R : G);
V = max;
delta = max - min;
if( max != 0 )
S = delta / max;
else {
S = 0;
H = -1;
continue;
}
if( R == max )
H = ( G - B ) / delta; // between yellow & magenta
else if( G == max )
H = 2 + ( B - R ) / delta; // between cyan & yellow
else
H = 4 + ( R - G ) / delta; // between magenta & cyan
H *= 60; // degrees
if( H < 0 )
H += 360;
// Must perform the conversion to 3 bytes data
// Is it exact?
(*image_buffer)[counter+t]=(unsigned char)((H*100)/255);
(*image_buffer)[counter+t+1]=(unsigned char)(S*100);
(*image_buffer)[counter+t+2]=(unsigned char)V;
}
// memcpy(image_buffer+counter, rows_buffer[0], raw_size);
counter += row_stride_len;
// copyScanlineToBuffer(image_buffer, rows_buffer[0], row_stride_len); // args: & pointer & sample count
}
image_buffer -=row_stride_len;
// Save global values for later use
image_width=(*cDecompresInfo).image_width;
image_height=(*cDecompresInfo).image_height;
(void) jpeg_finish_decompress(&cDecompresInfo); // Finish decompression, no errors possible
jpeg_destroy_decompress(&cDecompresInfo); // 8) Release JPEG decompression object
// @TODO: infile
// fclose(infile);
return 1;
}
I am completing this function. Originally it used global variables, but I remade it to use a pointer to struct: struct jpeg_decompress_struct * cDecompresInfo;
Code:
(void) jpeg_finish_decompress(&cDecompresInfo);
now it crashes on the line, where the pointer is not fixed yet:
Code:
(void) jpeg_finish_decompress(&cDecompresInfo);
It's not clear how to correct. I tried &*cDecompresInfo or &(*cDecompresInfo) none of them works.
jpeg_finish_decompress want the struct to be dereferenced, but I have it via pointer. How to correct?