]> mj.ucw.cz Git - libucw.git/commitdiff
Store thumbnails in the YCbCr colorspace.
authorPavel Charvat <pchar@paja.(none)>
Wed, 29 Apr 2009 14:14:01 +0000 (16:14 +0200)
committerPavel Charvat <pchar@paja.(none)>
Wed, 29 Apr 2009 14:14:01 +0000 (16:14 +0200)
images/color.c
images/io-libjpeg.c

index 0a9da8c4c7f526876cf2db780cced098d03791ef..7f99c0d711c106da0c75107ac05e8f2c17ca17db 100644 (file)
@@ -173,6 +173,24 @@ struct image_conv_options image_conv_defaults = {
 #define IMAGE_WALK_DO_STEP do{ walk_pos[0] = rgb_to_gray_func(walk_sec_pos[0], walk_sec_pos[1], walk_sec_pos[2]); }while(0)
 #include "images/image-walk.h"
 
+/* Grayscale <-> YCbCr */
+
+#define IMAGE_WALK_PREFIX(x) walk_##x
+#define IMAGE_WALK_FUNC_NAME image_conv_gray_1_to_ycbcr_n
+#define IMAGE_WALK_DOUBLE
+#define IMAGE_WALK_SEC_COL_STEP 1
+#define IMAGE_WALK_UNROLL 4
+#define IMAGE_WALK_DO_STEP do{ walk_pos[0] = walk_sec_pos[0]; walk_pos[1] = walk_pos[2] = 0; }while(0)
+#include "images/image-walk.h"
+
+#define IMAGE_WALK_PREFIX(x) walk_##x
+#define IMAGE_WALK_FUNC_NAME image_conv_ycbcr_n_to_gray_1
+#define IMAGE_WALK_DOUBLE
+#define IMAGE_WALK_COL_STEP 1
+#define IMAGE_WALK_UNROLL 4
+#define IMAGE_WALK_DO_STEP do{ walk_pos[0] = walk_sec_pos[0]; }while(0)
+#include "images/image-walk.h"
+
 /* YCbCr <-> RGB */
 
 static inline void
@@ -248,6 +266,22 @@ pixel_conv_rgb_to_cmyk(byte *dest, byte *src)
 #define IMAGE_WALK_DO_STEP do{ pixel_conv_rgb_to_cmyk(walk_pos, walk_sec_pos); }while(0)
 #include "images/image-walk.h"
 
+/* CMYK <-> YCbCr */
+
+#define IMAGE_WALK_PREFIX(x) walk_##x
+#define IMAGE_WALK_FUNC_NAME image_conv_cmyk_4_to_ycbcr_n
+#define IMAGE_WALK_DOUBLE
+#define IMAGE_WALK_SEC_COL_STEP 4
+#define IMAGE_WALK_DO_STEP do{ pixel_conv_cmyk_to_rgb(walk_pos, walk_sec_pos); pixel_conv_rgb_to_ycbcr(walk_pos, walk_pos); }while(0)
+#include "images/image-walk.h"
+
+#define IMAGE_WALK_PREFIX(x) walk_##x
+#define IMAGE_WALK_FUNC_NAME image_conv_ycbcr_n_to_cmyk_4
+#define IMAGE_WALK_DOUBLE
+#define IMAGE_WALK_COL_STEP 4
+#define IMAGE_WALK_DO_STEP do{ pixel_conv_ycbcr_to_rgb(walk_pos, walk_sec_pos); pixel_conv_rgb_to_cmyk(walk_pos, walk_pos); }while(0)
+#include "images/image-walk.h"
+
 /* YCCK <-> RGB */
 
 static inline void
@@ -289,6 +323,22 @@ pixel_conv_rgb_to_ycck(byte *dest, byte *src)
 #define IMAGE_WALK_DO_STEP do{ pixel_conv_rgb_to_ycck(walk_pos, walk_sec_pos); }while(0)
 #include "images/image-walk.h"
 
+/* YCCK <-> RGB */
+
+#define IMAGE_WALK_PREFIX(x) walk_##x
+#define IMAGE_WALK_FUNC_NAME image_conv_ycck_4_to_ycbcr_n
+#define IMAGE_WALK_DOUBLE
+#define IMAGE_WALK_SEC_COL_STEP 4
+#define IMAGE_WALK_DO_STEP do{ pixel_conv_ycck_to_rgb(walk_pos, walk_sec_pos); pixel_conv_rgb_to_ycbcr(walk_pos, walk_pos); }while(0)
+#include "images/image-walk.h"
+
+#define IMAGE_WALK_PREFIX(x) walk_##x
+#define IMAGE_WALK_FUNC_NAME image_conv_ycbcr_n_to_ycck_4
+#define IMAGE_WALK_DOUBLE
+#define IMAGE_WALK_COL_STEP 4
+#define IMAGE_WALK_DO_STEP do{ pixel_conv_ycbcr_to_rgb(walk_pos, walk_sec_pos); pixel_conv_rgb_to_ycck(walk_pos, walk_pos); }while(0)
+#include "images/image-walk.h"
+
 /* Main functions */
 
 static int
@@ -306,6 +356,13 @@ image_conv_color_space(struct image_context *ctx UNUSED, struct image *dest, str
                  return 1;
                }
              break;
+            case COLOR_SPACE_YCBCR:
+              if (dest->pixel_size == 1)
+               {
+                 image_conv_ycbcr_n_to_gray_1(dest, src);
+                 return 1;
+               }
+             break;
          }
        break;
       case COLOR_SPACE_RGB:
