2011-08-16 2 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)); 
     } 
    } 
} 

出力は(フルサイズで表示してください)です。本質的に、1秒ごとのピクセルが欠落しています。私はあらゆる種類の可能性を試してきましたが、どこが間違っているのか分かりません。

GetPixelおよび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)が4ではなく2ピクセルしか必要としないのか、私が頭に入れているのか分かりません! – Dataflashsabot