Skip to content
This repository was archived by the owner on Mar 14, 2020. It is now read-only.

Commit d6138d2

Browse files
committed
Merge pull request #10 from kypselia/master
Solves EXC_BAD_ACCESS on iOS 6 (fixes #8)
2 parents 58c4a1a + ca3d169 commit d6138d2

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

Classes/ImageFilter.m

+24-8
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ - (UIImage*) applyFilter:(FilterCallback)filter context:(void*)context
8181
}
8282

8383
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
84-
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
85-
8684
int length = CFDataGetLength(m_DataRef);
87-
85+
CFMutableDataRef m_DataRefEdit = CFDataCreateMutableCopy(NULL,length,m_DataRef);
86+
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetMutableBytePtr(m_DataRefEdit);
87+
CFRelease(m_DataRefEdit);
88+
8889
for (int i=0; i<length; i+=4)
8990
{
9091
filter(m_PixelBuf,i,context);
@@ -422,7 +423,10 @@ - (UIImage*) applyBlendFilter:(FilterBlendCallback)filter other:(UIImage*)other
422423
}
423424

424425
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
425-
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
426+
int length = CFDataGetLength(m_DataRef);
427+
CFMutableDataRef m_DataRefEdit = CFDataCreateMutableCopy(NULL,length,m_DataRef);
428+
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetMutableBytePtr(m_DataRefEdit);
429+
CFRelease(m_DataRefEdit);
426430

427431
CGImageRef otherImage = other.CGImage;
428432
CFDataRef m_OtherDataRef = CGDataProviderCopyData(CGImageGetDataProvider(otherImage));
@@ -767,8 +771,16 @@ - (UIImage*) applyConvolve:(NSArray*)kernel
767771
CGImageRef inImage = self.CGImage;
768772
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
769773
CFDataRef m_OutDataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
770-
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
771-
UInt8 * m_OutPixelBuf = (UInt8 *) CFDataGetBytePtr(m_OutDataRef);
774+
775+
int length = CFDataGetLength(m_DataRef);
776+
CFMutableDataRef m_DataRefEdit = CFDataCreateMutableCopy(NULL,length,m_DataRef);
777+
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetMutableBytePtr(m_DataRefEdit);
778+
CFRelease(m_DataRefEdit);
779+
780+
int outputLength = CFDataGetLength(m_OutDataRef);
781+
CFMutableDataRef m_OutDataRefEdit = CFDataCreateMutableCopy(NULL,outputLength,m_DataRef);
782+
UInt8 * m_OutPixelBuf = (UInt8 *) CFDataGetMutableBytePtr(m_OutDataRefEdit);
783+
CFRelease(m_OutDataRefEdit);
772784

773785
int h = CGImageGetHeight(inImage);
774786
int w = CGImageGetWidth(inImage);
@@ -950,8 +962,10 @@ - (UIImage*) vignette
950962
{
951963
CGImageRef inImage = self.CGImage;
952964
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
953-
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
954965
int length = CFDataGetLength(m_DataRef);
966+
CFMutableDataRef m_DataRefEdit = CFDataCreateMutableCopy(NULL,length,m_DataRef);
967+
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetMutableBytePtr(m_DataRefEdit);
968+
CFRelease(m_DataRefEdit);
955969
memset(m_PixelBuf,0,length);
956970

957971
CGContextRef ctx = CGBitmapContextCreate(m_PixelBuf,
@@ -988,8 +1002,10 @@ - (UIImage*) darkVignette
9881002
{
9891003
CGImageRef inImage = self.CGImage;
9901004
CFDataRef m_DataRef = CGDataProviderCopyData(CGImageGetDataProvider(inImage));
991-
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetBytePtr(m_DataRef);
9921005
int length = CFDataGetLength(m_DataRef);
1006+
CFMutableDataRef m_DataRefEdit = CFDataCreateMutableCopy(NULL,length,m_DataRef);
1007+
UInt8 * m_PixelBuf = (UInt8 *) CFDataGetMutableBytePtr(m_DataRefEdit);
1008+
CFRelease(m_DataRefEdit);
9931009
memset(m_PixelBuf,0,length);
9941010

9951011
CGContextRef ctx = CGBitmapContextCreate(m_PixelBuf,

0 commit comments

Comments
 (0)