I am attempting to load a jpeg image into a vImage_Buffer.
I am just trying to get the data in an ARGB format. This code works fine in the Xcode 15 build , but fails with kvImageInvalidParameter error from vImageBuffer_InitWithCGImage in the Xcode 26 build.
This code is written in ObjectiveC++. Here is a code fragment:
int CDib_ARGB::Load(LPCSTR pFilename) { int rc = 0; if (NULL == m_pRaw_vImage_Buffer) { NSString *pNS_filename = [[NSString alloc]initWithUTF8String:pFilename]; NSImage *pNSImage = [[NSImage alloc] initWithContentsOfFile:pNS_filename]; if (nil == pNSImage) rc = -1; else { int width = pNSImage.size.width; int height = pNSImage.size.height; if (pNSImage.representations) { NSImageRep *imageRep; int jj; width = 0; height = 0; for (jj = 0; jj < pNSImage.representations.count; jj++) { imageRep = pNSImage.representations[jj]; if (imageRep.pixelsWide > width) width = imageRep.pixelsWide; if (imageRep.pixelsHigh > height) height = imageRep.pixelsHigh; } } NSSize imageSize = NSMakeSize(width, height); NSRect imageRect = NSMakeRect(0, 0, width, height); pNSImage.size = imageSize; CGImageRef cgImage = [pNSImage CGImageForProposedRect:&imageRect context:NULL hints:nil]; if (nil == cgImage) rc = -1; else { //Alloc and load vImage_Buffer. vImage_Buffer *pvImage_Buffer = new vImage_Buffer; if (NULL == pvImage_Buffer) rc = -1; else { vImage_CGImageFormat format; format.bitsPerComponent = 8; format.bitsPerPixel = 32; format.colorSpace = nil; format.bitmapInfo = kCGImageAlphaFirst | kCGBitmapByteOrderDefault;//ARGB8888 format.version = 0; format.decode = nil; format.renderingIntent = kCGRenderingIntentDefault;
memset(pvImage_Buffer, 0, sizeof(vImage_Buffer));
long status = vImageBuffer_InitWithCGImage(pvImage_Buffer, &format, nil, cgImage, kvImagePrintDiagnosticsToConsole);
if (kvImageNoError != status)
{ //This is where Xcode 26 sends me.
delete pvImage_Buffer;
rc = -1;
}
=========================
Ok, I have found a workaround. See the attached text, which contains a routine that shows how to create a CGImage from the NSImage that vImageBuffer_InitWithCGImage can handle successfully for the problematic image files.
Apparently vImageBuffer_InitWithCGImage is brittle and it needs for the CGImage to be rather vanilla which this rendering logic accomplishes.
The files that cause failures are jpegs that came from an Android phone which feature color profiles that confuse vImageBuffer_InitWithCGImage.
This new method seems to fix all the problems, fingers crossed.