//! fills the surface with given color void CImage::fill(const ColourValue &color) { UINT32 c; switch (Format) { case ECF_A1R5G5B5: c = A8R8G8B8toA1R5G5B5(color.getAsARGB()); c |= c << 16; break; case ECF_R5G6B5: c = A8R8G8B8toR5G6B5(color.getAsARGB()); c |= c << 16; break; case ECF_A8R8G8B8: c = color.getAsARGB(); break; case ECF_R8G8B8: { UINT8 rgb[3]; CColorConverter::convert_A8R8G8B8toR8G8B8(&color, 1, rgb); const UINT32 size = getImageDataSizeInBytes(); for (UINT32 i = 0; i<size; i += 3) { memcpy(Data + i, rgb, 3); } return; } break; default: // TODO: Handle other formats return; } memset32(Data, c, getImageDataSizeInBytes()); }
void Line::_render( Menge::RenderServiceInterface * _renderService, const RenderObjectState * _state ) { const mt::mat4f & wm = this->getWorldMatrix(); mt::vec3f fromWM; mt::mul_v3_v3_m4( fromWM, m_from, wm ); mt::vec3f toWM; mt::mul_v3_v3_m4( toWM, m_to, wm ); mt::vec3f dir; mt::sub_v3_v3( dir, toWM, fromWM ); mt::vec3f dir_norm; mt::norm_v3_v3( dir_norm, dir ); mt::vec2f perp; mt::perp_v2( perp, mt::vec2f(dir_norm.x, dir_norm.y) ); m_vertices[0].position.x = fromWM.x + perp.x * m_width; m_vertices[0].position.y = fromWM.y + perp.y * m_width; m_vertices[0].position.z = fromWM.z; m_vertices[1].position.x = toWM.x + perp.x * m_width; m_vertices[1].position.y = toWM.y + perp.y * m_width; m_vertices[1].position.z = toWM.z; m_vertices[2].position.x = toWM.x - perp.x * m_width; m_vertices[2].position.y = toWM.y - perp.y * m_width; m_vertices[2].position.z = toWM.z; m_vertices[3].position.x = fromWM.x - perp.x * m_width; m_vertices[3].position.y = fromWM.y - perp.y * m_width; m_vertices[3].position.z = fromWM.z; ColourValue color; this->calcTotalColor(color); uint32_t argb = color.getAsARGB(); for( uint32_t i = 0; i != 4; ++i ) { m_vertices[i].color = argb; m_vertices[i].uv[0].x = 0.f; m_vertices[i].uv[0].y = 0.f; m_vertices[i].uv[1].x = 0.f; m_vertices[i].uv[1].y = 0.f; } RenderMaterialInterfacePtr material = RENDERMATERIAL_SERVICE(m_serviceProvider) ->getMaterial( STRINGIZE_STRING_LOCAL( m_serviceProvider, "Debug" ), PT_TRIANGLELIST, 0, nullptr ); _renderService ->addRenderQuad( _state, material, m_vertices, 4, nullptr, false ); }
//! sets a pixel void CImage::setPixel(UINT32 x, UINT32 y, const ColourValue &color, bool blend) { ColourValue c = color; if (x >= Size.Width || y >= Size.Height) return; switch (Format) { case ECF_A1R5G5B5: { UINT16 * dest = (UINT16*)(Data + (y * Pitch) + (x << 1)); *dest = A8R8G8B8toA1R5G5B5(color.getAsARGB()); } break; case ECF_R5G6B5: { UINT16 * dest = (UINT16*)(Data + (y * Pitch) + (x << 1)); *dest = A8R8G8B8toR5G6B5(color.getAsARGB()); } break; case ECF_R8G8B8: { UINT8* dest = Data + (y * Pitch) + (x * 3); dest[0] = (UINT8)c.getRed(); dest[1] = (UINT8)c.getGreen(); dest[2] = (UINT8)c.getBlue(); } break; case ECF_A8R8G8B8: { UINT32 * dest = (UINT32*)(Data + (y * Pitch) + (x << 2)); *dest = blend ? PixelBlend32(*dest, color.getAsARGB()) : color.getAsARGB(); } break; #ifndef _DEBUG default: break; #endif } }
//! copies this surface into another, using the alpha mask, a cliprect and a color to add with void CImage::copyToWithAlpha(IImage* target, const Vector2& pos, const rect<SINT32>& sourceRect, const ColourValue &color, const rect<SINT32>* clipRect) { // color blend only necessary on not full spectrum aka. color.color != 0xFFFFFFFF Blit(color.getAsARGB() == 0xFFFFFFFF ? BLITTER_TEXTURE_ALPHA_BLEND : BLITTER_TEXTURE_ALPHA_COLOR_BLEND, target, clipRect, &pos, this, &sourceRect, color.getAsARGB()); }