c - 尝试将 SDL_Surface 的大小加倍严重失败

标签 c resize sdl interpolation

源始终为 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));
        }
    }
}

输出如下所示: (请务必以全尺寸查看)。本质上,每隔一个像素都会丢失。我尝试了各种可能性,但找不到哪里出错了。

GetPixelSetPixel只需在给定X和Y[和颜色]的情况下设置/接收表面的颜色。

最佳答案

用途:

        SetPixel(dest, x*2, y*2, GetPixel(source, x, y));
        SetPixel(dest, x*2, y*2+1, GetPixel(source, x, y));
        SetPixel(dest, x*2+1, y*2, GetPixel(source, x, y));
        SetPixel(dest, x*2+1, y*2+1, GetPixel(source, x, y));

而不是:

        SetPixel(dest, x*2, y*2, GetPixel(source, x, y));
        SetPixel(dest, x*2+1, y*2+1, GetPixel(source, x, y));

为了加快速度:存储 GetPixel(source, x, y) 的返回值,因此您不需要每轮调用它 4 次。

关于c - 尝试将 SDL_Surface 的大小加倍严重失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7076665/

相关文章:

c - 使用 KEY 的 Openssl/libcrypto AES 128 编码

c - (C) 将std in解析成链表,无限循环

java - setPreferredSize() 在我的 JButton 中不起作用

css - 无法控制 Div 在 Div 中的大小/位置

c - SDL 2.0 : How to get the HWND from SDL_SysWMinfo

sdl - fatal error : EGL/egl. h:没有这样的文件或目录

c - 在函数中使用 const 修饰符

c - 如何跳过 GDB 中循环的多次迭代?

body 的动态调整大小(LibGDX)

c++ - SDL_BlitSurface 不起作用 - 我在我的表面上看不到图像