[gegl] organizing code a little



commit 0afb9cc8efc343d1ab4b3f543af85dbde76fdb20
Author: Victor Oliveira <victormatheus gmail com>
Date:   Thu Jan 26 11:13:35 2012 -0200

    organizing code a little

 gegl/buffer/gegl-buffer-cl-iterator.c        |  229 ++++++++++++++------------
 gegl/buffer/gegl-buffer-cl-iterator.h        |    2 +-
 gegl/operation/gegl-operation-point-filter.c |    2 +-
 3 files changed, 125 insertions(+), 108 deletions(-)
---
diff --git a/gegl/buffer/gegl-buffer-cl-iterator.c b/gegl/buffer/gegl-buffer-cl-iterator.c
index f28d133..55a8159 100644
--- a/gegl/buffer/gegl-buffer-cl-iterator.c
+++ b/gegl/buffer/gegl-buffer-cl-iterator.c
@@ -21,7 +21,7 @@ typedef struct GeglBufferClIterators
   /* current region of interest */
   gint          n;
   size_t        size [GEGL_CL_BUFFER_MAX_ITERATORS][GEGL_CL_NTEX][2];  /* length of current data in pixels */
-  cl_mem       *tex  [GEGL_CL_BUFFER_MAX_ITERATORS][GEGL_CL_NTEX];
+  cl_mem        tex  [GEGL_CL_BUFFER_MAX_ITERATORS][GEGL_CL_NTEX];
   GeglRectangle roi  [GEGL_CL_BUFFER_MAX_ITERATORS][GEGL_CL_NTEX];
 
   /* the following is private: */
@@ -268,107 +268,114 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
               const size_t region[3] = {i->roi[no][j].width, i->roi[no][j].height, 1};
 
               /* un-tile */
-              if (i->conv[no] == GEGL_CL_COLOR_NOT_SUPPORTED)
+              switch (i->conv[no])
                 {
-                  g_assert (i->tex_op[no][j] == NULL);
-                  i->tex_op[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
-                                                        CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
-                                                        &i->op_cl_format [no],
-                                                        i->roi[no][j].width,
-                                                        i->roi[no][j].height,
-                                                        0, NULL, &cl_err);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
-
-                  /* pre-pinned memory */
-                  data = gegl_clEnqueueMapImage(gegl_cl_get_command_queue(), i->tex_op[no][j], CL_TRUE,
-                                                CL_MAP_WRITE,
-                                                origin_zero, region, &pitch, NULL,
-                                                0, NULL, NULL, &cl_err);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
-
-                  /* color conversion using BABL */
-                  gegl_buffer_get (i->buffer[no], 1.0, &i->roi[no][j], i->format[no], data, pitch);
-
-                  i->tex[no][j] = &i->tex_op[no][j];
-                }
-              else if (i->conv[no] == GEGL_CL_COLOR_EQUAL)
-                {
-                  g_assert (i->tex_buf[no][j] == NULL);
-                  i->tex_buf[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
-                                                            CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
-                                                            &i->buf_cl_format [no],
-                                                            i->roi[no][j].width,
-                                                            i->roi[no][j].height,
-                                                            0, NULL, &cl_err);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
-
-                  /* pre-pinned memory */
-                  data = gegl_clEnqueueMapImage(gegl_cl_get_command_queue(), i->tex_buf[no][j], CL_TRUE,
-                                                CL_MAP_WRITE,
-                                                origin_zero, region, &pitch, NULL,
-                                                0, NULL, NULL, &cl_err);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
+                  case GEGL_CL_COLOR_NOT_SUPPORTED:
 
-                  /* color conversion will be performed in the GPU later */
-                  gegl_buffer_get (i->buffer[no], 1.0, &i->roi[no][j], i->buffer[no]->format, data, pitch);
+                    {
+                    g_assert (i->tex_op[no][j] == NULL);
+                    i->tex_op[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
+                                                          CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
+                                                          &i->op_cl_format [no],
+                                                          i->roi[no][j].width,
+                                                          i->roi[no][j].height,
+                                                          0, NULL, &cl_err);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    /* pre-pinned memory */
+                    data = gegl_clEnqueueMapImage(gegl_cl_get_command_queue(), i->tex_op[no][j], CL_TRUE,
+                                                  CL_MAP_WRITE,
+                                                  origin_zero, region, &pitch, NULL,
+                                                  0, NULL, NULL, &cl_err);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    /* color conversion using BABL */
+                    gegl_buffer_get (i->buffer[no], 1.0, &i->roi[no][j], i->format[no], data, pitch);
+
+                    i->tex[no][j] = i->tex_op[no][j];
+
+                    break;
+                    }
 
-                  cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), i->tex_buf[no][j], data,
-                                                         0, NULL, NULL);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
+                  case GEGL_CL_COLOR_EQUAL:
 
