尝试将 SDL_Surface 的大小加倍严重失败
源始终为 320x240,目标始终为 640x480。
void DoDoubleScaling(SDL_Surface* dest, SDL_Surface* source)
{
assert(dest->w == source->w*2);
assert(dest->h == source->h*2);
for (int y = 0; y < source->h; ++y)
{
for (int x = 0; x < source->w; ++x)
{
SetPixel(dest, x*2, y*2, GetPixel(source, x, y));
SetPixel(dest, x*2+1, y*2+1, GetPixel(source, x, y));
}
}
}
输出如下所示: (请务必以全尺寸查看)。本质上,每隔一个像素都会丢失。我已经尝试了各种可能性,但我找不到哪里出错了。
GetPixel
和SetPixel
只需在给定X和Y[和颜色]的情况下设置/接收表面的颜色。
source is always 320x240, dest is always 640x480.
void DoDoubleScaling(SDL_Surface* dest, SDL_Surface* source)
{
assert(dest->w == source->w*2);
assert(dest->h == source->h*2);
for (int y = 0; y < source->h; ++y)
{
for (int x = 0; x < source->w; ++x)
{
SetPixel(dest, x*2, y*2, GetPixel(source, x, y));
SetPixel(dest, x*2+1, y*2+1, GetPixel(source, x, y));
}
}
}
The output looks like this: (be sure to view at full size). Essentially, every second pixel is missing. I've tried all sorts of possibilities and I can't find where I'm going wrong.
GetPixel
and SetPixel
simply set/recieve a surface's colour, given an X and Y [and color].
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用:
代替:
并且为了加速: 存储 GetPixel(source, x, y) 的返回值,因此您不需要每轮调用它 4 次。
Use:
Instead of:
And for speed up: Store return value of GetPixel(source, x, y), so you don't need to call it 4 times per each round.