是任何转换8bpp bitmap
到32bpp bitmap
的方法,基本上我想转换单色bitmap
到彩色bitmap
,单色bitmap
有8bpp
我想把它带到32bpp bitmap
,谷歌的大多数问题是从向上到向下转换。
发布于 2019-09-13 14:46:28
8bpp通常表示您有一个颜色映射表,像素颜色值是该映射表的索引。
32bpp通常是RGBA或ARGB,具有单独的红、绿和蓝(和Alpha)分量。
要将索引的颜色表图像转换为RGB图像,只需用颜色表中相应的RGB值替换8bpp图像中的所有像素。
为了回应Mark Setchell的评论,处理8位灰度值几乎更简单:从原始图像中提取像素值,并将其用于所有R、G和B。
例如,如果原始像素值为0x37
,则R、G和B中的每一个也变为0x37
(即,对于ARGB为0x00373737
,对于RGBA为0x37373700
)。
发布于 2019-09-13 18:19:07
这是基于Mark Setchell的注释("P,P,P+ 255")的一些代码。(这是未经测试的,对不起-我可能会有一些“off-by-one”错误,但我只是想让你了解一下它是什么样子的):
/// NB this will allocate memory, where you put the
/// malloc depends on your context. But you do need one somewhere.
/// pImgOut is the resulting 32 bits-per-pixel image.
/// width and height are the width and height of original 8bit pixmap.
void make8bppTo32bpp(uint8_t* pPixmapIn, uint8_t** pImgOut, int width, int height)
{
*pImgOut = (uint8_t*)malloc((width*height)*4); //32 bits per pixel == 4 bytes per pixel
uint8_t* pSrc = pPixmapIn;
uint8_t* pDst = *pImgOut;
for(int y = 0; y < height; y++)
{
for(int x = 0; x < width; x++)
{
// assign R,G,B of dest all to be the same cur pix val of src.
uint8_t pixval = *pSrc;
*pDst++ = pixval;
*pDst++ = pixval;
*pDst++ = pixval;
*pDst++ = 255; // make alpha channel fully opaque
// next src pixel
pSrc++;
}
}
}
https://stackoverflow.com/questions/57918523
复制相似问题