-                  i->tex[no][j] = &i->tex_buf[no][j];
-                }
-              else
-                {
-                  g_assert (i->tex_buf[no][j] == NULL);
-                  i->tex_buf[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
-                                                            CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
-                                                            &i->buf_cl_format [no],
-                                                            i->roi[no][j].width,
-                                                            i->roi[no][j].height,
-                                                            0, NULL, &cl_err);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
-
-                  g_assert (i->tex_op[no][j] == NULL);
-                  i->tex_op[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
-                                                           CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
-                                                           &i->op_cl_format [no],
-                                                           i->roi[no][j].width,
-                                                           i->roi[no][j].height,
-                                                           0, NULL, &cl_err);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
+                    {
+                    g_assert (i->tex_buf[no][j] == NULL);
+                    i->tex_buf[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
+                                                              CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
+                                                              &i->buf_cl_format [no],
+                                                              i->roi[no][j].width,
+                                                              i->roi[no][j].height,
+                                                              0, NULL, &cl_err);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    /* pre-pinned memory */
+                    data = gegl_clEnqueueMapImage(gegl_cl_get_command_queue(), i->tex_buf[no][j], CL_TRUE,
+                                                  CL_MAP_WRITE,
+                                                  origin_zero, region, &pitch, NULL,
+                                                  0, NULL, NULL, &cl_err);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    /* color conversion will be performed in the GPU later */
+                    gegl_buffer_get (i->buffer[no], 1.0, &i->roi[no][j], i->buffer[no]->format, data, pitch);
+
+                    cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), i->tex_buf[no][j], data,
+                                                           0, NULL, NULL);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    i->tex[no][j] = i->tex_buf[no][j];
+
+                    break;
+                    }
 
-                  /* pre-pinned memory */
-                  data = gegl_clEnqueueMapImage(gegl_cl_get_command_queue(), i->tex_buf[no][j], CL_TRUE,
-                                                CL_MAP_WRITE,
-                                                origin_zero, region, &pitch, NULL,
-                                                0, NULL, NULL, &cl_err);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
+                  case GEGL_CL_COLOR_CONVERT:
 
-                  /* color conversion will be performed in the GPU later */
-                  gegl_buffer_get (i->buffer[no], 1.0, &i->roi[no][j], i->buffer[no]->format, data, pitch);
+                    {
+                    g_assert (i->tex_buf[no][j] == NULL);
+                    i->tex_buf[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
+                                                              CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
+                                                              &i->buf_cl_format [no],
+                                                              i->roi[no][j].width,
+                                                              i->roi[no][j].height,
+                                                              0, NULL, &cl_err);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    g_assert (i->tex_op[no][j] == NULL);
+                    i->tex_op[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
+                                                             CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
+                                                             &i->op_cl_format [no],
+                                                             i->roi[no][j].width,
+                                                             i->roi[no][j].height,
+                                                             0, NULL, &cl_err);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    /* pre-pinned memory */
+                    data = gegl_clEnqueueMapImage(gegl_cl_get_command_queue(), i->tex_buf[no][j], CL_TRUE,
+                                                  CL_MAP_WRITE,
+                                                  origin_zero, region, &pitch, NULL,
+                                                  0, NULL, NULL, &cl_err);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    /* color conversion will be performed in the GPU later */
+                    gegl_buffer_get (i->buffer[no], 1.0, &i->roi[no][j], i->buffer[no]->format, data, pitch);
+
+                    cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), i->tex_buf[no][j], data,
+                                                           0, NULL, NULL);
+                    if (cl_err != CL_SUCCESS) CL_ERROR;
+
+                    /* color conversion in the GPU (input) */
+                    g_assert (i->tex_buf[no][j] && i->tex_op[no][j]);
+                    cl_err = gegl_cl_color_conv (i->tex_buf[no][j], i->tex_op[no][j], i->size[no][j],
+                                                 i->buffer[no]->format, i->format[no]);
+                    if (cl_err == FALSE) CL_ERROR;
 
-                  cl_err = gegl_clEnqueueUnmapMemObject (gegl_cl_get_command_queue(), i->tex_buf[no][j], data,
-                                                         0, NULL, NULL);
-                  if (cl_err != CL_SUCCESS) CL_ERROR;
+                    i->tex[no][j] = i->tex_buf[no][j];
 
-                  i->tex[no][j] = &i->tex_buf[no][j];
+                    break;
+                    }
                 }
             }
 
