+
+ channels = cinfo.output_components;
+ switch (cinfo.out_color_space) {
+ case JCS_GRAYSCALE:
+ if (cinfo.output_components != 1) {
+ mm_log((1, "i_readjpeg: grayscale image with %d channels\n", cinfo.output_components));
+ i_push_errorf(0, "grayscale image with invalid components %d", cinfo.output_components);
+ wiol_term_source(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ return NULL;
+ }
+ transfer_f = transfer_gray;
+ break;
+
+ case JCS_RGB:
+ transfer_f = transfer_rgb;
+ if (cinfo.output_components != 3) {
+ mm_log((1, "i_readjpeg: RGB image with %d channels\n", cinfo.output_components));
+ i_push_errorf(0, "RGB image with invalid components %d", cinfo.output_components);
+ wiol_term_source(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ return NULL;
+ }
+ break;
+
+ case JCS_CMYK:
+ if (cinfo.output_components == 4) {
+ /* we treat the CMYK values as inverted, because that's what that
+ buggy photoshop does, and everyone has to follow the gorilla.
+
+ Is there any app that still produces correct CMYK JPEGs?
+ */
+ transfer_f = transfer_cmyk_inverted;
+ channels = 3;
+ }
+ else {
+ mm_log((1, "i_readjpeg: cmyk image with %d channels\n", cinfo.output_components));
+ i_push_errorf(0, "CMYK image with invalid components %d", cinfo.output_components);
+ wiol_term_source(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ return NULL;
+ }
+ break;
+
+ default:
+ mm_log((1, "i_readjpeg: unknown color space %d\n", cinfo.out_color_space));
+ i_push_errorf(0, "Unknown color space %d", cinfo.out_color_space);
+ wiol_term_source(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ return NULL;
+ }
+
+ if (!i_int_check_image_file_limits(cinfo.output_width, cinfo.output_height,
+ channels, sizeof(i_sample_t))) {
+ mm_log((1, "i_readjpeg: image size exceeds limits\n"));
+ wiol_term_source(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ return NULL;
+ }
+
+ im=i_img_empty_ch(NULL, cinfo.output_width, cinfo.output_height, channels);
+ if (!im) {
+ wiol_term_source(&cinfo);
+ jpeg_destroy_decompress(&cinfo);
+ return NULL;
+ }