Changeset View
Changeset View
Standalone View
Standalone View
intern/ghost/intern/GHOST_SystemCocoa.mm
| Show All 13 Lines | |||||
| * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||||
| * | * | ||||
| * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. | ||||
| * All rights reserved. | * All rights reserved. | ||||
| */ | */ | ||||
| #include "GHOST_SystemCocoa.h" | #include "GHOST_SystemCocoa.h" | ||||
| #include "GHOST_Bitmap.h" | |||||
| #include "GHOST_DisplayManagerCocoa.h" | #include "GHOST_DisplayManagerCocoa.h" | ||||
| #include "GHOST_EventButton.h" | #include "GHOST_EventButton.h" | ||||
| #include "GHOST_EventCursor.h" | #include "GHOST_EventCursor.h" | ||||
| #include "GHOST_EventDragnDrop.h" | #include "GHOST_EventDragnDrop.h" | ||||
| #include "GHOST_EventKey.h" | #include "GHOST_EventKey.h" | ||||
| #include "GHOST_EventString.h" | #include "GHOST_EventString.h" | ||||
| #include "GHOST_EventTrackpad.h" | #include "GHOST_EventTrackpad.h" | ||||
| #include "GHOST_EventWheel.h" | #include "GHOST_EventWheel.h" | ||||
| ▲ Show 20 Lines • Show All 1,175 Lines • ▼ Show 20 Lines | case GHOST_kEventDraggingDropDone: { | ||||
| temp_buff[pastedTextSize] = '\0'; | temp_buff[pastedTextSize] = '\0'; | ||||
| eventData = (GHOST_TEventDataPtr)temp_buff; | eventData = (GHOST_TEventDataPtr)temp_buff; | ||||
| break; | break; | ||||
| case GHOST_kDragnDropTypeBitmap: { | case GHOST_kDragnDropTypeBitmap: { | ||||
| NSImage *droppedImg = (NSImage *)data; | NSImage *droppedImg = (NSImage *)data; | ||||
| NSSize imgSize = [droppedImg size]; | NSSize imgSize = [droppedImg size]; | ||||
| ImBuf *ibuf = NULL; | GHOST_Bitmap *bitmap = NULL; | ||||
| GHOST_TUns8 *rasterRGB = NULL; | GHOST_TUns8 *rasterRGB = NULL; | ||||
| GHOST_TUns8 *rasterRGBA = NULL; | GHOST_TUns8 *rasterRGBA = NULL; | ||||
| GHOST_TUns8 *toIBuf = NULL; | GHOST_TUns8 *toBuf = NULL; | ||||
| int x, y, to_i, from_i; | int x, y, to_i, from_i; | ||||
| NSBitmapImageRep *blBitmapFormatImageRGB, *blBitmapFormatImageRGBA, *bitmapImage = nil; | NSBitmapImageRep *blBitmapFormatImageRGB, *blBitmapFormatImageRGBA, *bitmapImage = nil; | ||||
| NSEnumerator *enumerator; | NSEnumerator *enumerator; | ||||
| NSImageRep *representation; | NSImageRep *representation; | ||||
| ibuf = IMB_allocImBuf(imgSize.width, imgSize.height, 32, IB_rect); | bitmap = new GHOST_bitmap(imgSize.width, imgSize.height); | ||||
| if (!ibuf) { | if (!ibuf.isAllocated()) { | ||||
| [droppedImg release]; | [droppedImg release]; | ||||
| delete bitmap; | |||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| /*Get the bitmap of the image*/ | /*Get the bitmap of the image*/ | ||||
| enumerator = [[droppedImg representations] objectEnumerator]; | enumerator = [[droppedImg representations] objectEnumerator]; | ||||
| while ((representation = [enumerator nextObject])) { | while ((representation = [enumerator nextObject])) { | ||||
| if ([representation isKindOfClass:[NSBitmapImageRep class]]) { | if ([representation isKindOfClass:[NSBitmapImageRep class]]) { | ||||
| bitmapImage = (NSBitmapImageRep *)representation; | bitmapImage = (NSBitmapImageRep *)representation; | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| if (bitmapImage == nil) | if (bitmapImage == nil) | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| if (([bitmapImage bitsPerPixel] == 32) && (([bitmapImage bitmapFormat] & 0x5) == 0) && | if (([bitmapImage bitsPerPixel] == 32) && (([bitmapImage bitmapFormat] & 0x5) == 0) && | ||||
| ![bitmapImage isPlanar]) { | ![bitmapImage isPlanar]) { | ||||
| /* Try a fast copy if the image is a meshed RGBA 32bit bitmap*/ | /* Try a fast copy if the image is a meshed RGBA 32bit bitmap*/ | ||||
| toIBuf = (GHOST_TUns8 *)ibuf->rect; | toBuf = (GHOST_TUns8 *)image->getBuffer(); | ||||
| rasterRGB = (GHOST_TUns8 *)[bitmapImage bitmapData]; | rasterRGB = (GHOST_TUns8 *)[bitmapImage bitmapData]; | ||||
| for (y = 0; y < imgSize.height; y++) { | for (y = 0; y < imgSize.height; y++) { | ||||
| to_i = (imgSize.height - y - 1) * imgSize.width; | to_i = (imgSize.height - y - 1) * imgSize.width; | ||||
| from_i = y * imgSize.width; | from_i = y * imgSize.width; | ||||
| memcpy(toIBuf + 4 * to_i, rasterRGB + 4 * from_i, 4 * imgSize.width); | memcpy(toBuf + 4 * to_i, rasterRGB + 4 * from_i, 4 * imgSize.width); | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* Tell cocoa image resolution is same as current system one */ | /* Tell cocoa image resolution is same as current system one */ | ||||
| [bitmapImage setSize:imgSize]; | [bitmapImage setSize:imgSize]; | ||||
| /* Convert the image in a RGBA 32bit format */ | /* Convert the image in a RGBA 32bit format */ | ||||
| /* As Core Graphics does not support contextes with non premutliplied alpha, | /* As Core Graphics does not support contextes with non premutliplied alpha, | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | case GHOST_kEventDraggingDropDone: { | ||||
| if (rasterRGBA == NULL) { | if (rasterRGBA == NULL) { | ||||
| [bitmapImage release]; | [bitmapImage release]; | ||||
| [blBitmapFormatImageRGB release]; | [blBitmapFormatImageRGB release]; | ||||
| [blBitmapFormatImageRGBA release]; | [blBitmapFormatImageRGBA release]; | ||||
| [droppedImg release]; | [droppedImg release]; | ||||
| return GHOST_kFailure; | return GHOST_kFailure; | ||||
| } | } | ||||
| /*Copy the image to ibuf, flipping it vertically*/ | /*Copy the image to bitmap, flipping it vertically*/ | ||||
| toIBuf = (GHOST_TUns8 *)ibuf->rect; | toBuf = (GHOST_TUns8 *)bitmap->getBuffer(); | ||||
| for (y = 0; y < imgSize.height; y++) { | for (y = 0; y < imgSize.height; y++) { | ||||
| for (x = 0; x < imgSize.width; x++) { | for (x = 0; x < imgSize.width; x++) { | ||||
| to_i = (imgSize.height - y - 1) * imgSize.width + x; | to_i = (imgSize.height - y - 1) * imgSize.width + x; | ||||
| from_i = y * imgSize.width + x; | from_i = y * imgSize.width + x; | ||||
| toIBuf[4 * to_i] = rasterRGB[4 * from_i]; /* R */ | toBuf[4 * to_i] = rasterRGB[4 * from_i]; /* R */ | ||||
| toIBuf[4 * to_i + 1] = rasterRGB[4 * from_i + 1]; /* G */ | toBuf[4 * to_i + 1] = rasterRGB[4 * from_i + 1]; /* G */ | ||||
| toIBuf[4 * to_i + 2] = rasterRGB[4 * from_i + 2]; /* B */ | toBuf[4 * to_i + 2] = rasterRGB[4 * from_i + 2]; /* B */ | ||||
| toIBuf[4 * to_i + 3] = rasterRGBA[4 * from_i + 3]; /* A */ | toBuf[4 * to_i + 3] = rasterRGBA[4 * from_i + 3]; /* A */ | ||||
| } | } | ||||
| } | } | ||||
| [blBitmapFormatImageRGB release]; | [blBitmapFormatImageRGB release]; | ||||
| [blBitmapFormatImageRGBA release]; | [blBitmapFormatImageRGBA release]; | ||||
| [droppedImg release]; | [droppedImg release]; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 643 Lines • Show Last 20 Lines | |||||