CGImageCreateWithMaskingColor - I'm not understand the MaskingColor Array parameter..

damaged1130
Unregistered
 
Post: #1
I can't see to figure out how to use CGImageCreateWithMaskingColor

It seems that no matter what array I pass to it for masked colors it will not mask properly. I think I just fundementally don't understand the MaskedColors array...

Code:
    CGImageRef image, subImage, maskedImage;
    CGDataProviderRef provider;
    CFStringRef path;
    CFURLRef url;
    CGRect myImageArea;

    
    myImageArea = CGRectMake( ((image_num * SPRITE_WIDTH) % (SPRITE_WIDTH * SPRITE_COLUMNS)), (((int)(image_num / SPRITE_COLUMNS)) * SPRITE_HEIGHT), SPRITE_WIDTH, SPRITE_HEIGHT);
    
    path = CFStringCreateWithCString(NULL, filename, kCFStringEncodingUTF8);
    url = CFURLCreateWithFileSystemPath(NULL, path, kCFURLPOSIXPathStyle, NULL);
    
    CFRelease(path);
    provider = CGDataProviderCreateWithURL(url);
    
    CFRelease(url);
    image = CGImageCreateWithJPEGDataProvider(provider,
                                              NULL,
                                              true,
                                              kCGRenderingIntentDefault);
    CGDataProviderRelease(provider);
    
    const float myMaskingColors[6] ={255, 255, 255, 255, 255, 255};
    subImage = CGImageCreateWithImageInRect(image, myImageArea);
    maskedImage = CGImageCreateWithMaskingColor(subImage, myMaskingColors);
    CGContextDrawImage(myContext, myContextRect, maskedImage);
    CGImageRelease(image);
    CGImageRelease(subImage);
    CGImageRelease(maskedImage);

The above code should create an image that is transparent everywhere that there is white. but it does pretty much nothing... If I change it to:

Code:
    const float myMaskingColors[6] ={0, 255, 0, 255, 0, 255};

I expect the above mask to grab "EVERY" color but it seems to only grab random black spots in the picture? Can anyone re-educate me to what newb mistake I am making with myMaskingColors and advise how to set it up to grab white out of jpeg images?
Quote this message in a reply
Jones
Unregistered
 
Post: #2
If what you mean by "random black spots" is a form of splotching being masked out, and others not, it's probably because your image is antialiased in some way that introduces variants of the color you want to use as masks.

That sounds logical, if I interpreted your post correctly.
Quote this message in a reply
damaged1130
Unregistered
 
Post: #3
I guess the real question is though why am I getting the spottedness when using a mask of 0,255,0,255,0,255. When that should mask every color between 0,0,0 and 255,255,255 IE: every color. but instead it is only masking a few. And furthermore why 255,255,255,255,255,255 for a masking color range is not masking white at all.

If I understand correctly a jpeg is a 24 bit image so it has 8bits for each RGB so 0,255 ,0,255,0,255 should catch everything in the image instead of just parts of the image.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Vertex Array & Interleaved Array troubles TomorrowPlusX 5 5,476 Nov 17, 2007 09:59 AM
Last Post: TomorrowPlusX
  correct glDepthFunc() parameter? Vertizor 4 4,439 Sep 28, 2004 08:32 AM
Last Post: Vertizor