I'm trying to make a C program that composites two images together, pixel by pixel. To store the image, I defined this struct:
struct pixel {
int r;//red
int g;//green
int b;//blue
int a;//alpha
};
typedef struct pixel pixel;
and then created an array of pointers to store each pixel:
int pixelcount=1000*1000; //Resolution of Image
pixel** image1pointer=malloc(sizeof(pixel*)*pixelcount);
pixel** image2pointer=malloc(sizeof(pixel*)*pixelcount);
pixel** resultimagepointer=malloc(sizeof(pixel*)*pixelcount);
then used a for
loop to initialise and assign (random) data to each pixel for both images, and blend them for the result image. This seems to work fine, but how would I import an actual JPEG (or other image format) into pixel values that this program can use?
I found a library called libjpeg
that looks like it might be able to do the trick, but I couldn't find how to use it to accomplish this, and how it would return the pixel values.
Edit: In addition to converting an image file into raw data, what is the format of the data that I can use to place it in the struct?