I want to create PNG8 file with MagickCore (not Wand).
Default color (background) must be transparent.
Colour pixels must be set individually and manually.
Also it's not clear how to work with color tables.
Template for what I wanted to get is like this:
Code: Select all
int main (int argc, char *argv[])
{
char filename[...] = ...;
int width = 512, height = 512;
Image *image;
ImageInfo *image_info;
ExceptionInfo *exception;
MagickBooleanType status;
MagickCoreGenesis((char *)NULL, MagickFalse);
// Get and Initialize an exception info
exception = AcquireExceptionInfo();
GetExceptionInfo(exception);
// Imageinfo & image
image_info = AcquireImageInfo();
CopyMagickString(image_info->filename, filename, MaxTextExtent);
CopyMagickString(image_info->magick, "png", MaxTextExtent);
//*** Is it right "png" ?
//*** Or i must specify some like "png8" ?
//*** ... and.. may be some more CopyMagickString's ?
image_info->file = fopen(filename, "wb");
image_info->adjoin=MagickTrue;// MagickWriteImage does this so I do it too.
image = AcquireImage(image_info);
SetImageExtent(image, width, height);
SetImageStorageClass(image, DirectClass);
//*** Technique is similar to RGB workaround?
//*** Or... How we must work with indexed colors?
PixelPacket *pixels;
register PixelPacket *ppix;
pixels = GetImagePixels(image, 0, 0, width, height);
// Colortable
//***
//*** HOW TO Color Table ?!
//***
// Working with pixels
//-----------------------------------------------------+
ppix = pixels;
for(int i=0; i<height; i++){
for(int j=0; j<width; j++){
//ppix->red = some_red_intensity;
ppix->WHAT = needed_color_index;
///////
ppix++;
}
}
//-----------------------------------------------------+
// Finalizing
SyncImagePixels(image);
WriteImage(image_info, image);
DestroyImage(image);
DestroyImageInfo(image_info);
DestroyExceptionInfo(exception);
MagickCoreTerminus();
}
There are too insufficient examples for using MagickCore in plain C.
Hope i find help there.