18 #ifndef PIC_IO_TGA_HPP 19 #define PIC_IO_TGA_HPP 25 #include "../base.hpp" 26 #include "../util/buffer.hpp" 63 int &width,
int &height,
int &channels)
65 std::ifstream tga_in(nameFile.c_str(), std::ios::binary);
67 if(!tga_in.is_open()) {
73 tga_in.read((
char*)(&header.
id_length), 1);
81 tga_in.read((
char*)(&header.
x_origin), 2);
82 tga_in.read((
char*)(&header.
y_origin), 2);
83 tga_in.read((
char*)(&header.
width), 2);
84 tga_in.read((
char*)(&header.
height), 2);
85 tga_in.read((
char*)(&header.
depth), 1);
89 width = (int)(header.
width);
90 height = (int)(header.
height);
99 if(!((header.
depth==32) || (header.
depth==24))) {
104 channels = header.
depth / 8;
106 int size = width * height * channels;
108 data =
new unsigned char[size];
113 tga_in.read((
char*)(data), size);
140 int width,
int height,
int channels)
142 std::ofstream tga_out(nameFile.c_str(), std::ios::binary);
144 if(!tga_out.is_open()) {
159 header.
width = width;
161 header.
depth = 8 * channels;
175 tga_out.write((
char*)(&header.
id_length), 1);
177 tga_out.write((
char*)(&header.
image_type), 1);
183 tga_out.write((
char*)(&header.
x_origin), 2);
184 tga_out.write((
char*)(&header.
y_origin), 2);
185 tga_out.write((
char*)(&header.
width), 2);
186 tga_out.write((
char*)(&header.
height), 2);
187 tga_out.write((
char*)(&header.
depth), 1);
188 tga_out.write((
char*)(&header.
descriptor), 1);
193 tga_out.write((
char*)(data), width * height * channels);
short int colormap_first_entry
Definition: tga.hpp:39
unsigned char colormap_type
Definition: tga.hpp:35
unsigned char depth
Definition: tga.hpp:48
unsigned char colormap_entry_size
Definition: tga.hpp:41
short int y_origin
Definition: tga.hpp:45
short int height
Definition: tga.hpp:47
static void flipV(T *buffer, int width, int height, int channels, int frames)
flipV flips an image vertically
Definition: buffer.hpp:414
short int colormap_length
Definition: tga.hpp:40
short int width
Definition: tga.hpp:46
short int x_origin
Definition: tga.hpp:44
#define PIC_INLINE
Definition: base.hpp:33
unsigned char id_length
Definition: tga.hpp:34
unsigned char descriptor
Definition: tga.hpp:50
PIC_INLINE unsigned char * ReadTGA(std::string nameFile, unsigned char *data, int &width, int &height, int &channels)
ReadTGA reads an image in the .tga format.
Definition: tga.hpp:62
The TGA_HEADER struct.
Definition: tga.hpp:33
unsigned char image_type
Definition: tga.hpp:36
Definition: bilateral_separation.hpp:25
PIC_INLINE bool WriteTGA(std::string nameFile, const unsigned char *data, int width, int height, int channels)
WriteTGA writes an image in the .tga format.
Definition: tga.hpp:139
static T * BGRtoRGB(T *buffer, int width, int height, int channels, int frames)
BGRtoRGB swizzles from BGR to RGB a buffer.
Definition: buffer.hpp:659