// Ryzom - MMORPG Framework // Copyright (C) 2010 Winch Gate Property Limited // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Affero General Public License as // published by the Free Software Foundation, either version 3 of the // License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Affero General Public License for more details. // // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . #ifndef RY_BMP4IMAGE_H #define RY_BMP4IMAGE_H #include #include #include #include template class CBMP4Image { public: CBMP4Image(): hdr(W,H) { // nlassert((W&0xf)==0); memset(Data,0,sizeof(Data)); } void circle() { // a rough circle round the centre point of the grid for (int j=0;j Line; std::vector ColorMap; NLMISC::COFile File; CTGAImage() : IdLength(0), ColourMapType(0), DataTypeCode(2), ColourMapOrigin(0), ColourMapLength(0), ColourMapDepth(0), XOrigin(0), YOrigin(0), BitsPerPixel(16), ImageDescriptor(0) { } void setup(uint16 width, uint16 height, const std::string &filename, uint16 xorigin, uint16 yorigin) { Width = width; Height = height; XOrigin = xorigin; YOrigin = yorigin; Line.resize(Width); File.open(filename); File.serial(IdLength); File.serial(ColourMapType); File.serial(DataTypeCode); File.serial(ColourMapOrigin); File.serial(ColourMapLength); File.serial(ColourMapDepth); File.serial(XOrigin); File.serial(YOrigin); File.serial(Width); File.serial(Height); File.serial(BitsPerPixel); File.serial(ImageDescriptor); } static uint16 getColor16(uint blue, uint green, uint red) { return ((red>>3)<<10) + ((green>>3)<<5) + (blue>>3); } static uint16 getBlue( uint16 color16 ) { return (color16 & 31) << 3; } static uint16 getGreen( uint16 color16 ) { return ((color16 & 0x3E0) >> 5) << 3; } static uint16 getRed( uint16 color16 ) { return ((color16 & 0x7C00) >> 10) << 3; } void setupForCol() { ColorMap.resize(16); ColorMap[0] = getColor16(0x00, 0x00, 0x00); ColorMap[1] = getColor16(0x00, 0x00, 0x80); ColorMap[2] = getColor16(0x00, 0x80, 0xFF); ColorMap[3] = getColor16(0x00, 0xFF, 0xFF); ColorMap[4] = getColor16(0x40, 0x00, 0x00); ColorMap[5] = getColor16(0x40, 0x00, 0x80); ColorMap[6] = getColor16(0x40, 0x80, 0xFF); ColorMap[7] = getColor16(0x40, 0xFF, 0xFF); ColorMap[8] = getColor16(0xA0, 0x00, 0x00); ColorMap[9] = getColor16(0xA0, 0x00, 0x80); ColorMap[10] = getColor16(0xA0, 0x80, 0xFF); ColorMap[11] = getColor16(0xA0, 0xFF, 0xFF); ColorMap[12] = getColor16(0xFF, 0x00, 0x00); ColorMap[13] = getColor16(0xFF, 0x00, 0x80); ColorMap[14] = getColor16(0xFF, 0x80, 0xFF); ColorMap[15] = getColor16(0x00, 0x40, 0x00); } void setup4BitGreyScale() { ColorMap.clear(); for (uint32 i=0;i<0x10;++i) { uint32 value= 0x11*i; ColorMap.push_back(getColor16(value, value, value)); } } void setup8BitGreyScale() { ColorMap.clear(); for (uint32 i=0;i<256;++i) { ColorMap.push_back(getColor16(i, i, i)); } } void set(uint col, uint idx) { nlassert(!ColorMap.empty()); Line[col] = ColorMap[idx%ColorMap.size()]; } void set(uint col, uint r, uint g, uint b) { Line[col] = getColor16(r, g, b); } void set16(uint col, uint16 color16) { Line[col] = color16; } void writeLine() { File.serialBuffer((uint8*)(&(Line[0])), Line.size()*2); } }; class CTGAImageGrey: public CTGAImage { public: struct SGreyPixel { uint8 r,g,b; }; std::vector GreyLine; CTGAImageGrey() { BitsPerPixel= 24; // ImageDescriptor= 32; } void set(uint32 x, uint32 greyValue) { if (GreyLine.size()x); GreyLine[x].r = (uint8)greyValue; GreyLine[x].g = (uint8)greyValue; GreyLine[x].b = (uint8)greyValue; } void writeLine() { File.serialBuffer((uint8*)(&(GreyLine[0])), GreyLine.size()*sizeof(GreyLine[0])); } }; #endif // RY_BMP4IMAGE_H