29 #include <oc_stdlib.h> 30 #include <oc_errors.h> 37 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________ 41 oC_ColorMap_t * oC_ColorMap_New(
Allocator_t Allocator , AllocationFlags_t AllocationFlags , oC_Pixel_ResolutionUInt_t Width , oC_Pixel_ResolutionUInt_t Height , oC_ColorFormat_t ColorFormat )
45 if(Width > 0 && Height > 0 && ColorFormat != oC_ColorFormat_Unknown)
48 colorMap = kmalloc(
sizeof(
oC_ColorMap_t) , Allocator , AllocationFlags);
52 colorMap->Map = kmalloc(oC_Color_GetFormatSize(ColorFormat) * Width * Height , Allocator , AllocationFlags);
54 if(colorMap->Map !=
NULL)
56 colorMap->ColorFormat = ColorFormat;
57 colorMap->Height = Height;
58 colorMap->Width = Width;
59 colorMap->MagicNumber = oC_ColorMap_MagicNumber;
60 colorMap->FormatSize = oC_Color_GetFormatSize(ColorFormat);
65 oC_SaveIfFalse(
"ColorMap::New: cannot release memory" , kfree(colorMap,AllocationFlags), oC_ErrorCode_ReleaseError);
79 bool oC_ColorMap_Delete(
oC_ColorMap_t * ColorMap , AllocationFlags_t AllocationFlags )
83 if(oC_ColorMap_IsCorrect(ColorMap))
87 ColorMap->MagicNumber = 0;
89 if(kfree(ColorMap->WriteMap,AllocationFlags) && kfree(ColorMap,AllocationFlags))
103 return isaddresscorrect(ColorMap) && ColorMap->MagicNumber == oC_ColorMap_MagicNumber && isaddresscorrect(ColorMap->Map);
110 oC_Color_t color = 0;
112 if(oC_ColorMap_IsCorrect(ColorMap) && oC_ColorMap_IsPositionCorrect(ColorMap,Position))
114 oC_UInt_t formatSize = oC_Color_GetFormatSize(ColorMap->ColorFormat);
115 const uint8_t * colorRef = &ColorMap->ReadMap[(Position.X + ColorMap->Width * Position.Y)* formatSize ];
117 for(uint8_t byteIndex = 0; byteIndex < formatSize ; byteIndex++)
119 color |= (*colorRef) << byteIndex * 8;
123 color = oC_Color_ConvertToFormat(color,ColorMap->ColorFormat,ColorFormat);
131 static inline void SetColor(
oC_Pixel_Position_t Position , oC_Pixel_ResolutionUInt_t Width , oC_Pixel_ResolutionUInt_t Height , uint32_t FormatSize , uint8_t ColorMap[Height][Width][FormatSize] , oC_Color_t Color )
133 static const uint8_t bitOffset[4] = {
140 for(uint8_t byteIndex = 0 ; byteIndex < FormatSize ; byteIndex++)
142 ColorMap[Position.Y][Position.X][byteIndex] = (uint8_t)((Color >> bitOffset[byteIndex]) & 0xFF);
150 bool colorSet =
false;
153 if(ColorMap !=
NULL && Position.X < ColorMap->Width && Position.Y < ColorMap->Height)
155 oC_Color_t color = oC_Color_ConvertToFormat(Color,ColorFormat,ColorMap->ColorFormat);
156 SetColor(Position,ColorMap->Width,ColorMap->Height,ColorMap->FormatSize,ColorMap->GenericWriteMap,color);
167 return oC_ColorMap_IsCorrect(ColorMap) && Position.X < ColorMap->Width && Position.Y < ColorMap->Height;
176 if(oC_ColorMap_IsCorrect(ColorMap) && isram(ColorMap->Map) && isaddresscorrect(Font) && ColorFormat != oC_ColorFormat_Unknown && oC_ColorMap_IsPositionCorrect(ColorMap,Position))
180 if(oC_Font_ReadCharacterMap(Font,C,&characterMap))
182 oC_Pixel_ResolutionUInt_t x = 0;
183 oC_Pixel_ResolutionUInt_t y = 0;
184 uint8_t characterMapBitIndex = 0;
185 uint8_t characterMapByteIndex= 0;
186 uint8_t characterMapByte = characterMap.Data[characterMapByteIndex];
190 for( y = 0 ; y < characterMap.Height && drawed; y++ )
192 drawPosition.Y = Position.Y + y;
194 for( x = 0 ; x < characterMap.Width && drawed; x++ )
196 drawPosition.X = Position.X + x;
199 if(characterMapByte & (1<<characterMapBitIndex))
203 if(oC_ColorMap_IsPositionCorrect(ColorMap,drawPosition))
205 drawed = oC_ColorMap_SetColor(ColorMap,drawPosition,Color,ColorFormat);
210 characterMapBitIndex++;
212 if(characterMapBitIndex == 8)
214 characterMapBitIndex = 0;
215 characterMapByte = characterMap.Data[++characterMapByteIndex];
222 characterMapBitIndex = 0;
223 characterMapByte = characterMap.Data[++characterMapByteIndex];
233 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
identifier for allocations
static const oC_Allocator_t Allocator
#define NULL
pointer to a zero