Mercurial > dwindows
comparison mac/dw.m @ 957:beed3e7f9d4b
Fixes to flip pixmaps when loading from file or data on Mac.
Also added bitblt test to the test program.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Mon, 02 May 2011 04:45:38 +0000 |
parents | cfb12bf3bb06 |
children | f6234f870e81 |
comparison
equal
deleted
inserted
replaced
956:a3e4cebf3c99 | 957:beed3e7f9d4b |
---|---|
6031 bytesPerRow:0 | 6031 bytesPerRow:0 |
6032 bitsPerPixel:0]; | 6032 bitsPerPixel:0]; |
6033 return pixmap; | 6033 return pixmap; |
6034 } | 6034 } |
6035 | 6035 |
6036 /* Function takes an NSImage and copies it into a flipped NSBitmapImageRep */ | |
6037 void _flip_image(NSImage *tmpimage, NSBitmapImageRep *image, NSSize size) | |
6038 { | |
6039 [NSGraphicsContext saveGraphicsState]; | |
6040 [NSGraphicsContext setCurrentContext:[NSGraphicsContext | |
6041 graphicsContextWithGraphicsPort:[[NSGraphicsContext graphicsContextWithBitmapImageRep:image] graphicsPort] | |
6042 flipped:YES]]; | |
6043 [[NSDictionary alloc] initWithObjectsAndKeys:image, NSGraphicsContextDestinationAttributeName, nil]; | |
6044 // make a new transform: | |
6045 NSAffineTransform *t = [NSAffineTransform transform]; | |
6046 | |
6047 // by scaling Y negatively, we effectively flip the image: | |
6048 [t scaleXBy:1.0 yBy:-1.0]; | |
6049 | |
6050 // but we also have to translate it back by its height: | |
6051 [t translateXBy:0.0 yBy:-size.height]; | |
6052 | |
6053 // apply the transform: | |
6054 [t concat]; | |
6055 [tmpimage drawAtPoint:NSMakePoint(0, 0) fromRect:NSMakeRect(0, 0, size.width, size.height) | |
6056 operation:NSCompositeSourceOver fraction:1.0]; | |
6057 [NSGraphicsContext restoreGraphicsState]; | |
6058 } | |
6059 | |
6036 /* | 6060 /* |
6037 * Creates a pixmap from a file. | 6061 * Creates a pixmap from a file. |
6038 * Parameters: | 6062 * Parameters: |
6039 * handle: Window handle the pixmap is associated with. | 6063 * handle: Window handle the pixmap is associated with. |
6040 * filename: Name of the file, omit extention to have | 6064 * filename: Name of the file, omit extention to have |
6049 char *ext = _dw_get_image_extension( filename ); | 6073 char *ext = _dw_get_image_extension( filename ); |
6050 | 6074 |
6051 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6075 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
6052 return NULL; | 6076 return NULL; |
6053 NSString *nstr = [ NSString stringWithUTF8String:filename ]; | 6077 NSString *nstr = [ NSString stringWithUTF8String:filename ]; |
6054 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] initWithContentsOfFile:nstr]; | 6078 NSImage *tmpimage = [[NSImage alloc] initWithContentsOfFile:nstr]; |
6055 if(!image && ext) | 6079 if(!tmpimage && ext) |
6056 { | 6080 { |
6057 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; | 6081 nstr = [nstr stringByAppendingString: [NSString stringWithUTF8String:ext]]; |
6058 image = [[NSBitmapImageRep alloc] initWithContentsOfFile:nstr]; | 6082 tmpimage = [[NSImage alloc] initWithContentsOfFile:nstr]; |
6059 } | 6083 } |
6060 NSSize size = [image size]; | 6084 if(!tmpimage) |
6085 return NULL; | |
6086 NSSize size = [tmpimage size]; | |
6087 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] | |
6088 initWithBitmapDataPlanes:NULL | |
6089 pixelsWide:size.width | |
6090 pixelsHigh:size.height | |
6091 bitsPerSample:8 | |
6092 samplesPerPixel:4 | |
6093 hasAlpha:YES | |
6094 isPlanar:NO | |
6095 colorSpaceName:NSDeviceRGBColorSpace | |
6096 bytesPerRow:0 | |
6097 bitsPerPixel:0]; | |
6098 _flip_image(tmpimage, image, size); | |
6061 pixmap->width = size.width; | 6099 pixmap->width = size.width; |
6062 pixmap->height = size.height; | 6100 pixmap->height = size.height; |
6063 pixmap->image = image; | 6101 pixmap->image = image; |
6064 pixmap->handle = handle; | 6102 pixmap->handle = handle; |
6065 return pixmap; | 6103 return pixmap; |
6080 HPIXMAP pixmap; | 6118 HPIXMAP pixmap; |
6081 | 6119 |
6082 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) | 6120 if(!(pixmap = calloc(1,sizeof(struct _hpixmap)))) |
6083 return NULL; | 6121 return NULL; |
6084 NSData *thisdata = [NSData dataWithBytes:data length:len]; | 6122 NSData *thisdata = [NSData dataWithBytes:data length:len]; |
6085 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] initWithData:thisdata]; | 6123 NSImage *tmpimage = [[NSImage alloc] initWithData:thisdata]; |
6086 NSSize size = [image size]; | 6124 if(!tmpimage) |
6125 return NULL; | |
6126 NSSize size = [tmpimage size]; | |
6127 NSBitmapImageRep *image = [[NSBitmapImageRep alloc] | |
6128 initWithBitmapDataPlanes:NULL | |
6129 pixelsWide:size.width | |
6130 pixelsHigh:size.height | |
6131 bitsPerSample:8 | |
6132 samplesPerPixel:4 | |
6133 hasAlpha:YES | |
6134 isPlanar:NO | |
6135 colorSpaceName:NSDeviceRGBColorSpace | |
6136 bytesPerRow:0 | |
6137 bitsPerPixel:0]; | |
6138 _flip_image(tmpimage, image, size); | |
6087 pixmap->width = size.width; | 6139 pixmap->width = size.width; |
6088 pixmap->height = size.height; | 6140 pixmap->height = size.height; |
6089 pixmap->image = image; | 6141 pixmap->image = image; |
6090 pixmap->handle = handle; | 6142 pixmap->handle = handle; |
6091 return pixmap; | 6143 return pixmap; |