2011-08-16 21 views
2

源始終爲320x240,dest始終爲640x480。嘗試SDL_Surface的雙倍大小失敗可怕

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 and SetPixel只需設置/接收表面的顏色,給定X和Y [和顏色]。

+1

如果您將寬度和高度都加倍,則可以將面積乘以4來實現。因此,對於每個源像素,您需要編寫4個目標像素。 – pmg

+0

哦,廢話。確實是的。解決了。抱歉。 – Dataflashsabot

回答

3

用途:

 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(源,X,Y)的商店返回值,所以你不需要調用它每輪4次。

+0

謝謝!我不確定爲什麼我把它放在我的腦海裏,(x * 2)*(y * 2)只需要2個像素而不是4個! – Dataflashsabot