From 563470df4c990e6ccf41de7db08dad365cb0930e Mon Sep 17 00:00:00 2001 From: mikeash Date: Thu, 30 Aug 2007 16:09:46 +0000 Subject: [PATCH] Seams: added missing CIImageExtensions git-svn-id: file://localhost/home/mikeash/svn/mikeash@47 1ea6ab17-982b-0410-b0ab-91172c90a6e5 --- Seams/CIImageExtensions.h | 29 ++++++ Seams/CIImageExtensions.m | 142 ++++++++++++++++++++++++++ Seams/Seams.xcodeproj/project.pbxproj | 12 +-- 3 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 Seams/CIImageExtensions.h create mode 100644 Seams/CIImageExtensions.m diff --git a/Seams/CIImageExtensions.h b/Seams/CIImageExtensions.h new file mode 100644 index 0000000..ed5d626 --- /dev/null +++ b/Seams/CIImageExtensions.h @@ -0,0 +1,29 @@ +// +// CIImageExtensions.h +// GreatPhoto +// +// Created by Ron Aldrich on 4/10/07. +// +// This source code is provided by Software Architects, Inc (Herein, SAI). on an +// "AS IS" basis. SAI MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT +// LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE, REGARDING THIS SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL SAI BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND/OR DISTRIBUTION OF THIS SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER +// THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, +// EVEN IF SAI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#import + +@interface CIImage (CIImageExtensions) + +- (float*) getRGBAfBitmap: (CGColorSpaceRef) inColorSpace + fromRect: (CGRect) inFromRect + rowBytes: (size_t*) outRowBytes; + +@end diff --git a/Seams/CIImageExtensions.m b/Seams/CIImageExtensions.m new file mode 100644 index 0000000..008f74a --- /dev/null +++ b/Seams/CIImageExtensions.m @@ -0,0 +1,142 @@ +// +// CIImageExtensions.m +// GreatPhoto +// +// Created by Ron Aldrich on 4/10/07. +// +// This source code is provided by Software Architects, Inc (Herein, SAI). on an +// "AS IS" basis. SAI MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT +// LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND +// FITNESS FOR A PARTICULAR PURPOSE, REGARDING THIS SOFTWARE OR ITS USE AND +// OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. +// +// IN NO EVENT SHALL SAI BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION +// AND/OR DISTRIBUTION OF THIS SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER +// THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, +// EVEN IF SAI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#import "CIImageExtensions.h" + +#import + +/******************************************************************************/ + +@interface CIImage (CIImageExtensionsPrivate) + +- (size_t) rowBytesForWidth: (size_t) inWidth + bytesPerPixel: (size_t) inBytesPerPixel; + +@end + +/******************************************************************************/ + +@implementation CIImage (CIImageExtensionsPrivate) + +/******************************************************************************/ + +- (size_t) rowBytesForWidth: (size_t) inWidth + bytesPerPixel: (size_t) inBytesPerPixel +{ + size_t theResult = (inWidth * inBytesPerPixel + 15) & ~15; + + // Make sure we are not an even power of 2 wide. + // Will loop a few times for rowBytes <= 16. + + while ( 0 == (theResult & (theResult - 1) ) ) + theResult += 16; + + return theResult; +} + +/******************************************************************************/ + +@end + +/******************************************************************************/ + +@implementation CIImage (CIImageExtensions) + +/******************************************************************************/ + +- (float*) getRGBAfBitmap: (CGColorSpaceRef) inColorSpace + fromRect: (CGRect) inFromRect + rowBytes: (size_t*) outRowBytes +{ + CGColorSpaceRef theColorSpace = nil; + + if ((inColorSpace == nil) || (inColorSpace == (CGColorSpaceRef) kCFNull)) + { + theColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB); + + NSParameterAssert(theColorSpace != nil); + + inColorSpace = theColorSpace; + } + + NSParameterAssert(outRowBytes != nil); + + size_t theDestWidth = ceilf(inFromRect.size.width); + size_t theDestHeight = ceilf(inFromRect.size.height); + + CGContextRef theCGContext = nil; + CIContext* theCIContext = nil; + + size_t theBitsPerComponent = 32; + size_t theBytesPerRow = [self rowBytesForWidth: theDestWidth + bytesPerPixel: 16]; + size_t theDataSize = theBytesPerRow * theDestHeight; + + float* theBitmapData = malloc(theDataSize); + + float* theTempPtr = theBitmapData; + unsigned theIndex; + for (theIndex = 0; theIndex < theDataSize; theIndex += sizeof(float)) + *theTempPtr++ = 0.555; + + NSParameterAssert(theBitmapData != nil); + + CGBitmapInfo theBitmapInfo = kCGBitmapFloatComponents | kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Host; + + theCGContext = CGBitmapContextCreate(theBitmapData, + theDestWidth, + theDestHeight, + theBitsPerComponent, + theBytesPerRow, + inColorSpace, + theBitmapInfo); + + NSParameterAssert(theCGContext != nil); + + NSDictionary* theCICContextOptions = [NSDictionary dictionaryWithObjectsAndKeys: + (id) inColorSpace, kCIContextOutputColorSpace, + (id) inColorSpace, kCIContextWorkingColorSpace, + nil]; + + theCIContext = [CIContext contextWithCGContext: theCGContext + options: theCICContextOptions]; + + NSParameterAssert(theCIContext != nil); + + CGContextClearRect(theCGContext, + CGRectMake(0, 0, theDestWidth, theDestHeight)); + + [theCIContext drawImage: self + atPoint: CGPointZero + fromRect: inFromRect]; + + CGContextFlush(theCGContext); + + *outRowBytes = CGBitmapContextGetBytesPerRow(theCGContext); + + CGContextRelease(theCGContext); + CGColorSpaceRelease(theColorSpace); + + return theBitmapData; +} + +/******************************************************************************/ + +@end diff --git a/Seams/Seams.xcodeproj/project.pbxproj b/Seams/Seams.xcodeproj/project.pbxproj index 41cd92f..aeaedc1 100644 --- a/Seams/Seams.xcodeproj/project.pbxproj +++ b/Seams/Seams.xcodeproj/project.pbxproj @@ -13,8 +13,8 @@ 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; C22203B00C85DE960048CB75 /* minpluskernel.cikernel in Resources */ = {isa = PBXBuildFile; fileRef = C22203AF0C85DE960048CB75 /* minpluskernel.cikernel */; }; C22203B50C85DEF30048CB75 /* SeamKernelFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = C22203B40C85DEF30048CB75 /* SeamKernelFilter.m */; }; - C222059B0C85F19B0048CB75 /* CIImageExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = C22205990C85F19B0048CB75 /* CIImageExtensions.m */; }; C222060E0C85F72C0048CB75 /* slicekernel.cikernel in Resources */ = {isa = PBXBuildFile; fileRef = C222060D0C85F72B0048CB75 /* slicekernel.cikernel */; }; + C222F3BA0C8722C9002F6717 /* CIImageExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = C222F3B90C8722C9002F6717 /* CIImageExtensions.m */; }; C24FBC8D0C81079600901AF5 /* SeamAppController.m in Sources */ = {isa = PBXBuildFile; fileRef = C24FBC8C0C81079600901AF5 /* SeamAppController.m */; }; C24FBCD90C8109DF00901AF5 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C24FBCD80C8109DF00901AF5 /* QuartzCore.framework */; }; C288B10A0C81DF710061218B /* SeamImageView.m in Sources */ = {isa = PBXBuildFile; fileRef = C288B1090C81DF710061218B /* SeamImageView.m */; }; @@ -34,9 +34,9 @@ C22203AF0C85DE960048CB75 /* minpluskernel.cikernel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = minpluskernel.cikernel; sourceTree = ""; }; C22203B30C85DEF30048CB75 /* SeamKernelFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SeamKernelFilter.h; sourceTree = ""; }; C22203B40C85DEF30048CB75 /* SeamKernelFilter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SeamKernelFilter.m; sourceTree = ""; }; - C22205990C85F19B0048CB75 /* CIImageExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CIImageExtensions.m; path = ../../../../Downloads/zipM51t8bnkRV/CIImageExtensions.m; sourceTree = SOURCE_ROOT; }; - C222059A0C85F19B0048CB75 /* CIImageExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CIImageExtensions.h; path = ../../../../Downloads/zipM51t8bnkRV/CIImageExtensions.h; sourceTree = SOURCE_ROOT; }; C222060D0C85F72B0048CB75 /* slicekernel.cikernel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = slicekernel.cikernel; sourceTree = ""; }; + C222F3B80C8722C9002F6717 /* CIImageExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CIImageExtensions.h; sourceTree = ""; }; + C222F3B90C8722C9002F6717 /* CIImageExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CIImageExtensions.m; sourceTree = ""; }; C24FBC8B0C81079600901AF5 /* SeamAppController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SeamAppController.h; sourceTree = ""; }; C24FBC8C0C81079600901AF5 /* SeamAppController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SeamAppController.m; sourceTree = ""; }; C24FBCD80C8109DF00901AF5 /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = /System/Library/Frameworks/QuartzCore.framework; sourceTree = ""; }; @@ -66,8 +66,8 @@ C288B1090C81DF710061218B /* SeamImageView.m */, C22203B30C85DEF30048CB75 /* SeamKernelFilter.h */, C22203B40C85DEF30048CB75 /* SeamKernelFilter.m */, - C222059A0C85F19B0048CB75 /* CIImageExtensions.h */, - C22205990C85F19B0048CB75 /* CIImageExtensions.m */, + C222F3B80C8722C9002F6717 /* CIImageExtensions.h */, + C222F3B90C8722C9002F6717 /* CIImageExtensions.m */, ); name = Classes; sourceTree = ""; @@ -200,7 +200,7 @@ C24FBC8D0C81079600901AF5 /* SeamAppController.m in Sources */, C288B10A0C81DF710061218B /* SeamImageView.m in Sources */, C22203B50C85DEF30048CB75 /* SeamKernelFilter.m in Sources */, - C222059B0C85F19B0048CB75 /* CIImageExtensions.m in Sources */, + C222F3BA0C8722C9002F6717 /* CIImageExtensions.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; };