Page 1 of 1

Accessing index for palette with MagickExportImagePixels

Posted: 2014-04-07T07:35:04-07:00
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?

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

Posted: 2014-04-11T02:46:00-07:00
by sthustfo
Does the MagickExportImagePixels() API suit your needs?

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

Posted: 2014-04-11T10:09:11-07:00
by SlasherZet
Yes, that is exactly what I've been looking for, thank you!

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

Posted: 2014-04-11T14:50:28-07:00
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)...