mirror of
https://github.com/Ylianst/MeshAgent
synced 2025-12-17 08:43:21 +00:00
Fixed JPEG chroma subsampling on TurboLibJPEG
This commit is contained in:
@@ -83,7 +83,7 @@ void term_destination (j_compress_ptr cinfo)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_JPEG_buffer (JSAMPLE * image_buffer, int image_width, int image_height, int quality)
|
int write_JPEG_buffer(JSAMPLE * image_buffer, int image_width, int image_height, int quality)
|
||||||
{
|
{
|
||||||
struct jpeg_compress_struct cinfo;
|
struct jpeg_compress_struct cinfo;
|
||||||
struct jpeg_error_mgr jerr;
|
struct jpeg_error_mgr jerr;
|
||||||
@@ -94,26 +94,34 @@ int write_JPEG_buffer (JSAMPLE * image_buffer, int image_width, int image_height
|
|||||||
if (default_JPEG_error_handler != NULL) { jerr.error_exit = jpeg_error_handler; }
|
if (default_JPEG_error_handler != NULL) { jerr.error_exit = jpeg_error_handler; }
|
||||||
|
|
||||||
jpeg_create_compress(&cinfo);
|
jpeg_create_compress(&cinfo);
|
||||||
cinfo.dest = (struct jpeg_destination_mgr *) malloc (sizeof(struct jpeg_destination_mgr));
|
cinfo.dest = (struct jpeg_destination_mgr *) malloc(sizeof(struct jpeg_destination_mgr));
|
||||||
cinfo.dest->init_destination = &init_destination;
|
cinfo.dest->init_destination = &init_destination;
|
||||||
cinfo.dest->empty_output_buffer = &empty_output_buffer;
|
cinfo.dest->empty_output_buffer = &empty_output_buffer;
|
||||||
cinfo.dest->term_destination = &term_destination;
|
cinfo.dest->term_destination = &term_destination;
|
||||||
cinfo.comp_info[0].v_samp_factor = 1;
|
|
||||||
cinfo.comp_info[0].h_samp_factor = 1;
|
|
||||||
|
|
||||||
cinfo.image_width = image_width;
|
cinfo.image_width = image_width;
|
||||||
cinfo.image_height = image_height;
|
cinfo.image_height = image_height;
|
||||||
cinfo.input_components = 3;
|
cinfo.input_components = 3;
|
||||||
cinfo.in_color_space = JCS_RGB;
|
cinfo.in_color_space = JCS_RGB;
|
||||||
jpeg_set_defaults(&cinfo);
|
jpeg_set_defaults(&cinfo);
|
||||||
|
|
||||||
|
// 4:4:4, 1x1 (no subsampling)
|
||||||
|
// The resolution of chrominance information (Cb & Cr) is preserved at the same rate as the luminance (Y) information
|
||||||
|
cinfo.comp_info[0].v_samp_factor = 1;
|
||||||
|
cinfo.comp_info[0].h_samp_factor = 1;
|
||||||
|
cinfo.comp_info[1].v_samp_factor = 1;
|
||||||
|
cinfo.comp_info[1].h_samp_factor = 1;
|
||||||
|
cinfo.comp_info[2].v_samp_factor = 1;
|
||||||
|
cinfo.comp_info[2].h_samp_factor = 1;
|
||||||
|
|
||||||
jpeg_set_quality(&cinfo, quality, TRUE);
|
jpeg_set_quality(&cinfo, quality, TRUE);
|
||||||
jpeg_start_compress(&cinfo, TRUE);
|
jpeg_start_compress(&cinfo, TRUE);
|
||||||
row_stride = image_width * 3;
|
row_stride = image_width * 3;
|
||||||
|
|
||||||
while (cinfo.next_scanline < cinfo.image_height)
|
while (cinfo.next_scanline < cinfo.image_height)
|
||||||
{
|
{
|
||||||
row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride];
|
row_pointer[0] = &image_buffer[cinfo.next_scanline * row_stride];
|
||||||
(void) jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
(void)jpeg_write_scanlines(&cinfo, row_pointer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
jpeg_finish_compress(&cinfo);
|
jpeg_finish_compress(&cinfo);
|
||||||
@@ -124,4 +132,3 @@ int write_JPEG_buffer (JSAMPLE * image_buffer, int image_width, int image_height
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user