Q:

how should i be considering CGImageAlphaInfo when converting to JPEG?

i'm handing off to this method and using the resultant CGImageRef adding it to a CGImageDestinationRef that is setup for finalizing as a kUTTypeJPEG:
- (CGImageRef)scaleImage:(CGImageRef)fullImageRef originalSize:(CGSize)originalSize scale:(CGFloat)scale;
    {
        CGSize imageSize = originalSize;

        CGRect scaledRect = CGRectMake(0.0, 0.0, imageSize.width * scale, imageSize.height * scale);
        CGColorSpaceRef colorSpace = CGImageGetColorSpace(fullImageRef);
        CGContextRef context = CGBitmapContextCreate(NULL, scaledRect.size.width, scaledRect.size.height, 8, 0, colorSpace, CGImageGetAlphaInfo(fullImageRef));
        CGContextSetInterpolationQuality(context, kCGInterpolationHigh);
        CGImageRef subImage = CGImageCreateWithImageInRect(fullImageRef, scaledRect);
        CGContextDrawImage(context, scaledRect, subImage); // offscreen
        CGImageRef scaledImage = CGBitmapContextCreateImage(context);
        CGImageRelease(subImage);
        subImage = NULL;
        subImage = scaledImage;
        CGImageRelease(scaledImage);
        CGContextFlush(context);
        CGContextRelease(context);
        return subImage;
    }

i need to be sure that the resulting JPEG is the best possible color match for the original.
what i am unclear about is the actual role of CGImageAlphaInfo constant for my purposes.
i've read Quartz docs, and also the excellent Programming With Quartz book (by Gelphman and Laden), but i'm still not sure of my methods.
i've set the property kCGImageDestinationLossyCompressionQuality to 1.0 in the jpeg's property dictionary, along with capturing other properties.
should i be doing something more to maintain the color integrity of the original?
this is macos, and using gc.

A:

It doesn't much matter, because JPEG doesn't support alpha (at least, not without external masking or an extension), so you can expect that CGImageDestination will throw away the alpha channel at the export stage.
I would try the original image's alpha info first, and if I can't create the bitmap context that way, I would use either kCGImageAlphaNoneSkipFirst or kCGImageAlphaNoneSkipLast. For other destination file formats, of course, I'd use one of the alpha-with-premultiplied-colors pixel formats.
This page has the full list of combinations supported by CGBitmapContext.

