0

I have a vector something of this sort

typedef struct
{
  int r,g,b;
} __attribute__((__packed__))
rgbs;

vector<rgbs> rgbt;

rgbs rgb;
for(int row=0;row<100; row++)
{
  for(int col=0;col<100; col++)
  {
     rgb.r=col+row;
     rgb.g=col+row;
     rgb.b=col+row;
     rgbt.push_back(rgb);
  }
}

What will be an efficient way to form a new image out of this vector using magick++;

2 Answers 2

1

I customized an example from Magick++ API documentation for you.

Blob blob( &rgbt[0], rgbt.size() / sizeof(rgbt[0]) );
Image image;
image.size( "100x100") 
image.magick( "RGB" ); 
image.read( blob);

But I am not sure if you should use one byte unsigned char instead of 4 bytes int. Give it a try and you'll see.

Sign up to request clarification or add additional context in comments.

1 Comment

terminate called after throwing an instance of 'Magick::ErrorCorruptImage' what(): Magick: unexpected end-of-file `': No such file or directory @ error/rgb.c/ReadRGBImage/229 Aborted (core dumped)
0

Zaffy was right::

32 bit integer cannot be used in this case as the sizeof pixelpacket pointer to a red, blue or green pixel is 16 bit.

So, we need to use 16 bit unsigned integer from the stdint library

#include<stdint.h>
typedef uint16_t WORD;

Now in the structure rgbs we initialise WORD r,g,b instead.

The way to initialise Blob is : Blob blob(address of the pixel data, size of data) So, the code will be something like this:

Blob blob(&rgbt[0],(rgbt.size()*sizeof(rgbt[0]));
Image image;
image.size("100x100");
image.magick("RGB");
image.read(blob);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.