算法缩减位图字体 [英] Algorithms for downscaling bitmapped fonts

查看:110
本文介绍了算法缩减位图字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个后续这个问题

我的工作在低C级应用程序,在那里我有绘制文本。我决定来存储我想用一个数组(黑色和白色,每一个字符128x256,也许),那么我就降尺度到我需要一些算法(如灰度大小的字体,这样我就可以有一些粗制字体平滑)。

I am working on a low level C app where I have to draw text. I have decided to store the font I want to use as an array (black and white, each char 128x256, perhaps), then I'd downscale it to the sizes I need with some algorithm (as grayscale, so I can have some crude font smoothing).

注:这是一个玩具项目,请忽略的东西,如做计算在运行与否

Note: this is a toy project, please disregard stuff like doing calculations at runtime or not.

问题是,哪种算法?

我抬头一看 2xSaI ,但它是相当复杂的。我喜欢的东西我可以阅读说明,并制定出code自己(我是初学者,并已编码的C / C ++略低于一年)。

I looked up 2xSaI, but it's rather complicated. I'd like something I can read the description for and work out the code myself (I am a beginner and have been coding in C/C++ for just under a year).

建议,任何人吗?

感谢您的时间!

编辑:请注意,输入的是B和W,输出应进行平滑的灰度

Please note, the input is B&W, the output should be smoothed grayscale

推荐答案

找出源图像中的矩形,将对应于目标像素。例如,如果你的源图像是50×,你的目标是20x40,在目的地的左上像素对应于从(0,0)的源图像的矩形(2.2,2.2)。现在,做一个面积均超过那些像素:

Figure out the rectangle in the source image that will correspond to a destination pixel. For example if your source image is 50x100 and your destination is 20x40, the upper left pixel in the destination corresponds to the rectangle from (0,0) to (2.2,2.2) in the source image. Now, do an area-average over those pixels:

  • 在面积为2.2 * 2.2 = 4.84。你会用1 / 4.84缩放结果。
  • 像素(0,0),(0,1),(1,0),(1,1),每个重量在1个单位。
  • 像素处(0,2),(1,2),(2,0),和(2,1)每重量在0.2单元(因为矩形仅覆盖其中的20%)。
  • 在像素(2,2)的重量在0.04(因为矩形只包括它的4%)。
  • 的总重量是当然4 * 1 + 4 * 0.2 + 0.04 = 4.84的

因为你开始排队均匀地在图像边缘的源和目标像素这一个是容易的。在一般情况下,你将有部分覆盖在所有的四侧/ 4角滑动矩形的。

This one was easy because you started with source and destination pixels lined up evenly at the edge of the image. In general, you'll have partial coverage at all 4 sides/4 corners of the sliding rectangle.

不要算法比区域平均的降尺度等麻烦。他们中的大多数是普通的错误的(它们会导致可怕的混淆,至少有一个系数小于1/2),和那些不完全错误的是更痛苦的一个好一点的实现,可能不会给你更好的结果。

Don't bother with algorithms other than area-averaging for downscaling. Most of them are plain wrong (they result in horrible aliasing, at least with a factor smaller than 1/2) and the ones that aren't plain wrong are a good bit more painful to implement and probably won't give you better results.

这篇关于算法缩减位图字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