* src/profiler.c: Delete.
[bpt/emacs.git] / src / nsimage.m
index a4535c5..6b68072 100644 (file)
@@ -1,6 +1,6 @@
 /* Image support for the NeXT/Open/GNUstep and MacOSX window system.
-   Copyright (C) 1989, 1992, 1993, 1994, 2005, 2006, 2008, 2009, 2010, 2011, 2012
-     Free Software Foundation, Inc.
+   Copyright (C) 1989, 1992-1994, 2005-2006, 2008-2014 Free Software
+   Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -27,8 +27,7 @@ GNUstep port and post-20 update by Adrian Robert (arobert@cogsci.ucsd.edu)
 
 /* This should be the first include, as it may set up #defines affecting
    interpretation of even the system includes. */
-#include "config.h"
-#include <setjmp.h>
+#include <config.h>
 
 #include "lisp.h"
 #include "dispextern.h"
@@ -79,23 +78,25 @@ ns_image_from_file (Lisp_Object file)
   return [EmacsImage allocInitFromFile: file];
 }
 
-int
+bool
 ns_load_image (struct frame *f, struct image *img,
                Lisp_Object spec_file, Lisp_Object spec_data)
 {
-  NSTRACE (ns_load_image);
-
-  EmacsImage *eImg;
+  EmacsImage *eImg = nil;
   NSSize size;
 
-  if (NILP (spec_data))
+  NSTRACE (ns_load_image);
+
+  if (STRINGP (spec_file))
     {
       eImg = [EmacsImage allocInitFromFile: spec_file];
     }
-  else
+  else if (STRINGP (spec_data))
     {
-      NSData *data = [NSData dataWithBytes: SDATA (spec_data)
-                                    length: SBYTES (spec_data)];
+      NSData *data;
+
+      data = [NSData dataWithBytes: SSDATA (spec_data)
+                           length: SBYTES (spec_data)];
       eImg = [[EmacsImage alloc] initWithData: data];
       [eImg setPixmapData];
     }
@@ -169,7 +170,7 @@ static EmacsImage *ImageList = nil;
 
   /* look for an existing image of the same name */
   while (image != nil &&
-         [[image name] compare: [NSString stringWithUTF8String: SDATA (file)]]
+         [[image name] compare: [NSString stringWithUTF8String: SSDATA (file)]]
              != NSOrderedSame)
     image = [image imageListNext];
 
@@ -185,9 +186,13 @@ static EmacsImage *ImageList = nil;
     return nil;
 
   image = [[EmacsImage alloc] initByReferencingFile:
-                     [NSString stringWithUTF8String: SDATA (found)]];
+                     [NSString stringWithUTF8String: SSDATA (found)]];
 
+#if defined (NS_IMPL_COCOA) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
+  imgRep = [NSBitmapImageRep imageRepWithData:[image TIFFRepresentation]];
+#else
   imgRep = [image bestRepresentationForDevice: nil];
+#endif
   if (imgRep == nil)
     {
       [image release];
@@ -199,7 +204,7 @@ static EmacsImage *ImageList = nil;
   [image setScalesWhenResized: YES];
   [image setSize: NSMakeSize([imgRep pixelsWide], [imgRep pixelsHigh])];
 
-  [image setName: [NSString stringWithUTF8String: SDATA (file)]];
+  [image setName: [NSString stringWithUTF8String: SSDATA (file)]];
   [image reference];
   ImageList = [image imageListSetNext: ImageList];
 
@@ -296,7 +301,7 @@ static EmacsImage *ImageList = nil;
                   [bmRep release];
                   return nil;
                 }
-#define hexchar(x) (isdigit (x) ? x - '0' : x - 'a' + 10)
+#define hexchar(x) ('0' <= (x) && (x) <= '9' ? (x) - '0' : (x) - 'a' + 10)
               s1 = *s++;
               s2 = *s++;
               c = hexchar (s1) * 0x10 + hexchar (s2);
