ExportImagePixelArea

Adam Morissun <[email protected]>
Newsgroups gmane.comp.video.graphicsmagick.help
Message-ID <[email protected]>
Hi. Would someone explain how to use ExportImagePixelArea() ? I cannot 
make it work for the life of me.

I've attached the smallest C code I could devise to demonstrate my 
problem. I'm using Gimp to examine the '/tmp/pixels_**.data' files.

Thanks!

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot

_______________________________________________
Graphicsmagick-help mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/graphicsmagick-help
rot_test.c (text/x-csrc, 2.4 KB)
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <magick/api.h>

// write pixel data to a file
ssize_t write_pixels(const unsigned char *data, unsigned int len, const char *filename)
{
    int desc = open(filename, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
    assert(desc > -1);
    ssize_t bytes = write(desc, data, len);
    if(bytes < 0)
        perror(0);
    close(desc);
    return bytes;
}

int main(int argc, char **argv) {
    const char filename[] = "pogo.jpg";
    InitializeMagick(NULL);

    ExceptionInfo exception;
    GetExceptionInfo(&exception);
    ImageInfo *image_info = CloneImageInfo(NULL);
    strcpy(image_info->filename, filename);
    Image *org = ReadImage(image_info, &exception);
    if(exception.severity != UndefinedException) {
        CatchException(&exception);
        return 1;
    }
    DescribeImage(org, stdout, 0);
    printf("matte? %i, depth %i\n", org->matte, org->depth);

    unsigned int size = org->rows * org->columns * org->depth;
    unsigned char* data = (unsigned char*)malloc(size);
    assert(data);
    ExportPixelAreaOptions opts;
    ExportPixelAreaOptionsInit(&opts);
    opts.endian = NativeEndian; // match OpenGL implementation on this machine
    ExportPixelAreaInfo ex_info;
    // update the default cache view? so ExportImagePixelArea() actually works
    // (do not free() pxls!)
    //PixelPacket *pxls = GetImagePixels(org, 0, 0, org->columns, org->rows);
    // now we export pixels
    int result = ExportImagePixelArea(org,
        org->matte ? RGBAQuantum : RGBQuantum,
        org->depth, data, &opts, &ex_info);
    assert(result != MagickFail);

    ssize_t bytes = write_pixels(data, size, "/tmp/pixels_before.data");
    free(data);

    Image *rot = RotateImage(org, 90, &exception);
    if(exception.severity != UndefinedException)
        CatchException(&exception);
    size = rot->rows * rot->columns * rot->depth;
    data = (unsigned char*)malloc(size);
    assert(data);
    ExportPixelAreaOptionsInit(&opts);
    opts.endian = NativeEndian;
    //pxls = GetImagePixels(rot, 0, 0, rot->columns, rot->rows);
    result = ExportImagePixelArea(rot,
        rot->matte ? RGBAQuantum : RGBQuantum,
        rot->depth, data, &opts, &ex_info);
    assert(result != MagickFail);
    bytes = write_pixels(data, size, "/tmp/pixels_after.data");
    free(data);

    DestroyImage(org);
    DestroyImage(rot);
    DestroyMagick();
    return 0;
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.