[gegl] color conversion using BABL if not supported on the GPU



commit 862ccb1baa2a8227437b93e2483471331cb5d7d0
Author: Victor Oliveira <victormatheus gmail com>
Date:   Fri Dec 30 21:59:20 2011 -0200

    color conversion using BABL if not supported on the GPU

 gegl/operation/gegl-operation-point-filter.c |   48 ++++++++++++++-----------
 1 files changed, 27 insertions(+), 21 deletions(-)
---
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index c24574d..be7d7bd 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -104,11 +104,8 @@ gegl_operation_point_filter_cl_process_full (GeglOperation       *operation,
   struct buf_tex output_tex;
   size_t *pitch = NULL;
 
-  /* supported babl formats up to now:
-     RGBA u8
-     All formats with four floating-point channels
-     (I suppose others formats would be hard to put on GPU)
-  */
+  gegl_cl_color_op conv_in;
+  gegl_cl_color_op conv_out;
 
   cl_image_format rgbaf_format;
   cl_image_format rgbau8_format;
@@ -128,12 +125,23 @@ gegl_operation_point_filter_cl_process_full (GeglOperation       *operation,
   input_tex.tex     = (cl_mem *)        gegl_malloc(ntex * sizeof(cl_mem));
   output_tex.tex    = (cl_mem *)        gegl_malloc(ntex * sizeof(cl_mem));
 
-  g_printf("[OpenCL] BABL formats: (%s,%s:%d) (%s,%s:%d)\n \t Tile Size:(%d, %d)\n", babl_get_name(gegl_buffer_get_format(input)),  babl_get_name(in_format),
-                                                             gegl_cl_color_supported (gegl_buffer_get_format(input), in_format),
-                                                             babl_get_name(out_format), babl_get_name(gegl_buffer_get_format(output)),
-                                                             gegl_cl_color_supported (out_format, gegl_buffer_get_format(output)),
-                                                             input->tile_storage->tile_width,
-                                                             input->tile_storage->tile_height);
+  cl_image_format *in_image_format  = (input->format  == babl_format ("RGBA u8"))? &rgbau8_format : &rgbaf_format;
+  cl_image_format *out_image_format = (output->format == babl_format ("RGBA u8"))? &rgbau8_format : &rgbaf_format;
+
+  const size_t origin_zero[3] = {0, 0, 0};
+
+  conv_in  = gegl_cl_color_supported (input->format,   in_format);
+  conv_out = gegl_cl_color_supported (out_format, output->format);
+
+  g_printf("[OpenCL] BABL formats: (%s,%s:%d) (%s,%s:%d)\n \t Tile Size:(%d, %d)\n",
+           babl_get_name(input->format),
+           babl_get_name(in_format),
+           conv_in,
+           babl_get_name(out_format),
+           babl_get_name(output->format),
+           conv_out,
+           input->tile_storage->tile_width,
+           input->tile_storage->tile_height);
 
   input_tex.tex  = (cl_mem *) gegl_malloc(ntex * sizeof(cl_mem));
   output_tex.tex = (cl_mem *) gegl_malloc(ntex * sizeof(cl_mem));
@@ -160,14 +168,14 @@ gegl_operation_point_filter_cl_process_full (GeglOperation       *operation,
 
         input_tex.tex[i]  = gegl_clCreateImage2D (gegl_cl_get_context(),
                                                   CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
-                                                  (gegl_buffer_get_format(input) == babl_format ("RGBA u8"))? &rgbau8_format : &rgbaf_format,
+                                                  in_image_format,
                                                   region[0], region[1],
                                                   0,  NULL, &errcode);
         if (errcode != CL_SUCCESS) CL_ERROR;
 
         output_tex.tex[i] = gegl_clCreateImage2D (gegl_cl_get_context(),
                                                   CL_MEM_READ_WRITE,
-                                                  (gegl_buffer_get_format(output) == babl_format ("RGBA u8"))? &rgbau8_format : &rgbaf_format,
+                                                  out_image_format,
                                                   region[0], region[1],
                                                   0,  NULL, &errcode);
         if (errcode != CL_SUCCESS) CL_ERROR;
@@ -180,18 +188,17 @@ gegl_operation_point_filter_cl_process_full (GeglOperation       *operation,
 
   for (i=0; i < ntex; i++)
     {
-      const size_t origin[3] = {0, 0, 0};
       const size_t region[3] = {input_tex.region[i].width, input_tex.region[i].height, 1};
 
       /* pre-pinned memory */
       in_data[i]  = gegl_clEnqueueMapImage(gegl_cl_get_command_queue(), input_tex.tex[i], CL_TRUE,
                                            CL_MAP_WRITE,
-                                           origin, region, &pitch[i], NULL,
+                                           origin_zero, region, &pitch[i], NULL,
                                            0, NULL, NULL, &errcode);
       if (errcode != CL_SUCCESS) CL_ERROR;
 
       /* un-tile */
-      if (gegl_cl_color_supported (gegl_buffer_get_format(input), in_format) == CL_COLOR_NOT_SUPPORTED)
+      if (conv_in == CL_COLOR_NOT_SUPPORTED)
         /* color conversion using BABL */
         gegl_buffer_get (input, 1.0, &input_tex.region[i], in_format, in_data[i], pitch[i]);
       else
@@ -211,7 +218,7 @@ gegl_operation_point_filter_cl_process_full (GeglOperation       *operation,
   if (errcode != CL_SUCCESS) CL_ERROR;
 
   /* color conversion in the GPU (input) */
-  if (gegl_cl_color_supported (input->format, in_format) == CL_COLOR_CONVERT)
+  if (conv_in == CL_COLOR_CONVERT)
     for (i=0; i < ntex; i++)
      {
        const size_t size[2] = {input_tex.region[i].width, input_tex.region[i].height};
@@ -234,7 +241,7 @@ gegl_operation_point_filter_cl_process_full (GeglOperation       *operation,
   if (errcode != CL_SUCCESS) CL_ERROR;
 
   /* color conversion in the GPU (output) */
-  if (gegl_cl_color_supported (out_format, output->format) == CL_COLOR_CONVERT)
+  if (conv_out == CL_COLOR_CONVERT)
     for (i=0; i < ntex; i++)
      {
        const size_t size[2] = {output_tex.region[i].width, output_tex.region[i].height};
@@ -244,11 +251,10 @@ gegl_operation_point_filter_cl_process_full (GeglOperation       *operation,
   /* GPU -> CPU */
   for (i=0; i < ntex; i++)
     {
-      const size_t origin[3] = {0, 0, 0};
       const size_t region[3] = {input_tex.region[i].width, input_tex.region[i].height, 1};
 
       errcode = gegl_clEnqueueReadImage(gegl_cl_get_command_queue(), output_tex.tex[i], CL_FALSE,
-                                         origin, region, 0, 0, out_data[i],
+                                         origin_zero, region, 0, 0, out_data[i],
                                          0, NULL, NULL);
       if (errcode != CL_SUCCESS) CL_ERROR;
     }
@@ -264,7 +270,7 @@ gegl_operation_point_filter_cl_process_full (GeglOperation       *operation,
   for (i=0; i < ntex; i++)
     {
       /* tile-ize */
-      if (gegl_cl_color_supported (out_format, output->format) == CL_COLOR_NOT_SUPPORTED)
+      if (conv_out == CL_COLOR_NOT_SUPPORTED)
         /* color conversion using BABL */
         gegl_buffer_set (output, &output_tex.region[i], out_format, out_data[i], GEGL_AUTO_ROWSTRIDE);
       else



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