@@ -54,8 +54,7 @@ -(bool)unpremultiply:(nonnull unsigned char*)data width:(NSInteger)width height:
5454#if TARGET_OS_OSX
5555
5656-(nullable CGImageRef)makeCGImage {
57- NSRect rect = NSMakeRect (0 , 0 , self.size .width , self.size .height );
58- CGImageRef imageRef = [self CGImageForProposedRect: &rect context: nil hints: nil ];
57+ CGImageRef imageRef = [self CGImageForProposedRect: nil context: nil hints: nil ];
5958 return imageRef;
6059}
6160
@@ -70,13 +69,12 @@ - (nullable uint8_t*)jxlRGBAPixels:(nonnull size_t*)bufferSize width:(nonnull in
7069 *ySize = (int )height;
7170
7271 CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB ();
73- CGBitmapInfo bitmapInfo = (int )kCGImageAlphaPremultipliedLast | (int )kCGBitmapByteOrder32Big ;
72+ CGBitmapInfo bitmapInfo = (int )kCGImageAlphaPremultipliedLast | (int )kCGImageByteOrderDefault ;
7473
7574 CGContextRef targetContext = CGBitmapContextCreate (targetMemory, width, height, 8 , stride, colorSpace, bitmapInfo);
7675
7776 [NSGraphicsContext saveGraphicsState ];
7877 [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithCGContext: targetContext flipped: FALSE ]];
79- CGColorSpaceRelease (colorSpace);
8078
8179 [self drawInRect: NSMakeRect (0 , 0 , width, height)
8280 fromRect: NSZeroRect
@@ -86,6 +84,7 @@ - (nullable uint8_t*)jxlRGBAPixels:(nonnull size_t*)bufferSize width:(nonnull in
8684 [NSGraphicsContext restoreGraphicsState ];
8785
8886 CGContextRelease (targetContext);
87+ CGColorSpaceRelease (colorSpace);
8988
9089 if (![self unpremultiply: targetMemory width: width height: height]) {
9190 free (targetMemory);
@@ -94,40 +93,6 @@ - (nullable uint8_t*)jxlRGBAPixels:(nonnull size_t*)bufferSize width:(nonnull in
9493
9594 return targetMemory;
9695}
97-
98- - (bool )jxlRGBAVPixels : (std::vector<uint8_t>&)buf width : (nonnull int *)xSize height : (nonnull int *)ySize {
99- CGImageRef imageRef = [self makeCGImage ];
100- NSUInteger width = CGImageGetWidth (imageRef);
101- NSUInteger height = CGImageGetHeight (imageRef);
102- int stride = (int )4 * (int )width * sizeof (uint8_t );
103- buf.resize (stride * height);
104- *xSize = (int )width;
105- *ySize = (int )height;
106-
107- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB ();
108- CGBitmapInfo bitmapInfo = (int )kCGImageAlphaPremultipliedLast | (int )kCGBitmapByteOrder32Big ;
109-
110- CGContextRef targetContext = CGBitmapContextCreate (buf.data (), width, height, 8 , stride, colorSpace, bitmapInfo);
111-
112- [NSGraphicsContext saveGraphicsState ];
113- [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithCGContext: targetContext flipped: FALSE ]];
114- CGColorSpaceRelease (colorSpace);
115-
116- [self drawInRect: NSMakeRect (0 , 0 , width, height)
117- fromRect: NSZeroRect
118- operation: NSCompositingOperationCopy
119- fraction: 1.0 ];
120-
121- [NSGraphicsContext restoreGraphicsState ];
122-
123- CGContextRelease (targetContext);
124-
125- if (![self unpremultiply: buf.data () width: width height: height]) {
126- return false ;
127- }
128-
129- return true ;
130- }
13196#else
13297- (nullable uint8_t *)jxlRGBAPixels : (nonnull size_t *)bufferSize width : (nonnull int *)xSize height : (nonnull int *)ySize {
13398 CGImageRef imageRef = [self CGImage ];
0 commit comments