作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将 AVSubtitle 中的 DVBSub 数据转换为 RGB 格式,但它似乎不起作用。我只是得到随机的颜色。
这是代码:
/* rects comes from AVSubtitleRect type elsewhere*/
int bw = rects[0].w;
int bh = rects[0].h;
uint32_t colour;
uint32_t *bitmap;
int r, g, b;
/* Give it some memory */
bitmap = malloc(bw * bh * sizeof(uint32_t));
for (int y = 0; y < bh; y++)
{
for (int x = 0; x < bw; x++)
{
/* data[0] holds index data */
const uint8_t index = rects[0]->data[0][y * bw + x];
/* data[1] holds colours - get colour from index */
colour = rects[0]->data[1][4 * index];
r = (colour >> 16) & 0xFF;
g = (colour >> 8) & 0xFF;
b = (colour >> 0) & 0xFF;
/* construct bitmap pixel by pixel (24 bit RGB) */
bitmap[y * bw + x] = r << 16 | g << 8 | b;
}
}
最佳答案
DVBSub 矩形使用索引颜色位图。每个像素使用 2、16 或 256 种颜色。
话虽如此,这些矩形几乎总是使用 16(4 位)索引颜色格式。
然而,单个像素需要整个 8 位(4 位 + 4 位零)。
CLUT(颜色查找表)使用完整的 32 位 ARGB 格式(是的,使用 Alpha channel 实现透明度)。所以对于 16 色格式,CLUT 大小为 64 字节(16*4)。
希望这些有所帮助。
关于c - AVSubtitleRect DVBSub格式解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60551861/
我是一名优秀的程序员,十分优秀!