00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "SO3ConversionTools.h"
00029
00030 namespace SO3
00031 {
00032
00037 ConversionTools::ConversionTools()
00038 {
00039
00040 }
00041
00042 int ConversionTools::OgreToScolColorRGBA(Ogre::ColourValue ogreColor)
00043 {
00044
00045
00046 int a = static_cast<int>(ogreColor.a * CONST_COLOR_ALPHA);
00047 int b = static_cast<int>(ogreColor.b * CONST_COLOR);
00048 int g = static_cast<int>(ogreColor.g * CONST_COLOR);
00049 int r = static_cast<int>(ogreColor.r * CONST_COLOR);
00050 return 0x0 + ((a & 0x0000007E) + ((b & 0x000000ff) << 7) + ((g & 0x000000ff) << 15) + ((r & 0x000000ff) << 23));
00051 }
00052
00053 Ogre::ColourValue ConversionTools::ScolToOgreColorRGBA(int scolColor)
00054 {
00055
00056
00057 float r = ((scolColor>>23) & 0x000000ff) / CONST_COLOR;
00058 float g = ((scolColor>>15) & 0x000000ff) / CONST_COLOR;
00059 float b = ((scolColor>>7 ) & 0x000000ff) / CONST_COLOR;
00060 float a = ((scolColor ) & 0x0000007E) / CONST_COLOR_ALPHA;
00061 return Ogre::ColourValue(r, g, b, a);
00062 }
00063
00064 int ConversionTools::OgreToScolColorRGB(Ogre::ColourValue ogreColor)
00065 {
00066
00067
00068 int b = static_cast<int>(ogreColor.b * CONST_COLOR);
00069 int g = static_cast<int>(ogreColor.g * CONST_COLOR);
00070 int r = static_cast<int>(ogreColor.r * CONST_COLOR);
00071 return 0x0 + (r & 0x000000ff) + ((g & 0x000000ff) << 8) + ((b & 0x000000ff) << 16);
00072 }
00073
00074 Ogre::ColourValue ConversionTools::ScolToOgreColorRGB(int scolColor)
00075 {
00076
00077
00078 float b = ((scolColor>>16) & 0x000000ff) / CONST_COLOR;
00079 float g = ((scolColor>>8) & 0x000000ff) / CONST_COLOR;
00080 float r = ((scolColor) & 0x000000ff) / CONST_COLOR;
00081 return Ogre::ColourValue(r, g, b, 1.0f);
00082 }
00083
00084 void ConversionTools::ScolBitmapGetRGB(PtrObjBitmap scolBitmap, unsigned char* buff)
00085 {
00086 if ((scolBitmap == 0) || (buff == 0))
00087 return;
00088
00089
00090 int sbpl = scolBitmap->BPL;
00091 int dbpl = scolBitmap->TailleW * 3;
00092
00093 if (sbpl == dbpl)
00094 memcpy(buff, scolBitmap->bits, scolBitmap->TailleW * scolBitmap->TailleH * scolBitmap->BytesPP);
00095 else
00096 for (long y=0; y<scolBitmap->TailleH; y++)
00097 {
00098 for (long x=0; x<scolBitmap->TailleW; x++)
00099 {
00100 unsigned long srcByte = (x * scolBitmap->BytesPP) + (sbpl * y);
00101 unsigned long destByte = (x * 3) + (dbpl * y);
00102
00103 buff[destByte] = scolBitmap->bits[srcByte];
00104 buff[destByte + 1] = scolBitmap->bits[srcByte + 1];
00105 buff[destByte + 2] = scolBitmap->bits[srcByte + 2];
00106 }
00107 }
00108 }
00109
00110 void ConversionTools::ScolBitmapGetRGBA(PtrObjBitmap scolBitmap, PtrObjBitmap alphaBitmap, Ogre::uint32* buff)
00111 {
00112 if ((scolBitmap == 0) || (buff == 0))
00113 return;
00114
00115
00116 int sbpl = scolBitmap->BPL;
00117 int abpl = (alphaBitmap != 0) ? alphaBitmap->BPL : scolBitmap->TailleW;
00118 int dbpl = scolBitmap->TailleW;
00119
00120 for (long y=0; y<scolBitmap->TailleH; y++)
00121 {
00122 for (long x=0; x<scolBitmap->TailleW; x++)
00123 {
00124 unsigned long srcByte = (x * scolBitmap->BytesPP) + (sbpl * y);
00125 unsigned long srcByteA = (x * ((alphaBitmap != 0) ? alphaBitmap->BytesPP : 1)) + (abpl * y);
00126 unsigned long destByte = x + (dbpl * y);
00127 Ogre::uint32 color = static_cast<Ogre::uint32>(((alphaBitmap != 0) ? alphaBitmap->bits[srcByteA] : 0xff) + (scolBitmap->bits[srcByte] << 8) + (scolBitmap->bits[srcByte + 1] << 16) + (scolBitmap->bits[srcByte + 2] << 24));
00128 *(buff + destByte) = color;
00129 }
00130 }
00131 }
00132
00133 }