Thread: Problems with Image Magick [Unable to Quantisize Image]

  1. #1
    Registered User
    Join Date
    Jun 2004
    Posts
    277

    Problems with Image Magick [Unable to Quantizate Image]

    Hi folks I know this is not the best place to ask, Ive already asked in the mailling list and imagemagicks board, but maybe someone here had this very same problem, i'm trying to implement a simple posterization function, but I get strange values for the pixel vales and the image (it is supposed to work only with grayscale ) is outputed unchanged I have no idea about what do to anymore. But I will post the code, maybe someone have an idea:
    Code:
    int quantizateImage( Picture* input, Picture* output, int quantfactor )
    {
    
      long x, y;
    
    
      const PixelPacket *p;
    
      PixelPacket* q;
    
      PixelPacket white = {MaxRGB, MaxRGB, MaxRGB, OpaqueOpacity};
    
      output->data =  CloneImageInfo( input->data );
      output->exception = &(input->image)->exception;
      output->image = CloneImage( input->image,0,0,MagickTrue, output->exception );
      if (output->image  == (Image *) NULL)
        { return 0; } //@TODO: Provide a better exception handler
      
        q = GetImagePixels( output->image,0,y,(output->image)->columns,1 );
        if ((p == ( const PixelPacket* ) NULL) || (q == ( PixelPacket * ) NULL))
          return 0;
        int temp = MaxRGB/2;
        for (x=0; x < (long) (input->image)->columns; x++)
        {
         
          q->red = q->red/temp;
          q->red = q->red*temp;
          q->green = q->green/temp;
          q->green = q->green*temp;
          q->blue = q->blue/temp;
          q->green = q->green*temp;
    
          q++;
        }
        if (SyncImagePixels( output->image ) == MagickFalse)
          return 0;
    
      if (y < (long) (input->image)->rows)
        { return 0; } //@TODO: provide a better exception handler
    
    
    }
    A guy mentioned I could be overflowing float representation so Iv re implemented the for as
    Code:
    for (x=0; x < (long) (input->image)->columns; x++)
        {
         
          q->red = floorf(q->red/quantfactor);
          q->red = q->red*quantfactor;
          q->green = floorf(q->green/quantfactor);
          q->green = q->green*quantfactor;
          q->blue = floorf(q->blue/quantfactor);
          q->blue = q->green*quantfactor;
    
          q++;
        }
    but I still have the same output =/
    Oh Ive forgotten to provide the definition of Picture :P
    Here it goes:
    Code:
    typedef struct Picture Picture;
    struct Picture{
       Image* image;
       ImageInfo* data;
       MagickWand* wand;
       PixelPacket* pixels;
       PixelIterator* image_iterator;
       StringInfo* profile;
       ExceptionInfo* exception;
       Image* canvas;
    };
    Thanks in advance
    Last edited by Maragato; 09-18-2006 at 09:45 PM. Reason: typo

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    This is just a guess. It looks like you need to move the PixelPacket buffer (which you called q) to the Picture buffer (which you called output). It appears you did the transformation to q, but never moved it to the output buffer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Replies: 6
    Last Post: 03-03-2005, 03:52 AM
  3. Reading color tiff images?
    By compz in forum Game Programming
    Replies: 1
    Last Post: 11-21-2003, 12:48 AM
  4. Replies: 4
    Last Post: 03-02-2003, 09:12 AM
  5. How to change a mouse cursor in console mode
    By GaPe in forum Windows Programming
    Replies: 10
    Last Post: 07-03-2002, 07:42 AM