void RawBitmapUtil::Swizzle(uint8_t* pDst, const RawBitmap& src, const int dstIdx0, const int dstIdx1, const int dstIdx2, const int dstIdx3) { assert( pDst != nullptr ); assert( src.IsValid() ); assert( dstIdx0 != dstIdx1 ); assert( dstIdx0 != dstIdx2 ); assert( dstIdx0 != dstIdx3 ); assert( dstIdx1 != dstIdx2 ); assert( dstIdx1 != dstIdx3 ); assert( dstIdx2 != dstIdx3 ); const uint8_t*const pSrc = src.pContent; const int srcWidth = src.Width; const int srcHeight = src.Height; const int srcStride = src.Stride; int offset = 0; for( int y=0; y<srcHeight; ++y ) { for( int x=0; x<srcWidth; ++x ) { const uint8_t b0 = pSrc[offset+(x * 4)+0]; const uint8_t b1 = pSrc[offset+(x * 4)+1]; const uint8_t b2 = pSrc[offset+(x * 4)+2]; const uint8_t b3 = pSrc[offset+(x * 4)+3]; pDst[offset+(x * 4)+dstIdx0] = b0; pDst[offset+(x * 4)+dstIdx1] = b1; pDst[offset+(x * 4)+dstIdx2] = b2; pDst[offset+(x * 4)+dstIdx3] = b3; } offset += srcStride; } }
void RawBitmapUtil::Swizzle(std::vector<uint8_t>& rDst, const RawBitmap& src, const int dstIdx0, const int dstIdx1, const int dstIdx2, const int dstIdx3) { assert(src.GetBytesPerPixel() == 4); rDst.resize(src.Width * src.Height * 4); Swizzle(&rDst[0], src, dstIdx0, dstIdx1, dstIdx2, dstIdx3); }
void DrawGeoBitmap(const RawBitmap &bitmap, PixelSize bitmap_size, const GeoBounds &bounds, const Projection &projection) { assert(bounds.IsValid()); const BulkPixelPoint vertices[] = { projection.GeoToScreen(bounds.GetNorthWest()), projection.GeoToScreen(bounds.GetNorthEast()), projection.GeoToScreen(bounds.GetSouthWest()), projection.GeoToScreen(bounds.GetSouthEast()), }; const ScopeVertexPointer vp(vertices); const GLTexture &texture = bitmap.BindAndGetTexture(); const PixelSize allocated = texture.GetAllocatedSize(); const GLfloat src_x = 0, src_y = 0, src_width = bitmap_size.cx, src_height = bitmap_size.cy; GLfloat x0 = src_x / allocated.cx; GLfloat y0 = src_y / allocated.cy; GLfloat x1 = (src_x + src_width) / allocated.cx; GLfloat y1 = (src_y + src_height) / allocated.cy; const GLfloat coord[] = { x0, y0, x1, y0, x0, y1, x1, y1, }; #ifdef USE_GLSL OpenGL::texture_shader->Use(); glEnableVertexAttribArray(OpenGL::Attribute::TEXCOORD); glVertexAttribPointer(OpenGL::Attribute::TEXCOORD, 2, GL_FLOAT, GL_FALSE, 0, coord); #else const GLEnable<GL_TEXTURE_2D> scope; OpenGL::glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, coord); #endif glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); #ifdef USE_GLSL glDisableVertexAttribArray(OpenGL::Attribute::TEXCOORD); OpenGL::solid_shader->Use(); #else glDisableClientState(GL_TEXTURE_COORD_ARRAY); #endif }
void RawBitmapUtil::Copy(RawBitmapEx& dstBitmap, const Point2& dstPos, const RawBitmap& srcBitmap, const Rectangle*const pSrcRect) { assert(dstBitmap.IsValid()); assert(dstPos.X >= 0); assert(dstPos.Y >= 0); assert(srcBitmap.IsValid()); const Rectangle srcRect = (pSrcRect != nullptr ? *pSrcRect : Rectangle(0, 0, srcBitmap.Width, srcBitmap.Height)); assert(srcRect.X() >= 0); assert(srcRect.Y() >= 0); assert(srcRect.Width() >= 0 && srcRect.Width() <= srcBitmap.Width); assert(srcRect.Height() >= 0 && srcRect.Height() <= srcBitmap.Height); // Validate that the rect fit on the target bitmap assert((dstPos.X + srcRect.Width()) <= dstBitmap.Width); assert((dstPos.Y + srcRect.Height()) <= dstBitmap.Height); assert(dstBitmap.GetBytesPerPixel() == srcBitmap.GetBytesPerPixel()); const int numBytesPerPixel = dstBitmap.GetBytesPerPixel(); const int srcStride = srcBitmap.Stride; const uint8_t* pSrc = srcBitmap.pContent + (srcStride * srcRect.Y()) + (numBytesPerPixel*srcRect.X()); const uint8_t*const pSrcEnd = pSrc + (srcStride * srcRect.Height()); const int numBytes = srcRect.Width() * numBytesPerPixel; const int dstStride = dstBitmap.Stride; uint8_t* pDst = dstBitmap.pContent + (dstStride * dstPos.Y) + (numBytesPerPixel * dstPos.X); while( pSrc < pSrcEnd ) { for( int x=0; x<numBytes; ++x ) { pDst[x] = pSrc[x]; } pSrc += srcStride; pDst += dstStride; } }
const GLTexture &BindAndGetTexture() const { return image->BindAndGetTexture(); }