-/* xscreensaver, Copyright (c) 1992-2006 Jamie Zawinski <jwz@jwz.org>
+/* xscreensaver, Copyright (c) 1992-2009 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
*/
#import <stdlib.h>
+#import <stdint.h>
#import <Cocoa/Cocoa.h>
#import "jwxyz.h"
#import "grabscreen.h"
int ximw = xim->width;
int ximh = xim->height;
- unsigned long *odata = (unsigned long *) xim->data;
+ uint32_t *odata = (uint32_t *) xim->data;
switch (bpp) {
case 32:
if (spp != 3) abort();
if (bps != 5) abort();
for (y = 0; y < ximh; y++) {
- unsigned short *ip = (unsigned short *) data;
+ uint16_t *ip = (uint16_t *) data;
int x;
for (x = 0; x < ximw; x++) {
- unsigned short p = *ip++;
+ uint16_t p = *ip++;
// This should be ok on both PPC and Intel (ARGB, word order)
unsigned char r = (p >> 10) & 0x1F;
unsigned char g = (p >> 5) & 0x1F;
r = (r << 3) | (r >> 2);
g = (g << 3) | (g >> 2);
b = (b << 3) | (b >> 2);
- unsigned long pixel = 0xFF000000 | (r << 16) | (g << 8) | b;
+ uint32_t pixel = 0xFF000000 | (r << 16) | (g << 8) | b;
// XPutPixel (xim, x, y, pixel);
*odata++ = pixel;
}
CGDirectPaletteRef pal = CGPaletteCreateWithDisplay (cgdpy);
/* Map it to 32bpp pixels */
- unsigned long map[256];
+ uint32_t map[256];
for (y = 0; y < 256; y++) {
CGDeviceColor c = CGPaletteGetColorAtIndex (pal, y);
unsigned char r = c.red * 255.0;
unsigned char g = c.green * 255.0;
unsigned char b = c.blue * 255.0;
- unsigned long pixel = 0xFF000000 | (r << 16) | (g << 8) | b;
+ uint32_t pixel = 0xFF000000 | (r << 16) | (g << 8) | b;
map[y] = pixel;
}
}
+/* Returns the EXIF rotation property of the image, if any.
+ */
+static int
+exif_rotation (const char *filename)
+{
+ /* This is a ridiculous amount of rigamarole to go through, but for some
+ reason the "Orientation" tag does not exist in the "NSImageEXIFData"
+ dictionary inside the NSBitmapImageRep of the NSImage. Several other
+ EXIF tags are there (e.g., shutter speed) but not orientation. WTF?
+ */
+ CFStringRef s = CFStringCreateWithCString (NULL, filename,
+ kCFStringEncodingUTF8);
+ CFURLRef url = CFURLCreateWithFileSystemPath (NULL, s,
+ kCFURLPOSIXPathStyle, 0);
+ CGImageSourceRef cgimg = CGImageSourceCreateWithURL (url, NULL);
+ if (! cgimg) return -1;
+
+ NSDictionary *props = (NSDictionary *)
+ CGImageSourceCopyPropertiesAtIndex (cgimg, 0, NULL);
+ int rot = [[props objectForKey:@"Orientation"] intValue];
+ CFRelease (cgimg);
+ CFRelease (url);
+ CFRelease (s);
+ return rot;
+}
+
+
/* Loads an image file and splats it onto the drawable.
The image is drawn as large as possible while preserving its aspect ratio.
If geom_ret is provided, the actual rectangle the rendered image takes
if (!img)
return False;
- jwxyz_draw_NSImage (DisplayOfScreen (screen), drawable, img, geom_ret);
+ jwxyz_draw_NSImage (DisplayOfScreen (screen), drawable, img, geom_ret,
+ exif_rotation (filename));
[img release];
return True;
}
+