Newcomer trying to create PixMap

Ask a Question related to Mac Programming, Design and Development.

  1. #1

    Default Newcomer trying to create PixMap

    I'm working on some code for a 4D plugin. The code must run on Mac
    proper (OS9 & OSX, so Carbon) and Win32. The latter is done via Mac2Win,
    so the code is completely Mac-style. This is my first exposure to Mac;
    I'm usually a Unix/Win32 soul.

    The code is simply to display some pixmap graphics. From a library
    I am getting a buffer filled with the pixmap content as 32 bit colour
    ARGB. I also have the pixmap width and height.

    The route I'm taking at present is to build a PixMap directly and CopyBits
    it onto the port. This works fine under Mac2Win, but on a real Mac (OSX),
    nothing appears. If instead I try filling the target rectangle with red
    and writing some text in green I get the expected results, so I've defintely
    got the right target rectangle and the right port.

    Can some kind soul could provide guidance on

    a) anything obviously wrong with the code below,

    and/or

    b) ways of finding out from QuickDraw what it thinks any problem is.
    (QDError() returns 0 after the CopyBits call).

    Thanks in advance.

    Jim

    I'm creating the pixmap thus:

    pmh = NewPixMap();
    HLock(reinterpret_cast<char **>(pmh));
    pmp = *pmh;

    pmp->baseAddr = reinterpret_cast<Ptr>(rgba);

    // Top bit set means this is a pixmap not a bitmap
    pmp->rowBytes = static_cast<short>(width * 4) | 0x8000;

    pmp->bounds.left = 0;
    pmp->bounds.top = 0;
    pmp->bounds.right = static_cast<short>(width - 1);
    pmp->bounds.bottom = static_cast<short>(height - 1);

    pmp->cmpCount = 3;
    pmp->pixelType = RGBDirect;
    pmp->pixelSize = 32;
    pmp->cmpSize = 8;

    pmp->pmVersion = baseAddr32;
    pmp->packType = 0;
    pmp->packSize = 0;

    This is then passed to CopyBits to display on the current port:

    CopyBits(reinterpret_cast<BitMapPtr>(pmp),
    reinterpret_cast<BitMapPtr>(GetPortPixMap(curPort) ),
    &source, &target,
    srcCopy, NULL);

    Source and target are the source and target rectangles, and are correct.
    --
    Jim Hague - [email]jim@bear-cave.org.uk[/email] Never trust a computer you can't lift.
    Jim Hague Guest

  2. Similar Questions and Discussions

    1. PDF::Create (or alike) to create watermark for existing pdf file?
      Dear perl-ists: I tried out PDF::Create 0.01 (from cpan), and it is great. kudos, fabian. creates wonderful, clean, small valid pdf output. my...
    2. a bit of help for a newcomer please
      :confused; Guys, I guess this will be so easy for you but I am new to this game. I need to know how to zoom in/out of a map image, and also be able...
    3. Newcomer
      Hi people I am beginning to use Freehand MX. I am already experienced with Fireworks, and have some knowledge in Flash. But I am looking for a more...
    4. How to create this??
      Hi, I recently "found" this site http://www.egomedia.com / http://www.ego7.com and wondered how you can create such a flash page where the graphics...
    5. sco 505 - create windoze exe file that will create a unix disk
      Hi, I wonder if this is possible, I want to put some files on a floppy disk from my SCO unix box, then I want that disk to be converted to a file...
  3. #2

    Default Re: Newcomer trying to create PixMap

    In article <20030806155558.5729.0.NOFFLE@fluffy.bear-cave.org.uk>,
    [email]jim@fluffy.bear-cave.org.uk[/email] (Jim Hague) wrote:
    > a) anything obviously wrong with the code below,
    > // Top bit set means this is a pixmap not a bitmap
    > pmp->rowBytes = static_cast<short>(width * 4) | 0x8000;
    rowBytes can't just be whatever you feel like, it must be a multiple of
    some power of 2 that I can't remember, for example 64.
    David Phillip Oster Guest

  4. #3

    Default Re: Newcomer trying to create PixMap

    In article <oster-93A371.20281506082003@newssvr21-ext.news.prodigy.com>,
    David Phillip Oster <oster@ieee.org> wrote:
    >> a) anything obviously wrong with the code below,
    >
    >> // Top bit set means this is a pixmap not a bitmap
    >> pmp->rowBytes = static_cast<short>(width * 4) | 0x8000;
    >
    >rowBytes can't just be whatever you feel like, it must be a multiple of
    >some power of 2 that I can't remember, for example 64.
    Thats for the suggestion.

    The Carbon docs (and IM) say:

    rowBytes
    The offset in bytes from one row of the image to the next. The value
    must be even, less than $4000, and for best performance it should be
    a multiple of 4. The high 2 bits of rowBytes are used as flags. If
    bit 15 = 1, the data structure pointed to is a PixMap structure;
    otherwise it is a BitMap structure.

    so it doesn't look like that's the problem.

    (Later)

    Found it. For the record, the problem turned out to be in the CopyBits() call.

    CopyBits(reinterpret_cast<BitMapPtr>(pmp),
    reinterpret_cast<BitMapPtr>(GetPortPixMap(curPort) ),
    &source, &target,
    srcCopy, NULL);

    fails. Turn this into

    CopyBits(reinterpret_cast<BitMapPtr>(pmp),
    GetPortBitMapForCopyBits(curPort),
    &source, &target,
    srcCopy, NULL);

    and it works. As far as I can see, the difference is that the latter passes
    a BitMapPtr in while the former passes in a PixMapHandle, so that cast
    is a right stuff-up.
    --
    Jim Hague - [email]jim@bear-cave.org.uk[/email] Never trust a computer you can't lift.
    Jim Hague Guest

  5. #4

    Default Re: Newcomer trying to create PixMap

    In Article [email]20030810113743.74B0.2.NOFFLE@fluffy.bear-cave.org.uk[/email], Jim Hague
    wrote:
    > In article <BB59FE34.1517A%mike@objc-source.-DELETE-.org>,
    > Mike Kluev <mike@objc-source.-DELETE-.org> wrote:
    >>
    >> You didn't define hRes, lowRes, planeBytes, pmTable, pmReserved.
    >> I would, for completeness:
    >>
    >> pmp->hRes = 0x00480000;
    >> pmp->vRes = 0x00480000;
    >> pmp->planeBytes = 0;
    >> pmp->pmTable = NULL; // or GetCTable(8),
    >> //if NULL turns out to be a problem
    >> pmp->pmReserved = 0;
    >
    > I didn't define then because NewPixMap() is supposed to copy this stuff from
    > the current device's PixMap. Since it's a 32 bit colour image, I assumed
    > the colour table was irrelevant, so whatever's there is fine. Maybe I
    > should define hRes and vRes, to be on the safe side.
    I would clear pixelFormat (planeBytes) and pmExt (pmReserved) because
    current device's pixmap might contain something there that you don't
    want. As to color table for 32-bit pixmaps, in the dark ages there was
    a bug in QuickDraw that would cause a crash if there was NULL color
    table (even for direct-color pixmaps). Hopefully it is not there anymore.
    > CodeWarrior complained that planeBytes and pmReserved were not members of
    > the PixMap structure when I tried setting them.
    Because of this:

    #if OLDPIXMAPSTRUCT
    long planeBytes;
    CTabHandle pmTable;
    long pmReserved;
    #else
    OSType pixelFormat;
    CTabHandle pmTable;
    void* pmExt;
    #endif
    > Thanks for looking through my fumbling, Mike. Much appreciated.
    You are welcome.

    --
    Mike Kluev

    PS. Remove "-DELETE-." part of my e-mail address to reply.

    Mike Kluev Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139