Hey,
On OS X, the methods in NSBitmapImageRep for accessing and setting
pixels use "flipped" coordinates - i.e. [colorAtX:0 y:0] is the
top-left pixel, whereas on GNUstep that returns the bottom-left pixel.
This patch corrects GNUstep to match OS X, and changes the only place
where these methods are used.
-Eric
Index: Source/NSBitmapImageRep.m
===================================================================
--- Source/NSBitmapImageRep.m	(revision 29117)
+++ Source/NSBitmapImageRep.m	(working copy)
@@ -756,6 +756,10 @@
   return value & ((1<<bit_width)-1);
 }
 
+/**
+ * Returns the values of the components of pixel (x,y), where (0,0) is the 
+ * top-left pixel in the image, by storing them in the array pixelData.
+ */
 - (void) getPixel: (unsigned int[])pixelData atX: (int)x y: (int)y
 {
   int i;
@@ -768,9 +772,7 @@
       return;
     }
 
-  // FIXME: The y value is taken from the bottom of the image. 
-  // Not sure if this is correct.
-  line_offset = _bytesPerRow * (_pixelsHigh - 1 - y);
+  line_offset = _bytesPerRow * y;
   if (_isPlanar)
     {
       if (_bitsPerSample == 8)
@@ -847,6 +849,10 @@
   base[byte2] = (value & 255) | (base[byte2] ^ (all & 255));
 }
 
+/**
+ * Sets the components of pixel (x,y), where (0,0) is the top-left pixel in
+ * the image, to the given array of pixel components. 
+ */
 - (void) setPixel: (unsigned int[])pixelData atX: (int)x y: (int)y
 {
   int i;
@@ -865,9 +871,7 @@
       [self bitmapData];
     }
 
-  // FIXME: The y value is taken from the bottom of the image. 
-  // Not sure if this is correct.
-  line_offset = _bytesPerRow * (_pixelsHigh - 1 - y);
+  line_offset = _bytesPerRow * y;
   if(_isPlanar)
     {
       if (_bitsPerSample == 8)
@@ -911,6 +915,10 @@
     }
 }
 
+/**
+ * Returns an NSColor object representing the color of the pixel (x,y), where
+ * (0,0) is the top-left pixel in the image.
+ */
 - (NSColor*) colorAtX: (int)x y: (int)y
 {
 	unsigned int pixelData[5];
@@ -1159,6 +1167,10 @@
 	return nil;
 }
 
+/**
+ * Sets the color of pixel (x,y), where (0,0) is the top-left pixel in the
+ * image.
+ */
 - (void) setColor: (NSColor*)color atX: (int)x y: (int)y
 {
 	unsigned int pixelData[5];
Index: Source/GSThemeTools.m
===================================================================
--- Source/GSThemeTools.m	(revision 29117)
+++ Source/GSThemeTools.m	(working copy)
@@ -791,7 +791,7 @@
 
   for (i = 0; i < s.width; i++)
     {
-      NSColor	*pixelColor = [rep colorAtX: i y: s.height - 1];
+      NSColor	*pixelColor = [rep colorAtX: i y: 0];
 
       [pixelColor getRed: &r green: &g blue: &b alpha: &a];
       if (a > 0 && x1 == -1)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 29117)
+++ ChangeLog	(working copy)
@@ -1,3 +1,11 @@
+2009-12-12 Eric Wasylishen <[email protected]>
+
+	* Source/NSBitmapImageRep.m:
+	* Source/GSThemeTools.m: 
+	Change the colorAtX:y: and related methods in NSBitmapImageRep
+	to use flipped coordinates, matching OS X. colorAtX:0 y:0 now 
+	returns the top-left pixel instead of the bottom left.
+
 2009-12-12 Fred Kiefer <[email protected]>
 
 	* Source/NSApplication (-setWindowsMenu:): Only add windows that 
_______________________________________________
Gnustep-dev mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/gnustep-dev

Reply via email to