[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [24159] trunk/blender: Mac / COCOA : Imbuf

Damien Plisson damien.plisson at yahoo.fr
Thu Oct 29 19:06:49 CET 2009


Revision: 24159
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=24159
Author:   damien78
Date:     2009-10-29 19:06:49 +0100 (Thu, 29 Oct 2009)

Log Message:
-----------
Mac / COCOA : Imbuf

- replace libtiff by calls to Cocoa services to load/save tiff files
(Libtiff, dynamically linked is not distributed with OS X, and would have had to be shipped for all four architectures)

The imb_cocoaLoadImage & imb_cocoaSaveImage are generic towards the bitmap format, and thus can handle TIFF, GIF, JPG, JP2000, BMP and raw camera formats (read-only for these), even if today only TIFF is used as the other formats are already handled.

- CMake updated
- scons updated (Thx to Jens Verwiebe)

Modified Paths:
--------------
    trunk/blender/SConstruct
    trunk/blender/intern/ghost/SConscript
    trunk/blender/source/blender/imbuf/CMakeLists.txt
    trunk/blender/source/blender/imbuf/SConscript
    trunk/blender/source/blender/imbuf/intern/readimage.c
    trunk/blender/source/blender/imbuf/intern/writeimage.c
    trunk/blender/source/blender/windowmanager/intern/wm_init_exit.c
    trunk/blender/source/creator/creator.c

Added Paths:
-----------
    trunk/blender/source/blender/imbuf/intern/IMB_cocoa.h
    trunk/blender/source/blender/imbuf/intern/imbuf_cocoa.m

Modified: trunk/blender/SConstruct
===================================================================
--- trunk/blender/SConstruct	2009-10-29 17:57:02 UTC (rev 24158)
+++ trunk/blender/SConstruct	2009-10-29 18:06:49 UTC (rev 24159)
@@ -217,6 +217,11 @@
 				env.Append(CPPFLAGS=['-fopenmp'])
 				env.Append(CXXFLAGS=['-fopenmp'])
 
+if env['WITH_GHOST_COCOA'] == True:
+	env.Append(CFLAGS=['-DGHOST_COCOA']) 
+	env.Append(CXXFLAGS=['-DGHOST_COCOA'])
+	env.Append(CPPFLAGS=['-DGHOST_COCOA'])
+
 #check for additional debug libnames
 
 if env.has_key('BF_DEBUG_LIBS'):

Modified: trunk/blender/intern/ghost/SConscript
===================================================================
--- trunk/blender/intern/ghost/SConscript	2009-10-29 17:57:02 UTC (rev 24158)
+++ trunk/blender/intern/ghost/SConscript	2009-10-29 18:06:49 UTC (rev 24159)
@@ -10,10 +10,10 @@
 if window_system == 'darwin':
 	sources += env.Glob('intern/*.mm')
 
-if env['WITH_GHOST_COCOA'] == True:
-	env.Append(CFLAGS=['-DGHOST_COCOA']) 
-	env.Append(CXXFLAGS=['-DGHOST_COCOA'])
-	env.Append(CPPFLAGS=['-DGHOST_COCOA'])
+#if env['WITH_GHOST_COCOA'] == True:
+#	env.Append(CFLAGS=['-DGHOST_COCOA']) 
+#	env.Append(CXXFLAGS=['-DGHOST_COCOA'])
+#	env.Append(CPPFLAGS=['-DGHOST_COCOA'])
 
 #defs = ''
 #if env['WITH_GHOST_COCOA']:

Modified: trunk/blender/source/blender/imbuf/CMakeLists.txt
===================================================================
--- trunk/blender/source/blender/imbuf/CMakeLists.txt	2009-10-29 17:57:02 UTC (rev 24158)
+++ trunk/blender/source/blender/imbuf/CMakeLists.txt	2009-10-29 18:06:49 UTC (rev 24159)
@@ -24,7 +24,13 @@
 #
 # ***** END GPL LICENSE BLOCK *****
 
-FILE(GLOB SRC intern/*.c)
+IF(WITH_COCOA)
+	FILE(GLOB SRC intern/*.c intern/*.m)
+	LIST(REMOVE_ITEM SRC "${CMAKE_CURRENT_SOURCE_DIR}/intern/dynlibtiff.c")
+	LIST(REMOVE_ITEM SRC "${CMAKE_CURRENT_SOURCE_DIR}/intern/tiff.c")
+ELSE(WITH_COCOA)
+	FILE(GLOB SRC intern/*.c)
+ENDIF(WITH_COCOA)
 
 SET(INC 
 	. ../makesdna ../../../intern/guardedalloc ../../../intern/memutil ../blenlib
@@ -54,7 +60,7 @@
 	ADD_DEFINITIONS(-DWITH_FFMPEG)
 ENDIF(WITH_FFMPEG)
 
-if(WITH_DDS)
+IF(WITH_DDS)
 	ADD_DEFINITIONS(-DWITH_DDS)
 ENDIF(WITH_DDS)
 

Modified: trunk/blender/source/blender/imbuf/SConscript
===================================================================
--- trunk/blender/source/blender/imbuf/SConscript	2009-10-29 17:57:02 UTC (rev 24158)
+++ trunk/blender/source/blender/imbuf/SConscript	2009-10-29 18:06:49 UTC (rev 24159)
@@ -2,10 +2,15 @@
 Import ('env')
 
 sources = env.Glob('intern/*.c')
+if env['WITH_GHOST_COCOA']:
+	sources += env.Glob('intern/*.m')
+	sources.remove('intern/dynlibtiff.c')
+	sources.remove('intern/tiff.c')
 
 incs = '. ../makesdna #/intern/guardedalloc #/intern/memutil ../blenlib'
 incs += ' ../avi ../blenkernel'
 
+
 incs += ' ' + env['BF_JPEG_INC']
 incs += ' ' + env['BF_PNG_INC']
 incs += ' ' + env['BF_TIFF_INC']

Added: trunk/blender/source/blender/imbuf/intern/IMB_cocoa.h
===================================================================
--- trunk/blender/source/blender/imbuf/intern/IMB_cocoa.h	                        (rev 0)
+++ trunk/blender/source/blender/imbuf/intern/IMB_cocoa.h	2009-10-29 18:06:49 UTC (rev 24159)
@@ -0,0 +1,43 @@
+/*
+ * IMB_cocoa.h
+ *
+ * $Id: IMB_cocoa.h 13161 2008-01-07 19:13:47Z hos $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Contributor(s): Damien Plisson 10/2009
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+/**
+ * \file IMB_cocoa.h
+ * \ingroup imbuf
+ * \brief Function declarations for imbuf_cocoa.m
+ */
+
+#ifndef IMB_COCOA_H
+#define IMB_COCOA_H
+
+/* Foward declaration of ImBuf structure. */
+struct ImBuf;
+
+/* Declarations for imbuf_cocoa.m */
+struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, int size, int flags);
+short imb_cocoaSaveImage(struct ImBuf *ibuf, char *name, int flags);
+
+#endif /* IMB_COCOA_H */
+

Added: trunk/blender/source/blender/imbuf/intern/imbuf_cocoa.m
===================================================================
--- trunk/blender/source/blender/imbuf/intern/imbuf_cocoa.m	                        (rev 0)
+++ trunk/blender/source/blender/imbuf/intern/imbuf_cocoa.m	2009-10-29 18:06:49 UTC (rev 24159)
@@ -0,0 +1,382 @@
+/*
+ * imbuf_coca.m
+ *
+ * $Id: imbuf_cocoa.m 17958 2008-12-19 19:11:02Z blendix $
+ * 
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ *
+ * Contributor(s): Damien Plisson 10/2009
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/**
+ * Provides image file loading and saving for Blender, via Cocoa.
+ *
+ */
+
+#include <string.h>
+#import <Cocoa/Cocoa.h>
+
+#include "imbuf.h"
+#include "imbuf_patch.h"
+
+#include "IMB_cocoa.h"
+
+#include "BKE_global.h"
+#include "BKE_colortools.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+
+#include "IMB_allocimbuf.h"
+
+
+
+#pragma mark load/save functions
+
+/**
+ * Loads an image from the supplied buffer
+ *
+ * Loads any Core Graphics supported type
+ * Currently is : TIFF, BMP, JPEG, GIF, PNG, DIB, ICO, and various RAW formats
+ *
+ * @param mem:   Memory containing the bitmap image
+ * @param size:  Size of the mem buffer.
+ * @param flags: If flags has IB_test set then the file is not actually loaded,
+ *                but all other operations take place.
+ *
+ * @return: A newly allocated ImBuf structure if successful, otherwise NULL.
+ */
+struct ImBuf *imb_cocoaLoadImage(unsigned char *mem, int size, int flags)
+{
+	struct ImBuf *ibuf = NULL;
+	uint32 width, height;
+	uchar *rasterRGB = NULL;
+	uchar *rasterRGBA = NULL;
+	uchar *toIBuf = NULL;
+	int x, y, to_i, from_i;
+	NSData *data;
+	NSBitmapImageRep *bitmapImage;
+	NSBitmapImageRep *blBitmapFormatImageRGB,*blBitmapFormatImageRGBA;
+	NSAutoreleasePool *pool;
+	
+	pool = [[NSAutoreleasePool alloc] init];
+	
+	data = [NSData dataWithBytes:mem length:size];
+	bitmapImage = [[NSBitmapImageRep alloc] initWithData:data];
+
+	if (!bitmapImage) {
+		fprintf(stderr, "imb_cocoaLoadImage: error loading image\n");
+		[pool drain];
+		return NULL;
+	}
+	
+	width = [bitmapImage pixelsWide];
+	height = [bitmapImage pixelsHigh];
+	
+	/* allocate the image buffer */
+	ibuf = IMB_allocImBuf(width, height, 32/*RGBA*/, 0, 0);
+	if (!ibuf) {
+		fprintf(stderr, 
+			"imb_cocoaLoadImage: could not allocate memory for the " \
+			"image.\n");
+		[bitmapImage release];
+		[pool drain];
+		return NULL;
+	}
+
+	/* read in the image data */
+	if (!(flags & IB_test)) {
+
+		/* allocate memory for the ibuf->rect */
+		imb_addrectImBuf(ibuf);
+
+		/* Convert the image in a RGBA 32bit format */
+		/* As Core Graphics does not support contextes with non premutliplied alpha,
+		 we need to get alpha key values in a separate batch */
+		
+		/* First get RGB values w/o Alpha to avoid pre-multiplication, 32bit but last byte is unused */
+		blBitmapFormatImageRGB = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
+																	  pixelsWide:width 
+																	  pixelsHigh:height
+																   bitsPerSample:8 samplesPerPixel:3 hasAlpha:NO isPlanar:NO
+																  colorSpaceName:NSCalibratedRGBColorSpace 
+																	bitmapFormat:0
+																	 bytesPerRow:4*width
+																	bitsPerPixel:32/*RGB format padded to 32bits*/];
+				
+		[NSGraphicsContext saveGraphicsState];
+		[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:blBitmapFormatImageRGB]];
+		[bitmapImage draw];
+		[NSGraphicsContext restoreGraphicsState];
+		
+		rasterRGB = (uchar*)[blBitmapFormatImageRGB bitmapData];
+		if (rasterRGB == NULL) {
+			[bitmapImage release];
+			[blBitmapFormatImageRGB release];
+			[pool drain];
+			return NULL;
+		}
+
+		/* Then get Alpha values by getting the RGBA image (that is premultiplied btw) */
+		blBitmapFormatImageRGBA = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:NULL
+																		  pixelsWide:width
+																		  pixelsHigh:height
+																	   bitsPerSample:8 samplesPerPixel:4 hasAlpha:YES isPlanar:NO
+																	  colorSpaceName:NSCalibratedRGBColorSpace
+																		bitmapFormat:0
+																		 bytesPerRow:4*width
+																		bitsPerPixel:32/* RGBA */];
+		
+		[NSGraphicsContext saveGraphicsState];
+		[NSGraphicsContext setCurrentContext:[NSGraphicsContext graphicsContextWithBitmapImageRep:blBitmapFormatImageRGBA]];
+		[bitmapImage draw];
+		[NSGraphicsContext restoreGraphicsState];
+		
+		rasterRGBA = (uchar*)[blBitmapFormatImageRGBA bitmapData];
+		if (rasterRGBA == NULL) {
+			[bitmapImage release];
+			[blBitmapFormatImageRGB release];
+			[blBitmapFormatImageRGBA release];
+			[pool drain];
+			return NULL;
+		}
+		
+		/*Copy the image to ibuf, flipping it vertically*/
+		toIBuf = (uchar*)ibuf->rect;
+		for (x = 0; x < width; x++) {
+			for (y = 0; y < height; y++) {
+				to_i = (height-y-1)*width + x;
+				from_i = y*width + x;
+
+				toIBuf[4*to_i] = rasterRGB[4*from_i]; /* R */
+				toIBuf[4*to_i+1] = rasterRGB[4*from_i+1]; /* G */
+				toIBuf[4*to_i+2] = rasterRGB[4*from_i+2]; /* B */
+				toIBuf[4*to_i+3] = rasterRGBA[4*from_i+3]; /* A */
+			}

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list