| 5374 | } |
| 5375 | |
| 5376 | int32_t imageWriteTga(bx::WriterI* _writer, uint32_t _width, uint32_t _height, uint32_t _srcPitch, const void* _src, bool _grayscale, bool _yflip, bx::Error* _err) |
| 5377 | { |
| 5378 | BX_ERROR_SCOPE(_err); |
| 5379 | |
| 5380 | uint8_t type = _grayscale ? 3 : 2; |
| 5381 | uint8_t bpp = _grayscale ? 8 : 32; |
| 5382 | |
| 5383 | uint8_t header[18] = {}; |
| 5384 | header[ 2] = type; |
| 5385 | header[12] = _width &0xff; |
| 5386 | header[13] = (_width >>8)&0xff; |
| 5387 | header[14] = _height &0xff; |
| 5388 | header[15] = (_height>>8)&0xff; |
| 5389 | header[16] = bpp; |
| 5390 | header[17] = 32; |
| 5391 | |
| 5392 | int32_t total = 0; |
| 5393 | total += bx::write(_writer, header, sizeof(header), _err); |
| 5394 | |
| 5395 | uint32_t dstPitch = _width*bpp/8; |
| 5396 | if (_yflip) |
| 5397 | { |
| 5398 | const uint8_t* data = (const uint8_t*)_src + _srcPitch*_height - _srcPitch; |
| 5399 | for (uint32_t yy = 0; yy < _height && _err->isOk(); ++yy) |
| 5400 | { |
| 5401 | total += bx::write(_writer, data, dstPitch, _err); |
| 5402 | data -= _srcPitch; |
| 5403 | } |
| 5404 | } |
| 5405 | else if (_srcPitch == dstPitch) |
| 5406 | { |
| 5407 | total += bx::write(_writer, _src, _height*_srcPitch, _err); |
| 5408 | } |
| 5409 | else |
| 5410 | { |
| 5411 | const uint8_t* data = (const uint8_t*)_src; |
| 5412 | for (uint32_t yy = 0; yy < _height && _err->isOk(); ++yy) |
| 5413 | { |
| 5414 | total += bx::write(_writer, data, dstPitch, _err); |
| 5415 | data += _srcPitch; |
| 5416 | } |
| 5417 | } |
| 5418 | |
| 5419 | return total; |
| 5420 | } |
| 5421 | |
| 5422 | template<typename Ty> |
| 5423 | class HashWriter : public bx::WriterI |