Images with direct memory access

  • Hi,

    I need to create and manipulate an image, which I could access directly
    from memory and at the same time be able to use system drawing functions
    for optimization. On Windows I can create a memory bitmap, but it seems it
    is on possible on Mac, or is it? Note that I don't want to do any
    conversions from handles to memory etc., the whole point is optimization.

    Regards
    Vojtech
  • On 27/07/2012, at 10:36 PM, Vojtěch Meluzín wrote:

    > I need to create and manipulate an image, which I could access directly
    > from memory and at the same time be able to use system drawing functions
    > for optimization. On Windows I can create a memory bitmap, but it seems it
    > is on possible on Mac, or is it? Note that I don't want to do any
    > conversions from handles to memory etc., the whole point is optimization.

    What have you tried?

    There are all sorts of ways you can manipulate images, here's one:

    [NSBitmapImageRep initWithBitMapDataPlanes:.....];

    by passing existing pointer to memory in bitPlanes, it will wrap that memory in the necessary bitmap structure rather than create a new one.

    there are also some similar functions in CGImage (though it's more work to wrap an existing block of memory), and the vImage framework for image processing.

    --Graham
  • On Jul 27, 2012, at 7:45 AM, Graham Cox wrote:

    > On 27/07/2012, at 10:36 PM, Vojtěch Meluzín wrote:
    >
    >> I need to create and manipulate an image, which I could access directly
    >> from memory and at the same time be able to use system drawing functions
    >> for optimization. On Windows I can create a memory bitmap, but it seems it
    >> is on possible on Mac, or is it? Note that I don't want to do any
    >> conversions from handles to memory etc., the whole point is optimization.
    >
    > What have you tried?
    >
    > There are all sorts of ways you can manipulate images, here's one:
    >
    > [NSBitmapImageRep initWithBitMapDataPlanes:.....];
    >
    > by passing existing pointer to memory in bitPlanes, it will wrap that memory in the necessary bitmap structure rather than create a new one.
    >
    > there are also some similar functions in CGImage (though it's more work to wrap an existing block of memory), and the vImage framework for image processing.

    There's also CGBitmapContext.  You can draw to that as well as manipulate its memory.  You can't draw _from_ it directly, but you can obtain a CGImage from it using CGBitmapContextCreateImage().

    Also, if you use NSBitmapImageRep but let it allocate the data, you can still obtain it using -bitmapData.  It's a good idea to read the section about image technologies in the Snow Leopard AppKit release notes.  Search for "NSImage, CGImage, and CoreGraphics impedance matching" and "NSBitmapImageRep: CoreGraphics impedance matching and performance notes".
    <https://developer.apple.com/library/mac/releasenotes/Cocoa/AppKitOlderNotes
    .html#X10_6Notes
    >

    Regards,
    Ken
  • Keep in mind that accessing the image pixels directly can hurt drawing performance. Your code can only access the pixmap if it's in system RAM, while GPU acceleration requires that the pixmap be in VRAM. So messing with the pixels may either cause the pixmap to be copied back and forth, or force CoreGraphics to degrade to software rendering.

    —Jens
  • On 7/27/12, Jens Alfke <jens...> wrote:
    > Keep in mind that accessing the image pixels directly can hurt drawing
    > performance. Your code can only access the pixmap if it's in system RAM,
    > while GPU acceleration requires that the pixmap be in VRAM. So messing with
    > the pixels may either cause the pixmap to be copied back and forth, or force
    > CoreGraphics to degrade to software rendering.
    >
    > —Jens

    Jens is correct that the way you are implying you want to access
    pixels will hurt performance. So this is what shaders are for. If want
    fast access that will immediately be rendered, use OpenGL shaders or
    Core Image (an Apple framework).

    -Eric
    --
    Beginning iPhone Games Development
    http://playcontrol.net/iphonegamebook/
previous month july 2012 next month
MTWTFSS
            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          
Go to today