Accessing index for palette with MagickExportImagePixels

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
SlasherZet
Posts: 6
Joined: 2014-04-07T07:00:02-07:00
Authentication code: 6789

Accessing index for palette with MagickExportImagePixels

Post by SlasherZet »

I need to access indexes with MagickExportImagePixels, but the possible maps don't seem to have index in them, there is R, G, B, C, M, Y, K, Alpha, Opacity, Padding (?) and Intensity.
I tried with intensity but it doesn't seem to return an index, instead returns an odd number for a paletted image.
Help appreciated!

Below is the first problem I had, now fixed with MagickExportImagePixels:
Greetings.
I am wondering if it is possible to access packed raw pixel information using MagickWand.

The following code does what I want when using MagickCore. It gets a pointer to a row of packed pixel data stored in an array or PixelPackets (and IndexPackets).

Code: Select all

  PixelPacket *pixels; IndexPacket *index_pixels;
  ImageInfo *image_info; ExceptionInfo *exception_info;
  Image *image;
  
  // Generate
  MagickCoreGenesis(*argv,MagickTrue);
  if (IsMagickCoreInstantiated() != MagickTrue)
    return -1;
  image_info = AcquireImageInfo();
  GetImageInfo(image_info);
  exception_info = AcquireExceptionInfo();
  GetExceptionInfo(exception_info);

  // Read image
  CopyMagickString(image_info->filename,fname,MaxTextExtent);
  image = ReadImage(image_info,exception_info);

  // Get read only pixels
  pixels = GetVirtualPixels(image,(ssize_t)0,(ssize_t)row,(size_t)cols,(size_t)1,exception_info);
  if (pixels == (const PixelPacket *) NULL)
    // Throw error
  if (image->colorspace == CMYKColorspace)
    {
      index_pixels = GetVirtualIndexQueue(image);
      if (index_pixels == (const IndexPacket *) NULL)
        // Throw error
    }
  ...
I am wondering if it's possible to do the same using MagickWand. Using PixelWands doesn't really get me what I need, since the PixelWands are big, contain information I do not need and are not necessarily next to each other.

Code: Select all

  PixelWand **pixel_wands;
  size_t read;

  PixelIterator *pixel_iterator = NewPixelIterator(some_wand...);
  pixel_wands = PixelGetNextIteratorRow(pixel_iterator,&read);
Do I need to stick to MagickCore or is it somehow possible?
Last edited by SlasherZet on 2014-04-11T16:03:29-07:00, edited 1 time in total.
sthustfo
Posts: 4
Joined: 2014-04-11T02:35:22-07:00
Authentication code: 6789

Re: Accessing raw packed pixel data (PixelPacket) in MagickW

Post by sthustfo »

Does the MagickExportImagePixels() API suit your needs?
SlasherZet
Posts: 6
Joined: 2014-04-07T07:00:02-07:00
Authentication code: 6789

Re: Accessing raw packed pixel data (PixelPacket) in MagickW

Post by SlasherZet »

Yes, that is exactly what I've been looking for, thank you!
SlasherZet
Posts: 6
Joined: 2014-04-07T07:00:02-07:00
Authentication code: 6789

Re: Accessing raw packed pixel data (PixelPacket) in MagickW

Post by SlasherZet »

Got another problem.
MagickExportImagePixels can't seem to retrieve indexes for paletted images. I tried "I" for intensity, but that returns something else than index and it fails when I try "K" to get the black (or, in IndexPacket also representing the index)...
Post Reply