Si decide ir por un enfoque mínimo, sin dependencias libpng/libjpeg, sugiero usar stb_image
y stb_image_write
, encontrado here.
Es tan simple como se pone, solo necesita colocar los archivos de encabezado stb_image.h
y stb_image_write.h
en su carpeta.
Aquí está el código que se necesita leer imágenes:
#include <stdint.h>
#define STB_IMAGE_IMPLEMENTATION
#include "stb_image.h"
int main() {
int width, height, bpp;
uint8_t* rgb_image = stbi_load("image.png", &width, &height, &bpp, 3);
stbi_image_free(rgb_image);
return 0;
}
Y aquí está el código para escribir una imagen:
#include <stdint.h>
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#define CHANNEL_NUM 3
int main() {
int width = 800;
int height = 800;
uint8_t* rgb_image;
rgb_image = malloc(width*height*CHANNEL_NUM);
// Write your code to populate rgb_image here
stbi_write_png("image.png", width, height, CHANNEL_NUM, rgb_image, width*CHANNEL_NUM);
return 0;
}
puede compilar sin banderas o dependencias:
g++ main.cpp
Otras alternativas livianas incluyen:
Es la documentación de libjpeg (http://www.ijg.org/) o lo que sea nativo API tiene inadecuada ? – greyfade
No olvides elegir una respuesta correcta para las tres preguntas que has hecho. – mwcz