/** * Read pixels from 565 format. * * \param x x-coordinate of the first pixel * \param y y-coordinate of the first pixel * \param width x-dimension of the pixel rectangle * \param height y-dimension of the pixel rectangle * \param format format of the pixel data * \param type data type of the pixel data * \param pixels pixel data * \param info hardware buffer info */ static void _readpixels565 (GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels, GrLfbInfo_t *info) { const GLint srcStride = info->strideInBytes / 2; const GLushort *src = (const GLushort *)info->lfbPtr + y * srcStride + x; if (format == GL_RGB && type == GL_UNSIGNED_BYTE) { /* convert 5R6G5B into 8R8G8B */ GLint row, col; GLint dstStride = image_stride(&ctx_pack, width, 3); GLubyte *dst = (GLubyte *)image_address(&ctx_pack, pixels, width, height, 3, 0, 0, 0); for (row = 0; row < height; row++) { GLubyte *d = dst; for (col = 0; col < width; col++) { const GLushort pixel = src[col]; GLuint r = (pixel & 0xf800) >> 8; GLuint g = (pixel & 0x07e0) >> 3; GLuint b = (pixel & 0x001f) << 3; *d++ = r | (r >> 5); *d++ = g | (g >> 6); *d++ = b | (b >> 5); } dst += dstStride; src -= srcStride; } } else if (format == GL_RGBA && type == GL_UNSIGNED_BYTE) {
void Dirty::swapImagePixels(Image* image) { RowsList::iterator row_it = m_rows.begin(); RowsList::iterator row_end = m_rows.end(); for (; row_it != row_end; ++row_it) { Row* row = *row_it; ColsList::iterator col_it = (*row_it)->cols.begin(); ColsList::iterator col_end = (*row_it)->cols.end(); for (; col_it != col_end; ++col_it) { Col* col = *col_it; uint8_t* address = (uint8_t*)image_address(image, col->x, row->y); std::swap_ranges(address, address+getLineSize(col->w), col->data.begin()); } } }