//- // ========================================================================== // Copyright (C) 1995 - 2005 Alias Systems Corp. and/or its licensors. All // rights reserved. // // The coded instructions, statements, computer programs, and/or related // material (collectively the "Data") in these files are provided by Alias // Systems Corp. ("Alias") and/or its licensors for the exclusive use of the // Customer (as defined in the Alias Software License Agreement that // accompanies this Alias software). Such Customer has the right to use, // modify, and incorporate the Data into other products and to distribute such // products for use by end-users. // // THE DATA IS PROVIDED "AS IS". ALIAS HEREBY DISCLAIMS ALL WARRANTIES // RELATING TO THE DATA, INCLUDING, WITHOUT LIMITATION, ANY AND ALL EXPRESS OR // IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. IN NO EVENT SHALL ALIAS BE LIABLE FOR ANY DAMAGES // WHATSOEVER, WHETHER DIRECT, INDIRECT, SPECIAL, OR PUNITIVE, WHETHER IN AN // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, OR IN EQUITY, // ARISING OUT OF ACCESS TO, USE OF, OR RELIANCE UPON THE DATA. // ========================================================================== //+ /////////////////////////////////////////////////////////////////// // DESCRIPTION: // Some utilities to do file format conversions and others ... // /////////////////////////////////////////////////////////////////// #include #include #include "MNormalMapConverter.h" // Convert the heightfield texture to its corresponding normal map texture // bool MNormalMapConverter::convertToNormalMap( unsigned char* inImagePtr, unsigned int width, unsigned int height, OutFormatType outputPixelFormat, float bumpScale, unsigned char* outImagePtr ) { bool isOK = true; // Firewall: The input image should not be a NULL pointer, // if( NULL == inImagePtr ) return false; // No output file specified: convert in place // if( NULL == outImagePtr ) { convertToNormalMap_InPlace( inImagePtr, width, height, outputPixelFormat, bumpScale ); } else { if( outputPixelFormat == RGBA ) { // // Not implemented yet // // similar to the convertToNormalMap_InPlace but we store // the resulting texture in the outImagePtr and not // in the inImagePtr texture // } else if( outputPixelFormat == HILO ) { // Not implemented yet } else { isOK = false; } } return isOK; } // The heightfield texture inImage will be replaced from grey levels in RGBA // to the normal map values as specified by the pixel format // bool MNormalMapConverter::convertToNormalMap_InPlace( unsigned char* inImagePtr, unsigned int width, unsigned int height, OutFormatType outputPixelFormat, float bumpScale ) { bool isOK = true; if( outputPixelFormat == RGBA ) { bumpScale /= 255.0f; // will be used on unsignedChar unsigned int widthMinus1 = width - 1; unsigned int heightMinus1 = height - 1; unsigned int offset = (4 * width); // = sizeof(rgba) * width // ================== // Process the texels // ================== // Get the current pointer to the starting texel at (0,0) // unsigned char* imagePtr = inImagePtr; // For each rows (except the last one) // unsigned int m, n; for( m=0; m