Problem with Scale and OpenGL

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tomf

Problem with Scale and OpenGL

Post by tomf »

I have a little OpenGL application which uses ImageMagick for loading images. The only problem is that after scaling the image looks really strange. Without scaling it works perfectly.

I know it's no imagemagick error, because if I write the scaled version into a new file it looks ok. But maybe somebody knows what the scaling function does - because I have no idea why it doesn't work after the scaling.

My code:

Code: Select all

Magick::Image image;
image.read(Magick::Geometry(info->new_size, info->new_size), info->file_info.absoluteFilePath().toStdString());
image.scale(Magick::Geometry(info->new_size, info->new_size));

Magick::Blob blob;
image.magick("RGBA");
image.write(&blob);

image.write("c:/testtest.jpg");

glBindTexture(GL_TEXTURE_2D, info->texture_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8 , image.columns(), image.rows(), 0, GL_BGRA, GL_UNSIGNED_BYTE, blob.data());
And here the images (first not scaled, second scaled):
Image
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Problem with Scale and OpenGL

Post by anthony »

Are you sure that openGL can read JPEG images. Looks like you are attempting to read a raw RGB image data rather than JPEG image data you are passing it.

By the way interesting image.

PS; scaling may not be what you want. Scaling works by simply averaging rows and columns together to produce a smaller image, it is not a proper resizing of the image which uses a filter averging method to improve the final result.

see IM examples Resize for complete details.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
tomf

Re: Problem with Scale and OpenGL

Post by tomf »

Thx you are right.There was something wrong with the format. I changed my write to

Code: Select all

image.write(&blob, "RGBA", 8)
and now it works perfectly.
Post Reply