MCPcopy Create free account
hub / github.com/assimp/assimp / SaveAsTGA

Function SaveAsTGA

tools/assimp_cmd/ImageExtractor.cpp:176–198  ·  view source on GitHub ↗

----------------------------------------------------------------------------------- Save a texture as tga

Source from the content-addressed store, hash-verified

174// -----------------------------------------------------------------------------------
175// Save a texture as tga
176int SaveAsTGA(FILE *file, const aiTexel *data, unsigned int width, unsigned int height) {
177 if (!file || !data) {
178 return 1;
179 }
180
181 TGA_HEADER head;
182 memset(&head, 0, sizeof(head));
183 head.bits = 32;
184 head.height = (uint16_t)height;
185 head.width = (uint16_t)width;
186 head.descriptor |= (1u << 5);
187
188 head.imagetype = 2; // actually it's RGBA
189 fwrite(&head, sizeof(TGA_HEADER), 1, file);
190
191 for (unsigned int y = 0; y < height; ++y) {
192 for (unsigned int x = 0; x < width; ++x) {
193 fwrite(data + y * width + x, 4, 1, file);
194 }
195 }
196
197 return 0;
198}
199
200// -----------------------------------------------------------------------------------
201// Do the texture import for a given aiTexture

Callers 1

DoExportFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected