I need to save RGB values of each pixel in a 3D array A[width][height][3]. I found a code online that transfers the bytes into an array but I cant understand how bytes are saved them so i could transfer them into an array. The truth is I dont know much about working with images at all so i have a problem working on them. Can someone help me transfer the RGB data from an .jpeg image into a 3D array? This is my code so far:
Why are you storing them in a 3d array? That's unnecessary. Assuming you're loading this for OpenGL, just dump the contents into a 1d array and ship it off to the GPU.
Im working on pixel enchanting program and it works for .bmp images, but im enchancing .bmp images by an algorithm that I wrote that works on a 3D array.. so was looking to do the same on .jpg images.
Maybe it's not GOOD C++... But it's still C++. On to the question, a 3D array is a very bad idea. Get a one-dimensional array of packed RGB data.
You can find your pixel at (X + (Y * width)).
Isn't it simpler?
Sure, but then i also have to change the quality enchanceing algorithm. Ill give it a shot.
@EssGeEich
Im sorry i didnt fully understand your idea. After i save the bytes containing the RGB data, what should i do next, how do you expect me to access each pixel information and save the R G B values? I need them as numbers from 0-255, the whole idea is based on that.
1 2 3 4 5 6 7
data_size = x * y * 3;
jdata = (unsignedchar *)malloc(data_size);
for (;info.output_scanline < info.output_height;)
{
rowptr[0] = (unsignedchar *)jdata + 3*info.output_width*info.output_scanline;
jpeg_read_scanlines(&info, rowptr, 1);
}