1

画像のサイズ変更には多くのアルゴリズムがあります- lancorz、bicubic、bilinear など。

私が必要としているのは、許容できる品質で画像のサイズを変更するための高速で比較的単純な C++ コードです。

これが私が現在行っていることの例です:

for (int y = 0; y < height; y ++)
{
    int         srcY1Coord = int((double)(y * srcHeight) / height);
    int         srcY2Coord = min(srcHeight - 1, max(srcY1Coord, int((double)((y + 1) * srcHeight) / height) - 1));

    for (int x = 0; x < width; x ++)
    {
        int     srcX1Coord = int((double)(x * srcWidth) / width);
        int     srcX2Coord = min(srcWidth - 1, max(srcX1Coord, int((double)((x + 1) * srcWidth) / width) - 1));
        int     srcPixelsCount = (srcX2Coord - srcX1Coord + 1) * (srcY2Coord - srcY1Coord + 1);
        RGB32       color32;
        UINT32      r(0), g(0), b(0), a(0);

        for (int xSrc = srcX1Coord; xSrc <= srcX2Coord; xSrc ++)
            for (int ySrc = srcY1Coord; ySrc <= srcY2Coord; ySrc ++)
            {
                RGB32   curSrcColor32 = pSrcDIB->GetDIBPixel(xSrc, ySrc);
                r += curSrcColor32.r; g += curSrcColor32.g; b += curSrcColor32.b; a += curSrcColor32.alpha;
            }

            color32.r = BYTE(r / srcPixelsCount); color32.g = BYTE(g / srcPixelsCount); color32.b = BYTE(b / srcPixelsCount); color32.alpha = BYTE(a / srcPixelsCount);

            SetDIBPixel(x, y, color32);
    }
}

上記のコードは十分に高速ですが、画像を拡大すると品質が良くありません。

したがって、誰かがDIB をスケーリングするための高速で優れた C++ コード サンプルを既に持っているのではないでしょうか?

注:以前はStretchDIBitsを使用していました。10000x10000 の画像を 100x100 のサイズに縮小する必要があると、非常に遅くなりました。私のコードははるかに高速です。もう少し高品質にしたいだけです。

PS 私は独自の SetPixel/GetPixel 関数を使用して、データ配列を直接操作して高速に処理しています。これはデバイス コンテキストではありません。

4

3 に答える 3

3

なんでCPUでやるの?GDI を使用すると、ハードウェア アクセラレーションの可能性が高くなります。StretchBltSetStretchBltModeを使用します。

擬似コード:

 create source dc and destination dc using CreateCompatibleDC
 create source and destination bitmaps
 SelectObject source bitmap into source DC and dest bitmap into dest DC
 SetStretchBltMode
 StretchBlt
 release DCs
于 2011-11-01T14:37:38.273 に答える
1

繰り返しますが、なぜCPUで行うのですか?OpenGL / DirectX とフラグメント シェーダーを使用しないのはなぜですか? 擬似コード:

upload source texture (cache it if it's to be reused)
create destination texture
use shader program
render quad
download output texture

shader program使用しているフィルタリング方法はどこにありますか。GPU は、CPU/GetPixel/SetPixel よりもピクセルの処理に優れています。

ウェブ上でさまざまなフィルタリング方法のフラグメント シェーダーを見つけることができるでしょう。GPU Gems は、開始するのに適した場所です。

于 2011-11-01T14:59:00.487 に答える