From 21eaad595acb574d81bad5140d24b570da4f9785 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Thu, 3 Nov 2016 10:27:50 +0200 Subject: [PATCH] Have get_component_size return zero for unsized formats Get_pixel_size still assumes a component size of at least one byte. --- source/pixelformat.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/pixelformat.cpp b/source/pixelformat.cpp index ac2b1ea7..320fef1f 100644 --- a/source/pixelformat.cpp +++ b/source/pixelformat.cpp @@ -177,6 +177,17 @@ unsigned get_component_size(PixelFormat pf) { switch(pf) { + case R8: + case RG8: + case RGB8: + case RGBA8: + case SRGB8: + case SRGB8_ALPHA8: + case LUMINANCE8: + case LUMINANCE8_ALPHA8: + case SLUMINANCE8: + case SLUMINANCE8_ALPHA8: + return 1; case R16F: case RG16F: case RGB16F: @@ -192,13 +203,13 @@ unsigned get_component_size(PixelFormat pf) case DEPTH_COMPONENT32: return 4; default: - return 1; + return 0; } } unsigned get_pixel_size(PixelFormat pf) { - return get_component_count(pf)*get_component_size(pf); + return get_component_count(pf)*max(get_component_size(pf), 1U); } void require_pixelformat(PixelFormat pf) -- 2.45.2