@@ -57,7 +57,7 @@ int DecodeImageFromFile(const char *uri, unsigned int frame, REBCDI *codi)
57
57
CGContextRef ctx;
58
58
CFDataRef binSrc;
59
59
60
- NSUInteger w, h;
60
+ NSUInteger w, h, bytes ;
61
61
NSUInteger bytesPerPixel = 4 ;
62
62
NSUInteger bitsPerComponent = 8 ;
63
63
@@ -77,8 +77,10 @@ int DecodeImageFromFile(const char *uri, unsigned int frame, REBCDI *codi)
77
77
ASSERT_NOT_NULL (img, 3 , " create an image" );
78
78
w = CGImageGetWidth (img);
79
79
h = CGImageGetHeight (img);
80
- pixels = (UInt32 *)malloc (w * h * 4 ); // Rebol's library side must free it!
80
+ bytes = w * h * bytesPerPixel;
81
+ pixels = (UInt32 *)malloc (bytes); // Rebol's library side must free it!
81
82
ASSERT_NOT_NULL (pixels, 4 , " allocate pixels buffer" );
83
+ memset (pixels, 0 , bytes);
82
84
space = CGColorSpaceCreateDeviceRGB ();
83
85
ctx = CGBitmapContextCreate (pixels, w, h, bitsPerComponent, bytesPerPixel * w, space, kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little );
84
86
ASSERT_NOT_NULL (ctx, 5 , " create a bitmap context" );
@@ -88,7 +90,7 @@ int DecodeImageFromFile(const char *uri, unsigned int frame, REBCDI *codi)
88
90
89
91
codi->w = (UInt32 )w;
90
92
codi->h = (UInt32 )h;
91
- codi->len = w * h * 4 ;
93
+ codi->len = ( UInt32 )bytes ;
92
94
codi->data = (unsigned char *)pixels;
93
95
} while (FALSE );
94
96
SAFE_CF_RELEASE (url);
0 commit comments