----------------------------------------------------------------------------------- Save a texture as tga
| 174 | // ----------------------------------------------------------------------------------- |
| 175 | // Save a texture as tga |
| 176 | int 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 |