Ignore:
Timestamp:
Oct 19, 2008, 2:32:42 PM (15 years ago)
Author:
Jean-Yves Lamoureux
Message:
  • Convert CoreImage? buffer to RGBA right after loading
  • Crop padding while needed, making pitch consistent with (width*bytesperpixel)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libpipi/trunk/pipi/codec/coreimage.m

    r3021 r3032  
    4747    pipi_image_t *img;
    4848    img = pipi_new(w, h);
    49     img->p[PIPI_PIXELS_RGBA_C].pixels = [myImage bitmapData];
     49
    5050    img->p[PIPI_PIXELS_RGBA_C].w      = w;
    5151    img->p[PIPI_PIXELS_RGBA_C].h      = h;
     
    5555    img->last_modified                = PIPI_PIXELS_RGBA_C;
    5656
     57   
     58    /* CoreImage feeds us with BGRA while we need RGBA, so convert it.
     59     * We also need to get a pitch==(w*bpp) in order to pipi to opper properly.
     60     */
     61   
     62    int pitch = (img->p[PIPI_PIXELS_RGBA_C].bpp/8);
     63    unsigned char *tmp  = (unsigned char*)malloc(h*w*pitch);
     64    unsigned char *orig = (unsigned char*)[myImage bitmapData];
     65    int x, y, k=0, o=0, a=[myImage bytesPerRow] - (w*([myImage bitsPerPixel]/8));
     66
     67    for(y=0; y<h; y++)
     68    {
     69        for(x=0; x<w*pitch; x+=4)
     70        {
     71            if(!([myImage bitmapFormat] & NSAlphaFirstBitmapFormat))
     72            {
     73                tmp[k+2] = orig[o];
     74                tmp[k+1] = orig[o+1];
     75                tmp[k+0] = orig[o+2];
     76                tmp[k+3] = orig[o+3];
     77            } else
     78            {
     79                tmp[k+0] = orig[o];
     80                tmp[k+1] = orig[o+1];
     81                tmp[k+2] = orig[o+2];
     82                tmp[k+3] = orig[o+3];                   
     83            }
     84               
     85            o+=4;
     86            k+=4;
     87        }
     88        o+=a;
     89    }
     90    img->p[PIPI_PIXELS_RGBA_C].pixels = tmp;
     91    img->p[PIPI_PIXELS_RGBA_C].pitch  = w*([myImage bitsPerPixel]/8);
     92   
     93   
     94   
     95   
    5796    img->codec_priv = (struct pipi_codec_coreimage *) malloc(sizeof(struct pipi_codec_coreimage *));
    5897    struct pipi_codec_coreimage *infos = (struct pipi_codec_coreimage *) img->codec_priv;
     
    109148    }
    110149   
    111    
    112150    [[bitmap representationUsingType:type properties:nil] writeToFile:n  atomically:YES];
    113151    [autoreleasepool release];
Note: See TracChangeset for help on using the changeset viewer.