Go to the source code of this file.
manipulation directe d'images, format .hdr
Definition in file image_hdr.h.
◆ read_image_hdr()
Image read_image_hdr |
( |
const char * |
filename | ) |
|
charge une image a partir d'un fichier .hdr. renvoie Image::error() en cas d'echec. a detruire avec image::release( ).
- Parameters
-
filename | nom de l'image .hdr a charger |
Definition at line 16 of file image_hdr.cpp.
18 FILE *in= fopen(filename,
"rb");
21 printf(
"[error] loading hdr image '%s'...\n", filename);
27 if(RGBE_ReadHeader(in, &width, &height, &info) != RGBE_RETURN_SUCCESS)
30 printf(
"[error] loading hdr image '%s'...\n", filename);
34 std::vector<float> data(width*height*3, 0.f);
35 if(RGBE_ReadPixels_RLE(in, &data.front(), width, height) != RGBE_RETURN_SUCCESS)
38 printf(
"[error] loading hdr image '%s'...\n", filename);
45 printf(
"loading hdr image '%s' %dx%d...\n", filename, width, height);
46 Image image(width, height);
49 for(
int y= 0; y < height; y++)
50 for(
int x= 0; x < width; x++, i+= 3)
51 image(x, height - y -1)=
Color(data[i], data[i+1], data[i+2]);
representation d'une image.
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
representation d'une couleur (rgba) transparente ou opaque.
◆ write_image_hdr()
int write_image_hdr |
( |
const Image & |
image, |
|
|
const char * |
filename |
|
) |
| |
enregistre une image dans un fichier .hdr.
Definition at line 56 of file image_hdr.cpp.
61 FILE *out= fopen(filename,
"wb");
64 printf(
"[error] writing hdr image '%s'...\n", filename);
68 int width= image.
width();
69 int height= image.
height();
70 if(RGBE_WriteHeader(out, width, height, NULL) != RGBE_RETURN_SUCCESS)
74 printf(
"[error] writing hdr image '%s'...\n", filename);
78 std::vector<float> data(width*height*3, 0.f);
80 for(
int y= 0; y < height; y++)
81 for(
int x= 0; x < width; x++, i+= 3)
83 Color color= image(x, height - y -1);
89 int code= RGBE_WritePixels_RLE(out, &data.front(), width, height);
92 if(code != RGBE_RETURN_SUCCESS)
94 printf(
"[error] writing hdr image '%s'...\n", filename);
98 printf(
"writing hdr image '%s'...\n", filename);
int height() const
renvoie la hauteur de l'image.
int width() const
renvoie la largeur de l'image.
◆ is_hdr_image()
bool is_hdr_image |
( |
const char * |
filename | ) |
|
renvoie vrai si le nom de fichier se termine par .hdr.
Definition at line 10 of file image_hdr.cpp.
12 return (std::string(filename).rfind(
".hdr") != std::string::npos);
◆ read_image_pfm()
Image read_image_pfm |
( |
const char * |
filename | ) |
|
charge une image a partir d'un fichier .pfm.
Definition at line 103 of file image_hdr.cpp.
105 FILE *in= fopen(filename,
"rb");
108 printf(
"[error] loading pfm image '%s'...\n", filename);
114 if(fscanf(in,
"PF\xa%d %d\xa%f[^\xa]", &w, &h, &endian) != 3
117 printf(
"[error] loading pfm image '%s'...\n", filename);
122 unsigned char c= fgetc(in);
128 printf(
"loading pfm image '%s' %dx%d...\n", filename, w, h);
132 for(
int y= 0; y < h; y++)
133 for(
int x= 0; x < w; x++)
136 if(fread(&pixel.r,
sizeof(
float), 3, in) == 3)
◆ write_image_pfm()
int write_image_pfm |
( |
const Image & |
image, |
|
|
const char * |
filename |
|
) |
| |
enregistre une image dans un fichier .pfm.
Definition at line 146 of file image_hdr.cpp.
148 FILE *out= fopen(filename,
"wb");
151 printf(
"[error] writing pfm image '%s'...\n", filename);
155 fprintf(out,
"PF\xa%d %d\xa-1\xa", image.
width(), image.
height());
157 for(
int y= 0; y < image.
height(); y++)
158 for(
int x= 0; x < image.
width(); x++)
160 Color pixel= image(x, y);
161 fwrite(&pixel.r,
sizeof(
float), 3, out);
165 printf(
"writing pfm image '%s'...\n", filename);
◆ is_pfm_image()
bool is_pfm_image |
( |
const char * |
filename | ) |
|
renvoie vrai si le nom de fichier se termine par .pfm.
Definition at line 171 of file image_hdr.cpp.
173 return (std::string(filename).rfind(
".pfm") != std::string::npos);