[gegl] Kernels for Y'CbCrA color format



commit 6f84d1d03963cd32b2a7e3dbe96338eb17ed26bc
Author: Victor Oliveira <victormatheus gmail com>
Date:   Tue Jan 17 12:52:02 2012 -0200

    Kernels for Y'CbCrA color format

 gegl/opencl/gegl-cl-color-kernel.h |   42 ++++++++++++++++++++++++++++++++++++
 gegl/opencl/gegl-cl-color.c        |   11 ++++++++-
 2 files changed, 52 insertions(+), 1 deletions(-)
---
diff --git a/gegl/opencl/gegl-cl-color-kernel.h b/gegl/opencl/gegl-cl-color-kernel.h
index 149c370..9d517e0 100644
--- a/gegl/opencl/gegl-cl-color-kernel.h
+++ b/gegl/opencl/gegl-cl-color-kernel.h
@@ -125,4 +125,46 @@ static const char* kernel_color_source =
 "  float4 in_v  = read_imagef(in, sampler, gid);                                          \n"
 "  float4 out_v;                                                                          \n"
 "  write_imagef(out, gid, out_v);                                                         \n"
+"}                                                                                        \n"
+"                                                                                         \n"
+"/* RGBA float -> Y'CbCrA float */                                                        \n"
+"                                                                                         \n"
+"__kernel void rgba_to_ycbcra (__read_only  image2d_t in,                                 \n"
+"                              __write_only image2d_t out)                                \n"
+"{                                                                                        \n"
+"  int2 gid = (int2)(get_global_id(0), get_global_id(1));                                 \n"
+"  float4 in_v  = read_imagef(in, sampler, gid);                                          \n"
+"  float4 out_v;                                                                          \n"
+"                                                                                         \n"
+"  float4 rgb = (float4)(linear_to_gamma_2_2(in_v.x),                                     \n"
+"                        linear_to_gamma_2_2(in_v.y),                                     \n"
+"                        linear_to_gamma_2_2(in_v.z),                                     \n"
+"                        0.0f);                                                           \n"
+"                                                                                         \n"
+"  out_v = (float4)( 0.299f    * rgb.x + 0.587f    * rgb.y + 0.114f    * rgb.z,           \n"
+"                   -0.168736f * rgb.x - 0.331264f * rgb.y + 0.5f      * rgb.z,           \n"
+"                    0.5f      * rgb.x - 0.418688f * rgb.y - 0.081312f * rgb.z,           \n"
+"                   in_v.w);                                                              \n"
+"  write_imagef(out, gid, out_v);                                                         \n"
+"}                                                                                        \n"
+"                                                                                         \n"
+"/* Y'CbCrA float -> RGBA float */                                                        \n"
+"                                                                                         \n"
+"__kernel void ycbcra_to_rgba (__read_only  image2d_t in,                                 \n"
+"                              __write_only image2d_t out)                                \n"
+"{                                                                                        \n"
+"  int2 gid = (int2)(get_global_id(0), get_global_id(1));                                 \n"
+"  float4 in_v  = read_imagef(in, sampler, gid);                                          \n"
+"  float4 out_v;                                                                          \n"
+"                                                                                         \n"
+"  float4 rgb = (float4)(1.0f * in_v.x + 0.0f      * in_v.y + 1.40200f    * in_v.z,       \n"
+"                        1.0f * in_v.x - 0.344136f * in_v.y - 0.71414136f * in_v.z,       \n"
+"                        1.0f * in_v.x + 1.772f    * in_v.y + 0.0f        * in_v.z,       \n"
+"                        0.0f);                                                           \n"
+"                                                                                         \n"
+"  out_v = (float4)(linear_to_gamma_2_2(rgb.x),                                           \n"
+"                   linear_to_gamma_2_2(rgb.y),                                           \n"
+"                   linear_to_gamma_2_2(rgb.z),                                           \n"
+"                   in_v.w);                                                              \n"
+"  write_imagef(out, gid, out_v);                                                         \n"
 "}                                                                                        \n";
diff --git a/gegl/opencl/gegl-cl-color.c b/gegl/opencl/gegl-cl-color.c
index 4dd281f..38b52c8 100644
--- a/gegl/opencl/gegl-cl-color.c
+++ b/gegl/opencl/gegl-cl-color.c
@@ -6,7 +6,7 @@
 
 static gegl_cl_run_data *kernels_color = NULL;
 