@@ -315,9 +320,9 @@ static EmacsImage *ImageList = nil;
 
   [self addRepresentation: bmRep];
 
-  bzero (planes[0], w*h);
-  bzero (planes[1], w*h);
-  bzero (planes[2], w*h);
+  memset (planes[0], 0, w*h);
+  memset (planes[1], 0, w*h);
+  memset (planes[2], 0, w*h);
   [self setXBMColor: [NSColor blackColor]];
   return self;
 }
@@ -328,13 +333,12 @@ static EmacsImage *ImageList = nil;
 - setXBMColor: (NSColor *)color
 {
   NSSize s = [self size];
-  int len = (int) s.width * s.height;
   unsigned char *planes[5];
-  CGFloat r, g, b, a;
+  EmacsCGFloat r, g, b, a;
   NSColor *rgbColor;
 
   if (bmRep == nil || color == nil)
-    return;
+    return self;
 
   if ([color colorSpaceName] != NSCalibratedRGBColorSpace)
     rgbColor = [color colorUsingColorSpaceName: NSCalibratedRGBColorSpace];
@@ -359,6 +363,8 @@ static EmacsImage *ImageList = nil;
           planes[2][i] = bb;
         }
   }
+
+  return self;
 }
 
 
@@ -379,7 +385,7 @@ static EmacsImage *ImageList = nil;
 
   [bmRep getBitmapDataPlanes: pixmapData];
   for (i =0; i<4; i++)
-    bzero (pixmapData[i], width*height);
+    memset (pixmapData[i], 0, width*height);
   [self addRepresentation: bmRep];
   return self;
 }
@@ -392,12 +398,11 @@ static EmacsImage *ImageList = nil;
   NSImageRep *rep;
 
   reps = [[self representations] objectEnumerator];
-  while (rep = (NSImageRep *) [reps nextObject])
+  while ((rep = (NSImageRep *) [reps nextObject]))
     {
       if ([rep respondsToSelector: @selector (getBitmapDataPlanes:)])
         {
           bmRep = (NSBitmapImageRep *) rep;
-          onTiger = [bmRep respondsToSelector: @selector (colorAtX:y:)];
 
           if ([bmRep numberOfPlanes] >= 3)
               [bmRep getBitmapDataPlanes: pixmapData];
@@ -429,17 +434,16 @@ static EmacsImage *ImageList = nil;
        | (pixmapData[0][loc] << 16) | (pixmapData[1][loc] << 8)
        | (pixmapData[2][loc]);
     }
-  else if (onTiger)
+  else
     {
       NSColor *color = [bmRep colorAtX: x y: y];
-      CGFloat r, g, b, a;
+      EmacsCGFloat r, g, b, a;
       [color getRed: &r green: &g blue: &b alpha: &a];
       return ((int)(a * 255.0) << 24)
         | ((int)(r * 255.0) << 16) | ((int)(g * 255.0) << 8)
         | ((int)(b * 255.0));
 
     }
-  return 0;
 }
 
 - (void) setPixelAtX: (int)x Y: (int)y toRed: (unsigned char)r
@@ -457,7 +461,7 @@ static EmacsImage *ImageList = nil;
       pixmapData[2][loc] = b;
       pixmapData[3][loc] = a;
     }
-  else if (onTiger)
+  else
     {
       [bmRep setColor:
                [NSColor colorWithCalibratedRed: (r/255.0) green: (g/255.0)
@@ -477,7 +481,7 @@ static EmacsImage *ImageList = nil;
 
       pixmapData[3][loc] = a;
     }
-  else if (onTiger)
+  else
     {
       NSColor *color = [bmRep colorAtX: x y: y];
       color = [color colorWithAlphaComponent: (a / 255.0)];
@@ -494,5 +498,3 @@ static EmacsImage *ImageList = nil;
 }
 
 @end
-
-// arch-tag: 6b310280-6892-4e5e-8f34-41c4d384874f