]> mj.ucw.cz Git - libucw.git/blobdiff - images/io-libjpeg.c
Main: Removing an already removed event is always safe.
[libucw.git] / images / io-libjpeg.c
index 936dc24bf01a7be78b398c1494c944c305d5c0f6..8725610d330e5f035c00d61aa48c562c1a5c0e17 100644 (file)
@@ -9,9 +9,9 @@
 
 #undef LOCAL_DEBUG
 
 
 #undef LOCAL_DEBUG
 
-#include "lib/lib.h"
-#include "lib/mempool.h"
-#include "lib/fastbuf.h"
+#include "ucw/lib.h"
+#include "ucw/mempool.h"
+#include "ucw/fastbuf.h"
 #include "images/images.h"
 #include "images/error.h"
 #include "images/color.h"
 #include "images/images.h"
 #include "images/error.h"
 #include "images/color.h"
@@ -94,6 +94,7 @@ libjpeg_fastbuf_read_prepare(struct libjpeg_read_internals *i)
   DBG("libjpeg_fb_read_prepare()");
   byte *start;
   uns len = bdirect_read_prepare(i->fastbuf, &start);
   DBG("libjpeg_fb_read_prepare()");
   byte *start;
   uns len = bdirect_read_prepare(i->fastbuf, &start);
+  DBG("readed %u bytes at %p", len, start);
   if (!len)
     {
       // XXX: maybe only generate a warning and return EOI markers to recover from such errors (also in skip_input_data)
   if (!len)
     {
       // XXX: maybe only generate a warning and return EOI markers to recover from such errors (also in skip_input_data)
@@ -133,6 +134,7 @@ libjpeg_fill_input_buffer(j_decompress_ptr cinfo)
   DBG("libjpeg_fill_input_buffer()");
   struct libjpeg_read_internals *i = (struct libjpeg_read_internals *)cinfo;
   libjpeg_fastbuf_read_commit(i);
   DBG("libjpeg_fill_input_buffer()");
   struct libjpeg_read_internals *i = (struct libjpeg_read_internals *)cinfo;
   libjpeg_fastbuf_read_commit(i);
+  libjpeg_fastbuf_read_prepare(i);
   return 1;
 }
 
   return 1;
 }
 
@@ -356,38 +358,29 @@ libjpeg_read_data(struct image_io *io)
   uns read_flags = io->flags;
 
   /* Select color space */
   uns read_flags = io->flags;
 
   /* Select color space */
-  switch (read_flags & IMAGE_COLOR_SPACE)
+  switch (i->cinfo.jpeg_color_space)
     {
     {
-      case COLOR_SPACE_GRAYSCALE:
-       i->cinfo.out_color_space = JCS_GRAYSCALE;
-       break;
-      case COLOR_SPACE_YCBCR:
+      case JCS_GRAYSCALE:
+        read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_YCBCR; 
+        i->cinfo.out_color_space = JCS_YCbCr;
+        break;
+      case JCS_YCbCr:
+       read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_YCBCR; 
        i->cinfo.out_color_space = JCS_YCbCr;
        break;
        i->cinfo.out_color_space = JCS_YCbCr;
        break;
-      case COLOR_SPACE_CMYK:
+      case JCS_CMYK:
+       read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_CMYK; 
        i->cinfo.out_color_space = JCS_CMYK;
        break;
        i->cinfo.out_color_space = JCS_CMYK;
        break;
-      case COLOR_SPACE_YCCK:
+      case JCS_YCCK:
+       read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_YCCK; 
        i->cinfo.out_color_space = JCS_YCCK;
        break;
       default:
        i->cinfo.out_color_space = JCS_YCCK;
        break;
       default:
-       switch (i->cinfo.jpeg_color_space)
-         {
-           case JCS_CMYK:
-             read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_CMYK; 
-             i->cinfo.out_color_space = JCS_CMYK;
-             break;
-           case JCS_YCCK:
-             read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_YCCK; 
-             i->cinfo.out_color_space = JCS_YCCK;
-             break;
-           default:
-             read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_RGB; 
-             i->cinfo.out_color_space = JCS_RGB;
-             break;
-         }
+       read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_RGB; 
+       i->cinfo.out_color_space = JCS_RGB;
        break;
        break;
-    }
+  }
 
   /* Prepare the image  */
   struct image_io_read_data_internals rdi;
 
   /* Prepare the image  */
   struct image_io_read_data_internals rdi;