@@ -340,9 +397,30 @@ image_conv_color_space(struct image_context *ctx UNUSED, struct image *dest, str
       case COLOR_SPACE_YCBCR:
         switch (src->flags & IMAGE_CHANNELS_FORMAT)
          {
+            case COLOR_SPACE_GRAYSCALE:
+              if (src->pixel_size == 1)
+               {
+                  image_conv_gray_1_to_ycbcr_n(dest, src);
+                 return 1;
+               }
+             break;
            case COLOR_SPACE_RGB:
              image_conv_rgb_n_to_ycbcr_n(dest, src);
              return 1;
+           case COLOR_SPACE_CMYK:
+             if (src->pixel_size == 4)
+               {
+                 image_conv_cmyk_4_to_ycbcr_n(dest, src);
+                 return 1;
+               }
+             break;
+           case COLOR_SPACE_YCCK:
+             if (src->pixel_size == 4)
+               {
+                 image_conv_ycck_4_to_ycbcr_n(dest, src);
+                 return 1;
+               }
+             break;
          }
        break;
       case COLOR_SPACE_CMYK:
@@ -355,6 +433,13 @@ image_conv_color_space(struct image_context *ctx UNUSED, struct image *dest, str
                  return 1;
                }
              break;
+           case COLOR_SPACE_YCBCR:
+             if (dest->pixel_size == 4)
+               {
+                 image_conv_ycbcr_n_to_cmyk_4(dest, src);
+                 return 1;
+               }
+             break;
           }
         break;
       case COLOR_SPACE_YCCK:
@@ -367,6 +452,13 @@ image_conv_color_space(struct image_context *ctx UNUSED, struct image *dest, str
                  return 1;
                }
              break;
+           case COLOR_SPACE_YCBCR:
+             if (dest->pixel_size == 4)
+               {
+                 image_conv_ycbcr_n_to_ycck_4(dest, src);
+                 return 1;
+               }
+             break;
          }
        break;
     }
index 16f10b7a46ef3f39853089d948e0b9646bbb9bd9..ba2cfbe463226c3c15ee15fe9d5bad3d4be9b406 100644 (file)
@@ -363,9 +363,6 @@ libjpeg_read_data(struct image_io *io)
       case COLOR_SPACE_GRAYSCALE:
        i->cinfo.out_color_space = JCS_GRAYSCALE;
        break;
-      case COLOR_SPACE_YCBCR:
-       i->cinfo.out_color_space = JCS_YCbCr;
-       break;
       case COLOR_SPACE_CMYK:
        i->cinfo.out_color_space = JCS_CMYK;
        break;
@@ -375,6 +372,10 @@ libjpeg_read_data(struct image_io *io)
       default:
        switch (i->cinfo.jpeg_color_space)
          {
+           case JCS_YCbCr:
+             read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_YCBCR; 
+             i->cinfo.out_color_space = JCS_YCbCr;
+             break;
            case JCS_CMYK:
              read_flags = (read_flags & ~IMAGE_COLOR_SPACE & IMAGE_CHANNELS_FORMAT) | COLOR_SPACE_CMYK; 
              i->cinfo.out_color_space = JCS_CMYK;