@@ -54,8 +54,7 @@ -(bool)unpremultiply:(nonnull unsigned char*)data width:(NSInteger)width height:
54
54
#if TARGET_OS_OSX
55
55
56
56
-(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 ];
59
58
return imageRef;
60
59
}
61
60
@@ -70,13 +69,12 @@ - (nullable uint8_t*)jxlRGBAPixels:(nonnull size_t*)bufferSize width:(nonnull in
70
69
*ySize = (int )height;
71
70
72
71
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB ();
73
- CGBitmapInfo bitmapInfo = (int )kCGImageAlphaPremultipliedLast | (int )kCGBitmapByteOrder32Big ;
72
+ CGBitmapInfo bitmapInfo = (int )kCGImageAlphaPremultipliedLast | (int )kCGImageByteOrderDefault ;
74
73
75
74
CGContextRef targetContext = CGBitmapContextCreate (targetMemory, width, height, 8 , stride, colorSpace, bitmapInfo);
76
75
77
76
[NSGraphicsContext saveGraphicsState ];
78
77
[NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithCGContext: targetContext flipped: FALSE ]];
79
- CGColorSpaceRelease (colorSpace);
80
78
81
79
[self drawInRect: NSMakeRect (0 , 0 , width, height)
82
80
fromRect: NSZeroRect
@@ -86,6 +84,7 @@ - (nullable uint8_t*)jxlRGBAPixels:(nonnull size_t*)bufferSize width:(nonnull in
86
84
[NSGraphicsContext restoreGraphicsState ];
87
85
88
86
CGContextRelease (targetContext);
87
+ CGColorSpaceRelease (colorSpace);
89
88
90
89
if (![self unpremultiply: targetMemory width: width height: height]) {
91
90
free (targetMemory);
@@ -94,40 +93,6 @@ - (nullable uint8_t*)jxlRGBAPixels:(nonnull size_t*)bufferSize width:(nonnull in
94
93
95
94
return targetMemory;
96
95
}
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
- }
131
96
#else
132
97
- (nullable uint8_t *)jxlRGBAPixels : (nonnull size_t *)bufferSize width : (nonnull int *)xSize height : (nonnull int *)ySize {
133
98
CGImageRef imageRef = [self CGImage ];
0 commit comments