- count = i;
- buf = const_cast<unsigned char *>(buf) + n + 12;
-
- lj->stereo = FALSE;
-
- MPOData *mpo = jpeg_get_mpo_data(buf, count);
- if (mpo && mpo->num_images > 1)
- {
- guint i;
- gint idx1 = -1;
- gint idx2 = -1;
- guint num2 = 1;
-
- for (i = 0; i < mpo->num_images; i++)
- {
- if (mpo->images[i].type_code == 0x20002)
- {
- if (mpo->images[i].MPIndividualNum == 1)
- {
- idx1 = i;
- }
- else if (mpo->images[i].MPIndividualNum > num2)
- {
- idx2 = i;
- num2 = mpo->images[i].MPIndividualNum;
- }
- }
- }
-
- if (idx1 >= 0 && idx2 >= 0)
- {
- lj->stereo = TRUE;
- stereo_buf2 = const_cast<unsigned char *>(buf) + mpo->images[idx2].offset;
- stereo_length = mpo->images[idx2].length;
- buf = const_cast<unsigned char *>(buf) + mpo->images[idx1].offset;
- count = mpo->images[idx1].length;
- }
- }
- jpeg_mpo_data_free(mpo);
-
- /* setup error handler */
- cinfo.err = jpeg_std_error (&jerr.pub);
- if (lj->stereo) cinfo2.err = jpeg_std_error (&jerr.pub);
- jerr.pub.error_exit = fatal_error_handler;
- jerr.pub.output_message = output_message_handler;
-
- jerr.error = error;
-
-
- if (sigsetjmp(jerr.setjmp_buffer, 0))
- {
- /* If we get here, the JPEG code has signaled an error.
- * We need to clean up the JPEG object, close the input file, and return.
- */
- jpeg_destroy_decompress(&cinfo);
- if (lj->stereo) jpeg_destroy_decompress(&cinfo2);
- return FALSE;
- }
-
- jpeg_create_decompress(&cinfo);
-
- set_mem_src(&cinfo, const_cast<unsigned char *>(buf), count);
-
-
- jpeg_read_header(&cinfo, TRUE);
-
- if (lj->stereo)
- {
- jpeg_create_decompress(&cinfo2);
- set_mem_src(&cinfo2, stereo_buf2, stereo_length);
- jpeg_read_header(&cinfo2, TRUE);
-
- if (cinfo.image_width != cinfo2.image_width ||
- cinfo.image_height != cinfo2.image_height)
- {
- DEBUG_1("stereo data with different size");
- jpeg_destroy_decompress(&cinfo2);
- lj->stereo = FALSE;
- }
- }
-
-
-
- lj->requested_width = lj->stereo ? cinfo.image_width * 2: cinfo.image_width;
- lj->requested_height = cinfo.image_height;
- lj->size_cb(loader, lj->requested_width, lj->requested_height, lj->data);
-
- cinfo.scale_num = 1;
- for (cinfo.scale_denom = 2; cinfo.scale_denom <= 8; cinfo.scale_denom *= 2) {
- jpeg_calc_output_dimensions(&cinfo);
- if (cinfo.output_width < (lj->stereo ? lj->requested_width / 2 : lj->requested_width) || cinfo.output_height < lj->requested_height) {
- cinfo.scale_denom /= 2;
- break;
- }
- }
- jpeg_calc_output_dimensions(&cinfo);
- if (lj->stereo)
- {
- cinfo2.scale_num = cinfo.scale_num;
- cinfo2.scale_denom = cinfo.scale_denom;
- jpeg_calc_output_dimensions(&cinfo2);
- jpeg_start_decompress(&cinfo2);
- }
-
-
- jpeg_start_decompress(&cinfo);
-
-
- if (lj->stereo)
- {
- if (cinfo.output_width != cinfo2.output_width ||
- cinfo.output_height != cinfo2.output_height ||
- cinfo.out_color_components != cinfo2.out_color_components)
- {
- DEBUG_1("stereo data with different output size");
- jpeg_destroy_decompress(&cinfo2);
- lj->stereo = FALSE;
- }
- }
-
-
- lj->pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB,
- cinfo.out_color_components == 4 ? TRUE : FALSE,
- 8, lj->stereo ? cinfo.output_width * 2: cinfo.output_width, cinfo.output_height);
-
- if (!lj->pixbuf)
- {
- jpeg_destroy_decompress (&cinfo);
- if (lj->stereo) jpeg_destroy_decompress (&cinfo2);
- return 0;
- }
- if (lj->stereo) g_object_set_data(G_OBJECT(lj->pixbuf), "stereo_data", GINT_TO_POINTER(STEREO_PIXBUF_CROSS));
- lj->area_prepared_cb(loader, lj->data);
-
- rowstride = gdk_pixbuf_get_rowstride(lj->pixbuf);
- dptr = gdk_pixbuf_get_pixels(lj->pixbuf);
- dptr2 = gdk_pixbuf_get_pixels(lj->pixbuf) + ((cinfo.out_color_components == 4) ? 4 * cinfo.output_width : 3 * cinfo.output_width);
-
-
- while (cinfo.output_scanline < cinfo.output_height && !lj->abort)
- {
- guint scanline = cinfo.output_scanline;
- image_loader_cr3_read_scanline(&cinfo, &dptr, rowstride);
- lj->area_updated_cb(loader, 0, scanline, cinfo.output_width, cinfo.rec_outbuf_height, lj->data);
- if (lj->stereo)
- {
- guint scanline = cinfo2.output_scanline;
- image_loader_cr3_read_scanline(&cinfo2, &dptr2, rowstride);
- lj->area_updated_cb(loader, cinfo.output_width, scanline, cinfo2.output_width, cinfo2.rec_outbuf_height, lj->data);
- }
- }
-
- jpeg_finish_decompress(&cinfo);
- jpeg_destroy_decompress(&cinfo);
- if (lj->stereo)
- {
- jpeg_finish_decompress(&cinfo);
- jpeg_destroy_decompress(&cinfo);
- }
-
- return TRUE;