Skip to content

Commit 916fcdc

Browse files
committed
Merge pull request #68 from RSully/bugfix-animagebitmaprep
Replace ANImageBitmapRep with newest version. Fixes #67.
2 parents 3484a7c + 41a0df8 commit 916fcdc

10 files changed

+49
-7
lines changed

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/ANImageBitmapRep.m

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ @implementation ANImageBitmapRep
3838
- (void)forwardInvocation:(NSInvocation *)anInvocation {
3939
if (!baseClasses) [self generateBaseClasses];
4040
for (int i = 0; i < [baseClasses count]; i++) {
41-
BitmapContextManipulator * manip = baseClasses[i];
41+
BitmapContextManipulator * manip = [baseClasses objectAtIndex:i];
4242
if ([manip respondsToSelector:[anInvocation selector]]) {
4343
[anInvocation invokeWithTarget:manip];
4444
return;
@@ -148,7 +148,7 @@ - (void)generateBaseClasses {
148148
BitmapScaleManipulator * scalable = [[BitmapScaleManipulator alloc] initWithContext:self];
149149
BitmapRotationManipulator * rotatable = [[BitmapRotationManipulator alloc] initWithContext:self];
150150
BitmapDrawManipulator * drawable = [[BitmapDrawManipulator alloc] initWithContext:self];
151-
baseClasses = @[croppable, scalable, rotatable, drawable];
151+
baseClasses = [[NSArray alloc] initWithObjects:croppable, scalable, rotatable, drawable, nil];
152152
#if __has_feature(objc_arc) != 1
153153
[rotatable release];
154154
[scalable release];

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/BitmapContextRep.h

+13
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ BMPoint BMPointFromPoint (CGPoint point);
4242
*/
4343
- (id)initWithImage:(ANImageObj *)image;
4444

45+
/**
46+
* Creates a bitmap context with the information from a CGImageRef.
47+
* @param image The image to use for initialization. The reference will
48+
* not be consumed, so you will still need to CGImageRelease() this as expected.
49+
*/
50+
- (id)initWithCGImage:(CGImageRef)img;
51+
4552
/**
4653
* Creates a blank bitmap context with specified dimensions.
4754
* @param sizePoint The size to use for the new bitmap. The x value
@@ -101,6 +108,12 @@ BMPoint BMPointFromPoint (CGPoint point);
101108
*/
102109
- (CGImageRef)CGImage;
103110

111+
/**
112+
* Returns a mutable RGBA data array. If you modify this, you should call
113+
* [context setNeedsUpdate:YES] before calling [context CGImage] or similar.
114+
*/
115+
- (unsigned char *)bitmapData;
116+
104117
@end
105118

106119
@protocol BitmapContextRep

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/BitmapContextRep.m

+16-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ @implementation BitmapContextRep
2727

2828
- (id)initWithImage:(ANImageObj *)image {
2929
if ((self = [super init])) {
30-
context = [CGContextCreator newARGBBitmapContextWithImage:CGImageFromANImage(image)];
30+
CGImageRef img = CGImageFromANImage(image);
31+
context = [CGContextCreator newARGBBitmapContextWithImage:img];
3132
bitmapData = CGBitmapContextGetData(context);
32-
lastImage = CGBitmapContextCreateImage(context);
33+
lastImage = CGImageRetain(img);
34+
}
35+
return self;
36+
}
37+
38+
- (id)initWithCGImage:(CGImageRef)img {
39+
if ((self = [super init])) {
40+
context = [CGContextCreator newARGBBitmapContextWithImage:img];
41+
bitmapData = CGBitmapContextGetData(context);
42+
lastImage = CGImageRetain(img);
3343
}
3444
return self;
3545
}
@@ -114,6 +124,10 @@ - (CGImageRef)CGImage {
114124
#endif
115125
}
116126

127+
- (unsigned char *)bitmapData {
128+
return bitmapData;
129+
}
130+
117131
- (void)dealloc {
118132
CGContextRelease(context);
119133
free(bitmapData);

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/Compatibility/NSImage+ANImageBitmapRep.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
77
//
88

9+
#import "TargetConditionals.h"
10+
911
#if TARGET_OS_IPHONE != 1
1012

1113
#import <Cocoa/Cocoa.h>

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/Compatibility/NSImage+ANImageBitmapRep.m

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
77
//
88

9+
#import "TargetConditionals.h"
10+
911
#if TARGET_OS_IPHONE != 1
1012

1113
#import "NSImage+ANImageBitmapRep.h"

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/Compatibility/OSCommonImage.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#ifndef ImageBitmapRep_OSCommonImage_h
1010
#define ImageBitmapRep_OSCommonImage_h
1111

12+
#import "TargetConditionals.h"
1213
#import "CGImageContainer.h"
1314

1415
#if TARGET_OS_IPHONE

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/Compatibility/UIImage+ANImageBitmapRep.h

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright 2011 __MyCompanyName__. All rights reserved.
77
//
88

9+
#import "TargetConditionals.h"
10+
911
#if TARGET_OS_IPHONE
1012

1113
@class ANImageBitmapRep;

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/Compatibility/UIImage+ANImageBitmapRep.m

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
// Copyright 2011 __MyCompanyName__. All rights reserved.
77
//
88

9+
#import "TargetConditionals.h"
10+
911
#if TARGET_OS_IPHONE
1012

1113
#import "UIImage+ANImageBitmapRep.h"

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/CoreGraphics/CGContextCreator.h

+7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
//
88

99
#import <Foundation/Foundation.h>
10+
#import "TargetConditionals.h"
11+
12+
#if TARGET_OS_IPHONE
13+
#import <CoreGraphics/CoreGraphics.h>
14+
#elif TARGET_OS_MAC
15+
#import <Quartz/Quartz.h>
16+
#endif
1017

1118
/**
1219
* This class has several static methods for creating bitmap contexts.

RSColorPicker/ColorPickerClasses/ANImageBitmapRep/CoreGraphics/CGImageContainer.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,16 @@
66
// Copyright 2011 __MyCompanyName__. All rights reserved.
77
//
88

9-
10-
#if __has_feature(objc_arc) != 1
11-
129
#import <Foundation/Foundation.h>
10+
#import "TargetConditionals.h"
1311

1412
#if TARGET_OS_IPHONE
1513
#import <CoreGraphics/CoreGraphics.h>
1614
#elif TARGET_OS_MAC
1715
#import <Quartz/Quartz.h>
1816
#endif
1917

18+
#if __has_feature(objc_arc) != 1
2019

2120
@interface CGImageContainer : NSObject {
2221
CGImageRef image;

0 commit comments

Comments
 (0)