-          cl_err = gegl_clEnqueueBarrier(gegl_cl_get_command_queue());
-          if (cl_err != CL_SUCCESS) CL_ERROR;
-
-          /* color conversion in the GPU (input) */
-          if (i->conv[no] == GEGL_CL_COLOR_CONVERT)
-            for (j = 0; j < i->n; j++)
-              {
-                g_assert (i->tex_buf[no][j] && i->tex_op[no][j]);
-                cl_err = gegl_cl_color_conv (i->tex_buf[no][j], i->tex_op[no][j], i->size[no][j],
-                                             i->buffer[no]->format, i->format[no]);
-                if (cl_err == FALSE) CL_ERROR;
-              }
-
           /* Wait Processing */
           cl_err = gegl_clEnqueueBarrier(gegl_cl_get_command_queue());
           if (cl_err != CL_SUCCESS) CL_ERROR;
@@ -377,8 +384,11 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
         {
           for (j=0; j < i->n; j++)
             {
-              if (i->conv[no] == GEGL_CL_COLOR_NOT_SUPPORTED)
+              switch (i->conv[no])
                 {
+                  case GEGL_CL_COLOR_NOT_SUPPORTED:
+
+                  {
                   g_assert (i->tex_op[no][j] == NULL);
                   i->tex_op[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
                                                            CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
@@ -388,10 +398,14 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                                                            0, NULL, &cl_err);
                   if (cl_err != CL_SUCCESS) CL_ERROR;
 
-                  i->tex[no][j] = &i->tex_op[no][j];
-                }
-              else if (i->conv[no] == GEGL_CL_COLOR_EQUAL)
-                {
+                  i->tex[no][j] = i->tex_op[no][j];
+
+                  break;
+                  }
+
+                  case GEGL_CL_COLOR_EQUAL:
+
+                  {
                   g_assert (i->tex_buf[no][j] == NULL);
                   i->tex_buf[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
                                                             CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
@@ -401,10 +415,14 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                                                             0, NULL, &cl_err);
                   if (cl_err != CL_SUCCESS) CL_ERROR;
 
-                  i->tex[no][j] = &i->tex_buf[no][j];
-                }
-              else
-                {
+                  i->tex[no][j] = i->tex_buf[no][j];
+
+                  break;
+                  }
+
+                  case GEGL_CL_COLOR_CONVERT:
+
+                  {
                   g_assert (i->tex_buf[no][j] == NULL);
                   i->tex_buf[no][j] = gegl_clCreateImage2D (gegl_cl_get_context (),
                                                             CL_MEM_ALLOC_HOST_PTR | CL_MEM_READ_WRITE,
@@ -423,14 +441,13 @@ gegl_buffer_cl_iterator_next (GeglBufferClIterator *iterator, gboolean *err)
                                                            0, NULL, &cl_err);
                   if (cl_err != CL_SUCCESS) CL_ERROR;
 
-                  i->tex[no][j] = &i->tex_op[no][j];
-                }
+                  i->tex[no][j] = i->tex_op[no][j];
+
+                  break;
+                  }
+               }
             }
         }
-      else
-        {
-          g_assert (FALSE);
-        }
     }
 
   i->roi_no += i->n;
diff --git a/gegl/buffer/gegl-buffer-cl-iterator.h b/gegl/buffer/gegl-buffer-cl-iterator.h
index 143c57f..5558f9f 100644
--- a/gegl/buffer/gegl-buffer-cl-iterator.h
+++ b/gegl/buffer/gegl-buffer-cl-iterator.h
@@ -17,7 +17,7 @@ typedef struct GeglBufferClIterator
 {
   gint          n;
   size_t        size [GEGL_CL_BUFFER_MAX_ITERATORS][GEGL_CL_NTEX][2];  /* length of current data in pixels */
-  cl_mem       *tex  [GEGL_CL_BUFFER_MAX_ITERATORS][GEGL_CL_NTEX];
+  cl_mem        tex  [GEGL_CL_BUFFER_MAX_ITERATORS][GEGL_CL_NTEX];
   GeglRectangle roi  [GEGL_CL_BUFFER_MAX_ITERATORS][GEGL_CL_NTEX];
 } GeglBufferClIterator;
 
diff --git a/gegl/operation/gegl-operation-point-filter.c b/gegl/operation/gegl-operation-point-filter.c
index 67a73f1..c3eea28 100644
--- a/gegl/operation/gegl-operation-point-filter.c
+++ b/gegl/operation/gegl-operation-point-filter.c
@@ -112,7 +112,7 @@ gegl_operation_point_filter_cl_process (GeglOperation       *operation,
         if (err) return FALSE;
         for (j=0; j < i->n; j++)
           {
-            cl_err = point_filter_class->cl_process(operation, *(i->tex[read][j]), *(i->tex[0][j]),
+            cl_err = point_filter_class->cl_process(operation, i->tex[read][j], i->tex[0][j],
                                                     i->size[0][j], &i->roi[0][j]);
             if (cl_err != CL_SUCCESS)
               {



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