SDL2_ttf亚像素抗锯齿

时间:2019-06-18 09:53:33

标签: c++ sdl-2 antialiasing sdl-ttf

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

以下图像恰好演示了我的目标,最左边的图像是放大后会看到的实际结果:

subpixel rendering example

如果“开箱即用”是不可能的,但是您认为可以在开源SDL2_ttf中实现 ;我希望在正确的方向上提出一些想法或指示,以实现该目标。


编辑:

我已经开始浏览source code of 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...

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

1 个答案:

答案 0 :(得分:0)

SDL2_ttf最好的方法是在Shaded and Blended模式下进行灰度抗锯齿。

要获得亚像素渲染,您必须drop back to FreeType

a recent HG commit中引入的新提示设置 <?php use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; global $value; $value="100"; function mail(){ require 'PHPMailer/src/Exception.php'; require 'PHPMailer/src/PHPMailer.php'; require 'PHPMailer/src/SMTP.php'; global $message; global $toAddress; $toAddress = "xxxx@gmail.com"; //To whom you are sending the mail. $messages = <<<EOT <html> <body> Your value is <br> <h1 align="center"> </body> </html> EOT; $mail = new PHPMailer(); $mail->IsSMTP(); $mail->SMTPAuth = true; $mail->Host = "mail.xxx.com"; $mail->Port = 587; $mail->SMTPOptions = array( 'ssl' => array( 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ) ); $message = $messages.$value.'</h1>'; $mail->IsHTML(true); $mail->Username = "xxx@xxx.com"; // your gmail address $mail->Password = "xxxxxxx"; // password $mail->SetFrom("xxxxx@xxxx.com"); $mail->Subject = "Try "; // Mail subject $mail->Body = $message; $mail->Address($toAddress); } ?> 看起来将为您提供灰度子像素定位(向下映射到FreeType's FT_LOAD_TARGET_LIGHT)。