Commits

Jason McKesson committed da849bb Merge

Merge

Comments (0)

Files changed (3)

+/**
+\defgroup module_glimg GL Image
+
+**/
+
+/**
+\defgroup module_glimg_format Image Format
+
+\ingroup module_glimg
+**/
+
+/**
+\page page_glimg_format_validation Image Format Validation Rules
+
+**/
+
+/**
+\defgroup module_glimg_imageset ImageSet
+
+\ingroup module_glimg
+**/
+
+/**
+\defgroup module_glimg_loaders Image Loaders
+
+\ingroup module_glimg
+**/
+
+/**
+\defgroup module_glimg_texture Texture Creation
+
+\ingroup module_glimg
+**/
+
+/**
+\defgroup module_glimg_creation Image Creation
+
+\ingroup module_glimg
+**/
+
+/**
+\defgroup module_glimg_exceptions Exceptions
+
+\ingroup module_glimg
+**/

glimg/source/Util.cpp

+
+#include "ImageSetImpl.h"
+#include "Util.h"
+
+#define ARRAY_COUNT( array ) (sizeof( array ) / (sizeof( array[0] ) * (sizeof( array ) != sizeof(void*) || sizeof( array[0] ) <= sizeof(void*))))
+
+namespace glimg
+{
+	namespace
+	{
+		template<int arrayCount, typename TestType>
+		bool IsOneOfThese(TestType testValue, TestType *testArray)
+		{
+			for(int loop = 0; loop < arrayCount; loop++)
+			{
+				if(testValue == testArray[loop])
+					return true;
+			}
+
+			return false;
+		}
+
+		PixelComponents g_twoCompFormats[] = {FMT_COLOR_RG, FMT_DEPTH_X};
+		PixelComponents g_threeCompFormats[] = {FMT_COLOR_RGB, FMT_COLOR_RGB_sRGB};
+		PixelComponents g_fourCompFormats[] = {FMT_COLOR_RGBX, FMT_COLOR_RGBA,
+			FMT_COLOR_RGBX_sRGB, FMT_COLOR_RGBA_sRGB};
+	}
+
+	int ComponentCount(PixelComponents eFormat)
+	{
+		if(IsOneOfThese<ARRAY_COUNT(g_twoCompFormats)>(eFormat, g_twoCompFormats))
+			return 2;
+
+		if(IsOneOfThese<ARRAY_COUNT(g_threeCompFormats)>(eFormat, g_threeCompFormats))
+			return 3;
+
+		if(IsOneOfThese<ARRAY_COUNT(g_fourCompFormats)>(eFormat, g_fourCompFormats))
+			return 4;
+
+		return 1;
+	}
+
+	Dimensions ModifySizeForMipmap(Dimensions origDim, int mipmapLevel)
+	{
+		for(int iLoop = 0; iLoop < mipmapLevel; iLoop++)
+		{
+			origDim.width /= 2;
+			origDim.height /= 2;
+			origDim.depth /= 2;
+		}
+
+		return origDim;
+	}
+
+	size_t CalcBytesPerPixel( const ImageFormat &fmt )
+	{
+		size_t bytesPerPixel = 0;
+		switch(fmt.eBitdepth)
+		{
+		case BD_COMPRESSED:			return 0;
+		case BD_PER_COMP_8:					bytesPerPixel = 1;		break;
+		case BD_PER_COMP_16:				bytesPerPixel = 2;		break;
+		case BD_PER_COMP_32:				bytesPerPixel = 4;		break;
+		case BD_PACKED_16_BIT_565:			bytesPerPixel = 2;		break;
+		case BD_PACKED_16_BIT_5551:			bytesPerPixel = 2;		break;
+		case BD_PACKED_16_BIT_4444:			bytesPerPixel = 2;		break;
+		case BD_PACKED_32_BIT_8888:			bytesPerPixel = 4;		break;
+		case BD_PACKED_32_BIT_1010102:		bytesPerPixel = 4;		break;
+		case BD_PACKED_32_BIT_248:			bytesPerPixel = 4;		break;
+		case BD_PACKED_16_BIT_565_REV:		bytesPerPixel = 2;		break;
+		case BD_PACKED_16_BIT_1555_REV:		bytesPerPixel = 2;		break;
+		case BD_PACKED_16_BIT_4444_REV:		bytesPerPixel = 2;		break;
+		case BD_PACKED_32_BIT_8888_REV:		bytesPerPixel = 4;		break;
+		case BD_PACKED_32_BIT_2101010_REV:	bytesPerPixel = 4;		break;
+		case BD_PACKED_32_BIT_101111_REV:	bytesPerPixel = 4;		break;
+		case BD_PACKED_32_BIT_5999_REV:		bytesPerPixel = 4;		break;
+		}
+
+		if(fmt.eBitdepth < BD_NUM_PER_COMPONENT)
+			bytesPerPixel *= ComponentCount(fmt.eFormat);
+
+		return bytesPerPixel;
+	}
+}

glimg/source/Util.h

+
+#include "glimg/ImageSet.h"
+
+namespace glimg
+{
+	Dimensions ModifySizeForMipmap(Dimensions origDim, int mipmapLevel);
+
+	//Does not work for compressed textures.
+	size_t CalcBytesPerPixel(const ImageFormat &fmt);
+
+	int ComponentCount(PixelComponents eFormat);
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.