gKit2 light
Loading...
Searching...
No Matches
image_hdr.h File Reference
#include "image.h"

Go to the source code of this file.

Functions

bool is_hdr_image (const char *filename)
 renvoie vrai si le nom de fichier se termine par .hdr.
Image read_image_pfm (const char *filename)
 charge une image a partir d'un fichier .pfm.
int write_image_pfm (const Image &image, const char *filename)
 enregistre une image dans un fichier .pfm.
bool is_pfm_image (const char *filename)
 renvoie vrai si le nom de fichier se termine par .pfm.

Detailed Description

manipulation directe d'images, format .hdr et .pfm

Definition in file image_hdr.h.

Function Documentation

◆ 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.

11{
12 return (std::string(filename).rfind(".hdr") != std::string::npos);
13}

◆ read_image_pfm()

Image read_image_pfm ( const char * filename)

charge une image a partir d'un fichier .pfm.

Definition at line 15 of file image_hdr.cpp.

16{
17 FILE *in= fopen(filename, "rb");
18 if(in == nullptr)
19 {
20 printf("[error] loading pfm image '%s'...\n", filename);
21 return Image();
22 }
23
24 int w, h;
25 float endian= 0;
26 if(fscanf(in, "PF\xa%d %d\xa%f[^\xa]", &w, &h, &endian) != 3
27 || endian != -1)
28 {
29 printf("[error] loading pfm image '%s'...\n", filename);
30 return Image();
31 }
32
33 // saute la fin de l'entete
34 unsigned char c= fgetc(in);
35 while(c != '\xa')
36 c= fgetc(in);
37
38 // pourquoi aussi tordu ? fscanf(in, "PF\n%d %d\n%f\n") consomme les espaces apres le \n... ce qui est un poil genant pour relire les floats...
39
40 printf("loading pfm image '%s' %dx%d...\n", filename, w, h);
41
42 Image image(w, h);
43
44 for(int y= 0; y < h; y++)
45 for(int x= 0; x < w; x++)
46 {
47 Color pixel;
48 if(fread(&pixel.r, sizeof(float), 3, in) == 3)
49 image(x, y)= pixel;
50 }
51 fclose(in);
52
53 return image;
54}
representation d'une image.
Definition image.h:21
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().
Definition text.cpp:140
representation d'une couleur (rgba) transparente ou opaque.
Definition color.h:14

◆ write_image_pfm()

int write_image_pfm ( const Image & image,
const char * filename )

enregistre une image dans un fichier .pfm.

Definition at line 58 of file image_hdr.cpp.

59{
60 FILE *out= fopen(filename, "wb");
61 if(out == nullptr)
62 {
63 printf("[error] writing pfm image '%s'...\n", filename);
64 return -1;
65 }
66
67 fprintf(out, "PF\xa%d %d\xa-1\xa", image.width(), image.height());
68
69 for(unsigned y= 0; y < image.height(); y++)
70 for(unsigned x= 0; x < image.width(); x++)
71 {
72 Color pixel= image(x, y);
73 fwrite(&pixel.r, sizeof(float), 3, out);
74 }
75 fclose(out);
76
77 printf("writing pfm image '%s'...\n", filename);
78 return 0;
79}

◆ is_pfm_image()

bool is_pfm_image ( const char * filename)

renvoie vrai si le nom de fichier se termine par .pfm.

Definition at line 83 of file image_hdr.cpp.

84{
85 return (std::string(filename).rfind(".pfm") != std::string::npos);
86}