簡體   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