views:

33

answers:

1

I have code something like this...

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef ctx = CGBitmapContextCreate(pixelArray, width, height, 8, 4 * width, colorSpace, kCGImageAlphaNoneSkipLast);

CGImageRef createdImage = CGBitmapContextCreateImage (ctx);

uiImage = [[UIImage imageWithCGImage:createdImage] retain];

The problem is that, once I create CGImage and UIImage from the buffer (pixelArray), any write operations into the buffer becomes at least 4x slower. This happens only on iPad device not on iPhone. Has anyones face the same problem? What is going on here?

Here is the write operation code, and I call these in loops (setPixel)...

- (RGBA*) getPixel:(NSInteger)x  y:(NSInteger)y {
    // Bound the co-cordinates.
    x = MIN(MAX(x, 0), width - 1);
    y = MIN(MAX(y, 0), height - 1);

    // yIndexes are pre populated
    return (RGBA*)(&pixelArray[(x + yIndexes[y]) << 2]);
}

- (void) setPixel:(RGBA*)color x:(NSInteger)x  y:(NSInteger)y {
    // Bound the co-cordinates.
    x = MIN(MAX(x, 0), _width);
    y = MIN(MAX(y, 0), _height);

    memcpy([self getPixel:x y:y], color, 3);

    colorDirtyBit = YES;
}
A: 

I am not sure what is going wrong, but I believe it might be your write operation code that differ in speed. Could you try raw-writing operation without using those functions instead? e.g.

for(int i = 0; i < bufferlen; i++) {
    pixelArray[i] = i; // or any arbitrary value
}
tia
I already tried that but that does not help. If i create another buffer and do a memcpy(newBuffer, pixelArray) and do the write operations there, things go fine. Seem like once I create a image out of the memory block, some kind of callback is attached to it, no idea what it is how that can be possible.
Pankaj