Resizing images to 2x2 - c++

I've got a texture I'm using in OpenGL 4.6 that I want to scale to 2x2, but I'm not sure how. Is there any way to resize an image in a way so that each pixel in the original image is basically duplicated to create a 2x2 in the resized image? I've tried using photoshop to do this, but the image quality always seems to drop significantly. Or do I have to manually create the image myself?

Related

Replace white background of image with transparent using C++ / OpenCV or Matlab

Using C++ / OpenCV or Matlab I'm trying to find a method to replace the white background of an image from file with a transparent background and then save the image for further use elsewhere. (The image is similar to something like this: http://www.psdgraphics.com/file/monitor-on-white-background.jpg)
I understand this task can be completed easily with simple image editing software but I need to do this for a large batch of images. I've tried methods such as Make white background transparent png matlab as well as a bunch of others with no luck.
Thanks!
Load the image. Loading images in OpenCV
Convert it to a 4 channel image. OpenCV: transforming 3 channel image into 4 channel
Determine where the background is adjust the alpha channel of those pixels accordingly. I don't know what your images look like, but if there is no other white in your images, it's a fairly simple task. (If a pixel is white, then it should be transparent.) Otherwise, if there is other white in your images, then you need to look for the contiguous region(s) of white that make up the background. See Flood Fill Algorithm
Save the image (See the link from 1.)

LibGDX: BufferedImage into Texture

I'm trying to play videos within a LibGDX application. I've managed to load the individual video frames sequentially into a java.awt.BufferedImage using Xuggler.
Now I'm stuck trying to get that into a LibGDX Texture. Anyone know a way to do this?
I managed to find these two LibGDX files that happen to use BufferedImage's, however can't see how to use this to get my data into a Texture :(
LibGDX JoglPixmap.java
LibGDX JoglTexture.java
as soon as you transformed your bufferedImage to a pixmap just use the Texture constructor passing in a pixmap:
Texture newTexture = new Texture(myPixmap);
There are methods to construct an empty Pixmap and draw onto it. Use this pixmap then as described above
If you are using LibGDX, I have to say that I don't recommend also using BufferedImages (from Java2D), instead you could use a Pixmap, or if you really do need BufferedImages, then I guess you could use ImageIO to save the image to a file, bring the file back in as a texture, then delete the file, but that seems quite hacky and inefficient.

C++ Image Manipulation

So I have made this program for a game and need help with making it a bit more automatic.
The program takes in an image and then displays it. I'm doing this over textures in OpenGL. When I take the screenshot of the game it is usually something about 700x400. I input the height and width into my program, resize the image to 1024x1024 (making it a POT texture for better compatibility) by adding blank space (the original image stays at the top left corner and goes all the way to (700,400) and the rest is just blank; does anyone know the term for this?) and then load it into my program and adjust the corners so only the part from (0,0) to (700,400) is shown.
That's how I handle the display of the image. Now, I would like to make this automatic. So I'd take a 700x400 picture, pass it to the program which would get the image's width and height (700x400), resize it to 1024x1024 by adding blank space and then load it.
So does anyone know a C++ library capable of doing this? I would still be taking the screenshot manually though.
I am using the Simple OpenGL Image Library (SOIL) for loading the picture (.bmp) and converting it into a texture.
Thanks!
You don't really have to resize by adding blank space to display image properly. In fact, it's really unefficient way to do it, especially because you store images in .bmp format.
SOIL is able to automatically add the blank space when loading textures - maybe just try to load the file as-is, without doing any operations.
From SOIL Documentation:
Can automatically rescale the image to the next largest power-of-two
size
Can load rectangluar textures for GUI elements or splash screens
(requires GL_ARB/EXT/NV_texture_rectangle)
Anyway, you don't have to use texture to display pixels on the screen. I presume you aren't using shaders for rendering - if it all goes through fixed pipeline, there's glDrawPixels function, which will be much simpler. Just remember to change your SOIL call to SOIL_load_image.

Resizing animated GIF using GraphicsMagick

I have an animated gif image with transparent frames.
I need to resize it.
Before resizing, I use the Magick::coalesceImages function, after I resize the image I use the Magick::writeImages function to collect all the gif frames back into one single image.
The problem is that the output resized image file size is bigger than the original one, because the original animated gif had transparent frames, and the new resized gif does not have any transparent frames.
I have read about frame optimization on www.imagemagick.org plus I can see on www.graphicsmagick.org the gifDisposeMethod function.
My question is, how can I cause the resized animated gif image to use transparency frames and avoid the increase on the image KBytes size?
Well, I found the way to go:
When resizing an animated gif, using Magick::coalesceImages() is not the best way...
Instead I am rezising according to percentage sizing and not absolute sizing, while skipping the Magick::coalesceImages() call.
For example, lets say my original animated gif is 300x300 and I want to resize it to be 150x150, I'll do the following:
Read the image in a Magick::Blob
Calculate the percentage numbers (50%x50% in my demo case)
Resize each and every frame of the image according to the percentage calculations.
This way we are not increasing each frame size because we are not using the Magick::coalesceImages() function and we are resizing each frame according to its original size, so we don't have any problem with the transparency of the frame.

Cocos2D: How to use Mask Image

I am using cocos2d for a game which uses sprite sheets for my character animations. I created these images using TexturePacker. Now, I want to use PVRTC 4 format for reducing memory consumption due to some reasons. But as the PVRTC Texture Compression
Usage Guide suggests, I need to add extra border of 4 pixels in each character to produce proper results. Even if I add border, I will have to mask this image with alpha image to remove border at run time. I am using Texture Packer to create a sprite sheet with PVRTC4 format and created alpha masking image matching it. I am ready with these 2 images in hand which are of same width and height.
Now my question is, how can I mask my PVRTC texture with alpha image in Cocos2D?
It will be more helpful if the solution provided works with Batch Nodes!
Thanks in advance for any solutions!
Why don't you just make the border/padding area completely transparent?
I was having the same problem, and after reading ray wenderlichs page about masking, I made a little ccsprite subclass which allows you to mask by 2 images.
CCMaskedSprite