Basics to manipulate Images - ImadABID/photograph_The_Future GitHub Wiki

Basics Types

typedef struct structure2{ char *path; int l; int h; int add; int size; unsigned char *hex; }image;
typedef struct structure_of_color{
    unsigned char o1;
    unsigned char o2;
    unsigned char o3;
}color;

typedef struct structure_of_pixel{
    image img;
    int x;
    int y;
    color couleur;
}pixel;

Basics functions

Opening an image

To creat a new image use:
image set_image(char *img_path, int lenght, int hight);
To edit an existing image use:
image open(char *path);

Processing the image

void put_pixel(pixel px); Write the pixel (px) in its image.
pixel get_pixel(image img, int x, int y); Get the pixel which has the coordinates(x,y) from the image img.

Save the image

void save_image(image img); To save the image.

Exemple

#include "src/bmp.h"
int main(){
image img=set_image("french_flag.bmp",256,128);

color red=rgb(255,0,0);
color white=rgb(255,255,255);
color bleu=rgb(0,0,255); 

pixel px; px.img= img;
int x,y;

px.couleur=red;
for(x=0;x<img.l/3;x++){
    px.x=x;
    for(y=0;y<img.h;y++){
        px.y=y;
        put_pixel(px);
    }
}

px.couleur=white;
for(x=img.l/3;x<2*img.l/3;x++){
    px.x=x;
    for(y=0;y<img.h;y++){
        px.y=y;
        put_pixel(px);
    }
}

px.couleur=bleu;
for(x=2*img.l/3;x<img.l;x++){
    px.x=x;
    for(y=0;y<img.h;y++){
        px.y=y;
        put_pixel(px);
    }
}

save_image(img);

return 0;

}

Ce programme produit :

⚠️ **GitHub.com Fallback** ⚠️