繁体   English   中英

SDL2_ttf子像素抗锯齿

[英]SDL2_ttf Subpixel Antialiasing

是否可以使用子像素渲染技术使用SDL2库渲染文本以​​提高LCD屏幕的质量? (最好使用标准SDL2_ttf。)

下图显示了我的目标,最左边的图像是放大时可以看到的实际结果:

子像素渲染示例

如果这不可能“开箱即用”,但您认为可以在开源SDL2_ttf中实现; 我很欣赏一些关于如何实施的想法或指示。


编辑:

我已经开始查看SDL2_ttf源代码 ,并得出结论,为了实现亚像素LCD抗锯齿,我必须对其进行修改。

根据我对FreeType的研究,我将不得不更改以下代码行:

// (from SDL_ttf.c, approx. line 650)
/* Render the glyph */
error = FT_Render_Glyph(glyph, mono ? ft_render_mode_mono : ft_render_mode_normal);

/* Render the glyph, (ft_render_mode_mono is also deprecated) */
error = FT_Render_Glyph(glyph, mono ? FT_RENDER_MODE_MONO : FT_RENDER_MODE_LCD);

此外,需要添加一些代码来写入位图。 由于缺乏评论,我完全不知道如何做到这一点,因为我几乎不了解已有的内容。 以下是'灰色2位'像素模式的代码:

// (from SDL_ttf.c, approx. line 800)
// ... other pixel modes handled above this...
else if (src->pixel_mode == FT_PIXEL_MODE_GRAY2) {
    // srcp appears to be the source buffer, 
    // and dstp the destination buffer.
    unsigned char *srcp = src->buffer + soffset;
    unsigned char *dstp = dst->buffer + doffset;
    unsigned char c;
    unsigned int j, k;

    // No idea how any of this works.
    // I'd guess 'j' should increment by 1
    // instead of 4, since LCD uses 8-bits.
    for (j = 0; j < src->width; j += 4) {
        c = *srcp++;
        for (k = 0; k < 4; ++k) 
        {
            // Literally no idea where they pulled these numbers out.
            if ((c&0xA0) >> 6) {
                *dstp++ = NUM_GRAYS * ((c&0xA0) >> 6) / 3 - 1;
            } 
            else {
                *dstp++ = 0x00;
            }
        }
        c <<= 2;
    }
}
// 4-bit grey is done down here...

我希望有人能够帮助我解决这个问题......
干杯。

SDL2_ttf可以做的最好的是着色和混合模式下的灰度抗锯齿。

要获得子像素渲染,您必须回退到FreeType

最近的HG提交中引入的新的hinter设置TTF_HINTING_LIGHT_SUBPIXEL看起来会给你灰度子像素定位(它映射到FreeType的FT_LOAD_TARGET_LIGHT )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM