views:

93

answers:

1

I have an IKImageView, and I'm putting CGImages (That I make out of NSImages) onto it. However, a normal 200DPI 8.5/11 page takes like 3 seconds to come up, appearing in rectangles about 2inches (screen) on a side at a time. This is really annoying. Is there a way around this?

Alternatively, is there a way to double buffer the view? To have 2 IKImageViews and draw into one, and then display it?

ETA: doubling my scrollviews (with ikimageviews inside) and then drawing into them, and then unhiding them, doesn't seem to help... or, maybe it helps a little, but not much

I did a little poking around with instruments, and found that a lot of work seems to be being done in memcopy:

  22 commpage [libSystem.B.dylib] 78.0  __memcpy
  21 ImageIO 37.0  CGImageReadGetBytesAtOffset
  20 ImageIO 37.0  CGImageReadSessionGetBytes
  19 ImageIO 37.0  myTIFFReadProc
  18 libTIFF.dylib 37.0  TIFFReadRawStrip1
  17 libTIFF.dylib 37.0  TIFFFillStrip
  16 libTIFF.dylib 37.0  _cg_TIFFReadEncodedStrip
  15 ImageIO 37.0  copyImageBlockSetTIFF
  14 ImageIO 37.0  ImageProviderCopyImageBlockSetCallback
  13 CoreGraphics 37.0  CGImageProviderCopyImageBlockSet
  12 CoreGraphics 37.0  img_blocks_create
  11 CoreGraphics 37.0  img_blocks_extent
  10 CoreGraphics 37.0  img_interpolate_extent
   9 CoreGraphics 37.0  img_data_lock
   8 CoreGraphics 37.0  CGSImageDataLock
   7 libRIP.A.dylib 37.0  ripc_AcquireImage
   6 libRIP.A.dylib 37.0  ripc_DrawImage
   5 CoreGraphics 37.0  CGContextDrawImage
   4 ImageKit 37.0  -[IKImageLayer drawInContext:]
   3 QuartzCore 37.0  tiled_layer_render(_CAImageProvider*, unsigned int, unsigned int, unsigned int, unsigned int, void*)
   2 QuartzCore 37.0  CAImageProviderThread(void*)
   1 libSystem.B.dylib 37.0  _pthread_wqthread
   0 libSystem.B.dylib 37.0  start_wqthread

I'm not sure what that tells me though...

EDIT: For the record, the problem is NOT data size. I have an old version of the program, that uses deprecated quickdraw method calls. When I zoom the image up to 300%, so that one screen pixel = one image pixel, so it needs to be using the whole image, it STILL zips right along page after page.

I'm being ridiculed by the guy who wrote this originally, because his version moves faster on his ancient 10.3 G5 than it does on my up-to-date Intel box. faster by at least a factor of 10.

+2  A: 

200DPI 8.5/11 page

Assuming those are in RGB color, that's 11.22 megabytes of pixels per image. Your application uses a lot of memory, and drawing 3.74 megapixels (regardless of color space) is going to be slow.

2 inches (screen) on a side

Make use of that. Figure out how many screen pixels 2 inches is, using the 72 dpi constant and the window's user-space scale factor, and rasterize your pages to that size. Currently, those rectangles will be 144 points on a side, and a 144×144 image is very efficient to have in memory and to draw.

If you have a zoom setting, you'll want to invalidate your cache of these images when it changes, and re-compute each image no earlier than when your view gets told to draw.

Peter Hosey
well, 1 it's black andwhite at the moment, but more impportantly, in the past,before I used IKImageView, it took like 1/20th the time. I'm NOT exagerating. Before it took like .1 seconds to draw the screen, less probably. Now it's 2 seconds. that's a LONG time... it only takes 1/2 second to SCAN the page...
Brian Postow
You should profile your app in Instruments and see what it's spending all this time on.
Peter Hosey
which instrument should I be using for that? instruments seems like a huge tool, and I've never quite figured it out...
Brian Postow
Oh, are you in for some delightful discoveries, then! :-) SPEND THE TIME learning this tool - you won't regret it.
Joshua Nozzi
well, as I added above, it appears that the time is being spent in memcopy, but that doesn't really help me much...
Brian Postow
Brian Postow: That's just a low-level detail. Don't get too caught up in individual trees; keep an eye on the greater forest. You're spending that time reading TIFF data. (Also, 37 what? Milliseconds? See if you can build up more data, and make sure you have the milliseconds values visible so you know how much you should care about each function.)
Peter Hosey
yes, It's 37 miliseconds.Probably the more interesting thing is it's taking about 100ms to get the TIFF Representation, and another 100ms to get the data representation from the PDFPage...
Brian Postow