-#define CL_FORMAT_N 8
+#define CL_FORMAT_N 10
 
 static const Babl *format[CL_FORMAT_N];
 
@@ -21,6 +21,8 @@ gegl_cl_color_compile_kernels(void)
                                "rgba_gamma_2_2_premultiplied2rgba",  /* 5 */
                                "rgbaf_to_rgbau8",                    /* 6 */
                                "rgbau8_to_rgbaf",                    /* 7 */
+                               "rgba_to_ycbcra",                     /* 8 */
+                               "ycbcra_to_rgba",                     /* 9 */
                                NULL};
 
   format[0] = babl_format ("RaGaBaA float"),
@@ -31,6 +33,8 @@ gegl_cl_color_compile_kernels(void)
   format[5] = babl_format ("RGBA float"),
   format[6] = babl_format ("RGBA u8"),
   format[7] = babl_format ("RGBA float"),
+  format[8] = babl_format ("Y'CbCrA float"),
+  format[9] = babl_format ("RGBA float"),
 
   kernels_color = gegl_cl_compile_and_build (kernel_color_source, kernel_name);
 }
@@ -126,6 +130,7 @@ gegl_cl_color_conv (cl_mem *in_tex, cl_mem *aux_tex, const size_t size[2],
           else if (out_format == babl_format ("R'G'B'A float"))    CONV_1(2)
           else if (out_format == babl_format ("R'aG'aB'aA float")) CONV_1(4)
           else if (out_format == babl_format ("RGBA u8"))          CONV_1(6)
+          else if (out_format == babl_format ("Y'CbCrA float"))    CONV_1(8)
         }
       else if (in_format == babl_format ("RaGaBaA float"))
         {
@@ -133,6 +138,7 @@ gegl_cl_color_conv (cl_mem *in_tex, cl_mem *aux_tex, const size_t size[2],
           else if (out_format == babl_format ("R'G'B'A float"))    CONV_2(1, 2)
           else if (out_format == babl_format ("R'aG'aB'aA float")) CONV_2(1, 4)
           else if (out_format == babl_format ("RGBA u8"))          CONV_2(1, 6)
+          else if (out_format == babl_format ("Y'CbCrA float"))    CONV_2(1, 8)
         }
       else if (in_format == babl_format ("R'G'B'A float"))
         {
@@ -140,6 +146,7 @@ gegl_cl_color_conv (cl_mem *in_tex, cl_mem *aux_tex, const size_t size[2],
           else if (out_format == babl_format ("RaGaBaA float"))    CONV_2(3, 0)
           else if (out_format == babl_format ("R'aG'aB'aA float")) CONV_2(3, 4)
           else if (out_format == babl_format ("RGBA u8"))          CONV_2(3, 6)
+          else if (out_format == babl_format ("Y'CbCrA float"))    CONV_2(3, 8)
         }
       else if (in_format == babl_format ("R'aG'aB'aA float"))
         {
@@ -147,6 +154,7 @@ gegl_cl_color_conv (cl_mem *in_tex, cl_mem *aux_tex, const size_t size[2],
           else if (out_format == babl_format ("RaGaBaA float"))    CONV_2(5, 0)
           else if (out_format == babl_format ("R'G'B'A float"))    CONV_2(5, 2)
           else if (out_format == babl_format ("RGBA u8"))          CONV_2(5, 6)
+          else if (out_format == babl_format ("Y'CbCrA float"))    CONV_2(5, 8)
         }
       else if (in_format == babl_format ("RGBA u8"))
         {
@@ -154,6 +162,7 @@ gegl_cl_color_conv (cl_mem *in_tex, cl_mem *aux_tex, const size_t size[2],
           else if (out_format == babl_format ("RaGaBaA float"))    CONV_2(7, 0)
           else if (out_format == babl_format ("R'G'B'A float"))    CONV_2(7, 2)
           else if (out_format == babl_format ("RGBA u8"))          CONV_2(7, 6)
+          else if (out_format == babl_format ("Y'CbCrA float"))    CONV_2(7, 8)
         }
 
       /* XXX: maybe there are precision problems if a 8-bit texture is used as intermediate */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]