]> granicus.if.org Git - imagemagick/commitdiff
Improved readability.
authordirk <dirk@git.imagemagick.org>
Sun, 27 Mar 2016 11:50:52 +0000 (13:50 +0200)
committerdirk <dirk@git.imagemagick.org>
Sun, 27 Mar 2016 11:50:52 +0000 (13:50 +0200)
MagickCore/accelerate-private.h

index 0a271c8b346cc27a556af4bf05a8fb6b6cad895d..6a158be7e5d7f787504187c186d4747be13093ef 100644 (file)
@@ -365,6 +365,16 @@ OPENCL_ENDIF()
 
   STRINGIFY(
 
+  inline CLQuantum getPixelRed(const __global CLQuantum *p)   { return *p; }
+  inline CLQuantum getPixelGreen(const __global CLQuantum *p) { return *(p+1); }
+  inline CLQuantum getPixelBlue(const __global CLQuantum *p)  { return *(p+2); }
+  inline CLQuantum getPixelAlpha(const __global CLQuantum *p) { return *(p+3); }
+
+  inline void setPixelRed(__global CLQuantum *p,const CLQuantum value)   { *p=value; }
+  inline void setPixelGreen(__global CLQuantum *p,const CLQuantum value) { *(p+1)=value; }
+  inline void setPixelBlue(__global CLQuantum *p,const CLQuantum value)  { *(p+2)=value; }
+  inline void setPixelAlpha(__global CLQuantum *p,const CLQuantum value) { *(p+3)=value; }
+
   inline CLQuantum getBlue(CLPixelType p)               { return p.x; }
   inline void setBlue(CLPixelType* p, CLQuantum value)  { (*p).x = value; }
   inline float getBlueF4(float4 p)                      { return p.x; }
@@ -2106,26 +2116,28 @@ OPENCL_ENDIF()
 */
 
   STRINGIFY(
-  __kernel void Grayscale(__global CLQuantum *im,const int number_channels,
+  __kernel void Grayscale(__global CLQuantum *image,const int number_channels,
     const unsigned int colorspace,const unsigned int method)
   {
     const int x = get_global_id(0);
     const int y = get_global_id(1);
     const int columns = get_global_size(0);
-    const int c = (x * number_channels) + (y * columns * number_channels);
+    __global CLQuantum *p = image+(x * number_channels) + (y * columns * number_channels);
 
     float
-        blue,
-        green,
-        intensity,
-        red;
+      blue,
+      green,
+      red;
+
+    red=(float)getPixelRed(p);
+    green=(float)getPixelGreen(p);
+    blue=(float)getPixelBlue(p);
 
-    red=(float)im[c];
-    green=(float)im[c+1];
-    blue=(float)im[c+2];
+    CLQuantum intensity=ClampToQuantum(GetPixelIntensity(colorspace, method, red, green, blue));
 
-    intensity = GetPixelIntensity(colorspace, method, red, green, blue);
-    im[c] = im[c+1] = im[c+2] = ClampToQuantum(intensity);
+    setPixelRed(p,intensity);
+    setPixelGreen(p,intensity);
+    setPixelBlue(p,intensity);
   }
   )