diff options
| author | raysan5 <[email protected]> | 2018-01-06 02:50:20 +0100 |
|---|---|---|
| committer | raysan5 <[email protected]> | 2018-01-06 02:50:20 +0100 |
| commit | 7fa28611607c210789054056095588b17c5bdaac (patch) | |
| tree | ee470bf077b1f45ece7494387341d5fd623d62e1 /src/textures.c | |
| parent | 0e48396369f7cb3c41a69c9d7dba01328e0dd51c (diff) | |
| download | raylib-7fa28611607c210789054056095588b17c5bdaac.tar.gz raylib-7fa28611607c210789054056095588b17c5bdaac.zip | |
Added function: GetPixelDataSize()
Just found I need that function...
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/textures.c b/src/textures.c index fd2fae0d..9abee62b 100644 --- a/src/textures.c +++ b/src/textures.c @@ -515,6 +515,43 @@ Color *GetImageData(Image image) return pixels; } +// Get pixel data size in bytes (image or texture) +// NOTE: Size depends on pixel format +int GetPixelDataSize(int width, int height, int format) +{ + int dataSize = 0; // Size in bytes + int bpp = 0; // Bits per pixel + + switch (format) + { + case UNCOMPRESSED_GRAYSCALE: bpp = 8; break; + case UNCOMPRESSED_GRAY_ALPHA: + case UNCOMPRESSED_R5G6B5: + case UNCOMPRESSED_R5G5B5A1: + case UNCOMPRESSED_R4G4B4A4: bpp = 16; break; + case UNCOMPRESSED_R8G8B8A8: bpp = 32; break; + case UNCOMPRESSED_R8G8B8: bpp = 24; break; + case UNCOMPRESSED_R32G32B32: bpp = 32*3; break; + case UNCOMPRESSED_R32G32B32A32: bpp = 32*4; break; + case COMPRESSED_DXT1_RGB: + case COMPRESSED_DXT1_RGBA: + case COMPRESSED_ETC1_RGB: + case COMPRESSED_ETC2_RGB: + case COMPRESSED_PVRT_RGB: + case COMPRESSED_PVRT_RGBA: bpp = 4; break; + case COMPRESSED_DXT3_RGBA: + case COMPRESSED_DXT5_RGBA: + case COMPRESSED_ETC2_EAC_RGBA: + case COMPRESSED_ASTC_4x4_RGBA: bpp = 8; break; + case COMPRESSED_ASTC_8x8_RGBA: bpp = 2; break; + default: break; + } + + dataSize = width*height*bpp/8; // Total data size in bytes + + return dataSize; +} + // Get pixel data from GPU texture and return an Image // NOTE: Compressed texture formats not supported Image GetTextureData(Texture2D texture) |
