• 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
Extremely confused, GWorlds and CopyBits
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Extremely confused, GWorlds and CopyBits


  • Subject: Extremely confused, GWorlds and CopyBits
  • From: Sailor Quasar <email@hidden>
  • Date: Sun, 11 Jan 2004 11:23:45 -0500

I apologize profusely for the cross-post, but while this problem involves a NSQuickDrawView, I expect my issue is in NewGWorldFormPtr() somewhere, so I'm not entirely sure which list is appropriate between Carbon and Cocoa. Please reply to only one list.

I have an NSQuickDrawView with a set size of 1024x768, inside an NSScrollView (and hence an NSClipView too, of course). In my concrete subclass, I set up two GWorlds for backing stores (yes, I'm aware of double-buffering etc.; my drawing algorithms require extra backing stores for now). These are based on memory buffers that I allocate myself like so:
backingPtr = (char *)calloc(1024 * 768, 3);
backingPtr2 = (char *)calloc(1024 * 768, 3);
I then call NewGWorldFromPtr():
SetRect(&r, 0, 0, 1023, 767);
NewGWorldFromPtr(&backingStore, k24RGBPixelFormat, &r, NULL, NULL, 0, backingPtr, 1024 * 3);
NewGWorldFromPtr(&backingStore2, k24RGBPixelFormat, &r, NULL, NULL, 0, backingPtr2, 1024 * 3);

From here on, very strange things indeed go on. If I stick with NewGWorldFromPtr(), any drawing I do gets mirrored approx. 512 pixels to the right and exactly one pixel up from the original drawing, to the point of wrapping around a second time if the original picture gets too wide. If I switch to QTNewGWorldFromPtr(), my CopyBits() which draws the backing store into the view immediately crashes (badly enough that gdb gets an internal error and SIGABRTs in PB), unless I double the amount of memory allocated for the buffers of the gworlds, in which case my code acts as if the view is something around half its original _height_. This is the CopyBits() call:
SetRect(&r, 0, 0, 1023, 767);
CopyBits(GetPortBitMapForCopyBits((CGrafPtr)backingStore2),
GetPortBitMapForCopyBits((CGrafPtr)[self qdPort]),
&r, &r,
srcCopy, NULL);
(where, for the Carbon people, [self qdPort] gives me access to the window's CGrafPtr with an origin relative to the upper left of my view)

It's reasonably obvious that I've got a rowBytes issue or something, but for the life of me I can not figure out what the heck it is. 24-bit RGB should yield 3 bytes per pixel, times the width of the image, hence 1024 * 3. Someone please point out to me whatever my glaringly obvious error is.

-- Sailor Quasar, guardian of Leraz's memory
"A face of stone may hide a soul with the deepest Love of all"
Email: email@hidden
_______________________________________________
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.

  • Prev by Date: Re: NSArrayController with Combo Boxes, etc.
  • Next by Date: how do i change the controller keys ??
  • Previous by thread: Re: help, objc_msgSend problems
  • Next by thread: Re: Extremely confused, GWorlds and CopyBits
  • Index(es):
    • Date
    • Thread