[SDL] Pixel bug in Mac OS X
pixelman93 at gmail.com
Fri Sep 30 13:29:29 PDT 2011
For convenience, here's the code where the CGImage is copied into the
Like I said before, I think the inaccuracy happens when the CGImage is drawn
into a CGContext, because I've had this same issue before. If you read the
raw pixel data of a loaded CGImage (without changing it in any way) then the
pixel data is accurate.
On Fri, Sep 30, 2011 at 1:38 PM, Eric Wing <ewmailing at gmail.com> wrote:
> Sorry all. I'm still around, but just been really busy.
> I'm going from distant memory here. I thought I recall calling some
> memory calibration stuff in the code already. I think I was unsure
> which way to go so I think there may have been two lines, one
> commented out to go the other way. I thought the current way would not
> do color calibration because I thought that would alter the pixel
> I recall people were having problems with premulitplied alpha related
> issues. Was it Sam that added the code to 'fix' that? Is this always
> run? Are these cases orthogonal? Maybe this can be skipped when not
> needed and thus avoiding any accidental pixel color changes?
> I never did figure out grayscale, but I never deeply pursued this.
> Maybe some ambitious person would like to ask on the Quartz mailing
> list or something or if they have a spare DTS incident to throw
> As a workaround for grayscale, I was thinking it could be done the
> brute force way. Check the bitdepth for 8-bit and then go through all
> the pixels after blitting to 24/32-bit and check for r==g==b. If it
> passes the check, create a SDL_Surface that looks like what you might
> get from the other IMG_Load backends.
> On 9/21/11, pixelman <pixelman93 at gmail.com> wrote:
> > @Jeremy: Haha trying to write a pixel art editor on the Mac is a
> > o_O
> > I'm reading the SDL_image source right now, and I see in
> > Create_SDL_Surface_From_CGImage they're creating a CGBitmapContext with
> > surface->pixels and drawing the loaded image to the context. I'm 99% sure
> > this is what I was doing before and getting headaches over.
> > Check this out:
> > http://developer.apple.com/library/mac/#qa/qa1509/_index.html
> > *Warning:* The pixel data returned by CGDataProviderCopyData has not been
> >> color matched and is in the format that the image is in, as described by
> >> the
> >> various CGImageGet functions (see for Getting Information About an
> >> Image<
> >> more
> >> information). If you want the image in a different format, or color
> >> matched
> >> to a specific color space, then you should draw the image to a bitmap
> >> context as described later in this Q&A, with the caveat that alpha
> >> information from the image will be multiplied into the color components.
> > So basically, it *is* possible to get the unaltered pixel data directly
> > the image with ImageIO. I think the alpha-premultiplication is what's
> > screwing everything up -- would it be possible to copy the raw pixel data
> > into the SDL_Surface?
> > - pixelman
> > On Wed, Sep 21, 2011 at 1:04 AM, Ryan C. Gordon <icculus at icculus.org>
> >> "We are changing the backend of SDL_image to use Apple's ImageIO API"
> >> We should just disable this, because it constantly causes three
> >> - Slightly different colors when you need pixel-perfect decoding.
> >> - No 8-bit support (which is bad when you use an 8-bit grayscale .png
> >> say, a heightmap, and actually wanted an 8-bit surface from SDL_image).
> >> - The first two problems are completely non-obvious to track down when
> >> realize you have a problem, and a pain to resolve, because now you have
> >> build your own SDL_image at a minimum.
> >> The benefits to using ImageIO are a smaller compiled library, no need
> >> us to manage the external dependencies, and no need to worry about
> >> updating
> >> the dependencies for security issues. I'm not sure this is the _worst_
> >> thing, though.
> >> Eric Wing, if you're around: can the color thing be resolved? Maybe with
> >> an
> >> NSColorSpace or something?
> >> For the other issue, I imagine that, for correctness, we can convert the
> >> final SDL_Surface to 8-bit if the original PNG is 8-bit too. Maybe?
> >> --ryan.
> >> ______________________________**_________________
> >> SDL mailing list
> >> SDL at lists.libsdl.org
> >> http://lists.libsdl.org/**listinfo.cgi/sdl-libsdl.org<
> Beginning iPhone Games Development
> SDL mailing list
> SDL at lists.libsdl.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SDL