• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CGImage failing to animate
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CGImage failing to animate


  • Subject: CGImage failing to animate
  • From: Colin Klipsch <email@hidden>
  • Date: Sat, 27 Jul 2002 12:39:12 -0400

Greetings.

I'm trying to have a CoreGraphics CGImage of offscreen pixels animate inside a customized NSView. The View draws the image statically from its 'drawRect' method -- when the OS calls for a refresh -- and also refreshes itself periodically in response to an NSTimer driving the animation.

But it isn't working. The initial frame of animation is being drawn correctly. After that, the View just displays the same initial frame, regardless of how the underlying pixels are changed. It's as if the first display of the image puts it in a cache somewhere, and thereafter, the offscreen pixel values are ignored.

The animation /does/ work correctly when I don't use CoreGraphics, but instead use an NSBitmapImageRep, along with the appropriate lines of supporting code. The problem therefore must be in my use or misuse of CoreGraphics. (And yes, I need the CoreGraphics way I'm afraid; I can't revert to the older technique.)

Given the following "prolog":

enum { kWidth = 400, kHeight = 300 };
static UInt8 gPixels[kHeight][kWidth];
static UInt8 gColorTable[16*3] = { /*... 48 RGB values*/ };
static CGImageRef gImage;

static void
releasePixels(void*, const void*, size_t)
{ /*intentionally empty*/ }

I create the CGImage like so:

gImage = CGImageCreate(kWidth, kHeight,
8, //size_t bitsPerComponent
8, //size_t bitsPerPixel
kWidth, //size_t bytesPerRow
CGColorSpaceCreateIndexed(
CGColorSpaceCreateDeviceRGB(),
16-1, gColorTable
),
kCGImageAlphaNone,
CGDataProviderCreateWithData(
nil, gPixels, sizeof(gPixels), &releasePixels
),
nil, //const float decode[]
false, //shouldInterpolate
kCGRenderingIntentDefault); //CGColorRenderingIntent

My custom NSView's 'drawRect' method is:

- (void)drawRect:(NSRect)dirtyRect
{
CGRect rect = {0, 0, kWidth, kHeight};
CGContextRef context = [[NSGraphicsContext
graphicsContextWithWindow:[self window]] graphicsPort];

CGContextDrawImage(context, rect, gImage);
CGContextSynchronize(context); //need??
CGContextFlush(context); //need??
}

And the NSTimer's callback, which invokes each frame of animation, goes like:

- (void)fireTimer:(NSTimer*)aTimer
{
// fiddle with the gPixels array
[myView setNeedsDisplay:YES];
}


So, any ideas why I'm not getting animation beyond the drawing of the first frame (which renders correctly)?

Thanks to anyone who responds.

-- Colin K.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: CGImage failing to animate
      • From: Marcel Weiher <email@hidden>
  • Prev by Date: Re: Hiding class and method symbols in the compiled program?
  • Next by Date: (no subject)
  • Previous by thread: Rulers in shared text views
  • Next by thread: Re: CGImage failing to animate
  • Index(es):
    • Date
    • Thread