ソフトウェア開発 Win32プログラミング

GradientFillの代わり

戻る


Windows 95でGradientFillと同じようなことをやるコードは以下の通り。

#include <windows.h>

static const BYTE g_bayer_x_16_plus_8[] = 
{
      8, 136,  40, 168, 
    200,  72, 232, 104, 
     56, 184,  24, 152, 
    248, 120, 216,  88, 
};

inline BYTE bayer_dithering(INT x, INT y, BYTE b)
{
    if (g_bayer_x_16_plus_8[(y & 3) * 4 + (x & 3)] <= b)
        return 255;
    else
        return 0;
}

BOOL WINAPI GradientFill95(HDC hdc, TRIVERTEX *pTriVertex, ULONG dwNumVertex,
                           VOID *pMesh, ULONG dwNumMesh, ULONG dwMode)
{
    ULONG i;
    BITMAPINFO bi;
    HBITMAP hbm;
    LPBYTE pbBits, pb;
    GRADIENT_RECT *rect;
    GRADIENT_TRIANGLE *tri;
    TRIVERTEX *v1, *v2, *v3;
    COLOR16 r1, g1, b1, a1, r2, g2, b2, a2;
    COLOR16 dr, dg, db, da;
    INT dx, dy, x1, y1, x2;
    INT xMin, yMin, xMax, yMax;
    INT cx, cy, widthbytes;
    HDC hdcMem;
    HGDIOBJ hbmOld;
    BITMAP bm;
    BOOL fDithering;

    if (dwNumVertex == 0 || dwNumMesh == 0)
        return FALSE;

    xMin = xMax = pTriVertex[0].x;
    yMin = yMax = pTriVertex[0].y;
    for(i = 1; i < dwNumVertex; i++)
    {
        if (pTriVertex[i].x < xMin)
            xMin = pTriVertex[i].x;
        else if (xMax < pTriVertex[i].x)
            xMax = pTriVertex[i].x;
        if (pTriVertex[i].y < yMin)
            yMin = pTriVertex[i].y;
        else if (yMax < pTriVertex[i].y)
            yMax = pTriVertex[i].y;
    }
    cx = xMax - xMin;
    cy = yMax - yMin;
    ZeroMemory(&bi.bmiHeader, sizeof(BITMAPINFOHEADER));
    bi.bmiHeader.biSize     = sizeof(BITMAPINFOHEADER);
    bi.bmiHeader.biWidth    = cx;
    bi.bmiHeader.biHeight   = -cy;
    bi.bmiHeader.biPlanes   = 1;
    bi.bmiHeader.biBitCount = 32;
    hbm = CreateDIBSection(NULL, &bi, DIB_RGB_COLORS, (VOID **)&pbBits,
                           NULL, 0);
    if (hbm == NULL)
        return FALSE;

    hdcMem = CreateCompatibleDC(NULL);
    if (hdcMem == NULL)
    {
        DeleteObject(hbm);
        return FALSE;
    }

    if (GetObject(GetCurrentObject(hdc, OBJ_BITMAP), sizeof(BITMAP), &bm))
        fDithering = (bm.bmBitsPixel <= 8);
    else
        fDithering = FALSE;

    widthbytes = cx * 4;

    hbmOld = SelectObject(hdcMem, hbm);
    BitBlt(hdcMem, 0, 0, cx, cy, hdc, xMin, yMin, SRCCOPY);

    switch(dwMode)
    {
    case GRADIENT_FILL_RECT_H:
        for(i = 0; i < dwNumMesh; i++)
        {
            rect = (GRADIENT_RECT *)pMesh + i;
            v1 = pTriVertex + rect->UpperLeft;
            v2 = pTriVertex + rect->LowerRight;
            if (v1->x > v2->x)
                { TRIVERTEX *t = v2; v2 = v1; v1 = t; }
            /* v1->x <= v2->x */
            dx = v2->x - v1->x; dy = v2->y - v1->y;
            r1 = v1->Red;
            g1 = v1->Green;
            b1 = v1->Blue;
            a1 = v1->Alpha;
            if (dx != 0)
            {
                dr = (v2->Red - v1->Red) / dx;
                dg = (v2->Green - v1->Green) / dx;
                db = (v2->Blue - v1->Blue) / dx;
                da = (v2->Alpha - v1->Alpha) / dx;
            }
            if (dy < 0)
            {
                pb = pbBits + (v2->y - yMin) * widthbytes + (v1->x - xMin) * 4;
                dy = -dy;
            }
            else
            {
                pb = pbBits + (v1->y - yMin) * widthbytes + (v1->x - xMin) * 4;
            }
            if (fDithering)
            {
                for(x1 = 0; x1 < dx; x1++)
                {
                    for(y1 = 0; y1 < dy; y1++)
                    {
                        *pb++ = bayer_dithering(x1, y1, b1 >> 8);
                        *pb++ = bayer_dithering(x1, y1, g1 >> 8);
                        *pb++ = bayer_dithering(x1, y1, r1 >> 8);
                        pb++;
                        pb += widthbytes - 4;
                    }
                    r1 += dr;
                    g1 += dg;
                    b1 += db;
                    pb -= dy * widthbytes - 4;
                }
            }
            else
            {
                for(x1 = 0; x1 < dx; x1++)
                {
                    for(y1 = 0; y1 < dy; y1++)
                    {
                        *pb++ = b1 >> 8;
                        *pb++ = g1 >> 8;
                        *pb++ = r1 >> 8;
                        *pb++ = a1 >> 8;
                        pb += widthbytes - 4;
                    }
                    r1 += dr;
                    g1 += dg;
                    b1 += db;
                    a1 += da;
                    pb -= dy * widthbytes - 4;
                }
            }
        }
        break;

    case GRADIENT_FILL_RECT_V:
        for(i = 0; i < dwNumMesh; i++)
        {
            rect = (GRADIENT_RECT *)pMesh + i;
            v1 = pTriVertex + rect->UpperLeft;
            v2 = pTriVertex + rect->LowerRight;
            if (v1->y > v2->y)
                { TRIVERTEX *t = v2; v2 = v1; v1 = t; }
            /* v1->y <= v2->y */
            dx = v2->x - v1->x; dy = v2->y - v1->y;
            r1 = v1->Red;
            g1 = v1->Green;
            b1 = v1->Blue;
            a1 = v1->Alpha;
            if (dy != 0)
            {
                dr = (v2->Red - v1->Red) / dy;
                dg = (v2->Green - v1->Green) / dy;
                db = (v2->Blue - v1->Blue) / dy;
                da = (v2->Alpha - v1->Alpha) / dy;
            }
            if (dx < 0)
            {
                pb = pbBits + (v1->y - yMin) * widthbytes + (v2->x - xMin) * 4;
                dx = -dx;
            }
            else
            {
                pb = pbBits + (v1->y - yMin) * widthbytes + (v1->x - xMin) * 4;
            }
            if (fDithering)
            {
                for(y1 = 0; y1 < dy; y1++)
                {
                    for(x1 = 0; x1 < dx; x1++)
                    {
                        *pb++ = bayer_dithering(x1, y1, b1 >> 8);
                        *pb++ = bayer_dithering(x1, y1, g1 >> 8);
                        *pb++ = bayer_dithering(x1, y1, r1 >> 8);
                        pb++;
                    }
                    r1 += dr;
                    g1 += dg;
                    b1 += db;
                    pb -= dx * 4;
                    pb += widthbytes;
                }
            }
            else
            {
                for(y1 = 0; y1 < dy; y1++)
                {
                    for(x1 = 0; x1 < dx; x1++)
                    {
                        *pb++ = b1 >> 8;
                        *pb++ = g1 >> 8;
                        *pb++ = r1 >> 8;
                        *pb++ = a1 >> 8;
                    }
                    r1 += dr;
                    g1 += dg;
                    b1 += db;
                    a1 += da;
                    pb -= dx * 4;
                    pb += widthbytes;
                }
            }
        }
        break;

    case GRADIENT_FILL_TRIANGLE:
        for(i = 0; i < dwNumMesh; i++)
        {
            tri = (GRADIENT_TRIANGLE *)pMesh + i;
            v1 = pTriVertex + tri->Vertex1;
            v2 = pTriVertex + tri->Vertex2;
            v3 = pTriVertex + tri->Vertex3;

            if (v1->y > v2->y)
                { TRIVERTEX *t = v1; v1 = v2; v2 = t; }
            if (v2->y > v3->y)
            {
                TRIVERTEX *t = v2; v2 = v3; v3 = t;
                if (v1->y > v2->y)
                    { t = v1; v1 = v2; v2 = t; }
            }
            /* v1->y <= v2->y <= v3->y */

            if (fDithering)
            {
                for(y1 = v1->y; y1 < v2->y; y1++)
                {
                    if (v2->x < v3->x)
                    {
                        x1 = v1->x + (v2->x - v1->x) * (y1 - v1->y) / (v2->y - v1->y);
                        r1 = v1->Red   + (v2->Red   - v1->Red)   * (y1 - v1->y) / (v2->y - v1->y);
                        g1 = v1->Green + (v2->Green - v1->Green) * (y1 - v1->y) / (v2->y - v1->y);
                        b1 = v1->Blue  + (v2->Blue  - v1->Blue)  * (y1 - v1->y) / (v2->y - v1->y);
                        x2 = v1->x + (v3->x - v1->x) * (y1 - v1->y) / (v3->y - v1->y);
                        r2 = v1->Red   + (v3->Red   - v1->Red)   * (y1 - v1->y) / (v3->y - v1->y);
                        g2 = v1->Green + (v3->Green - v1->Green) * (y1 - v1->y) / (v3->y - v1->y);
                        b2 = v1->Blue  + (v3->Blue  - v1->Blue)  * (y1 - v1->y) / (v3->y - v1->y);
                        dx = x2 - x1;
                        if (dx != 0)
                        {
                            db = (b2 - b1) / dx;
                            dg = (g2 - g1) / dx;
                            dr = (r2 - r1) / dx;
                        }
                        pb = pbBits + (x1 - xMin) * 4 + (y1 - yMin) * widthbytes;
                        for( ; x1 < x2; x1++)
                        {
                            *pb++ = bayer_dithering(x1, y1, b1 >> 8);
                            *pb++ = bayer_dithering(x1, y1, g1 >> 8);
                            *pb++ = bayer_dithering(x1, y1, r1 >> 8);
                            pb++;
                            b1 += db;
                            g1 += dg;
                            r1 += dr;
                        }
                    }
                    else
                    {
                        x1 = v1->x + (v3->x - v1->x) * (y1 - v1->y) / (v3->y - v1->y);
                        r1 = v1->Red   + (v3->Red   - v1->Red)   * (y1 - v1->y) / (v3->y - v1->y);
                        g1 = v1->Green + (v3->Green - v1->Green) * (y1 - v1->y) / (v3->y - v1->y);
                        b1 = v1->Blue  + (v3->Blue  - v1->Blue)  * (y1 - v1->y) / (v3->y - v1->y);
                        x2 = v1->x + (v2->x - v1->x) * (y1 - v1->y) / (v2->y - v1->y);
                        r2 = v1->Red   + (v2->Red   - v1->Red)   * (y1 - v1->y) / (v2->y - v1->y);
                        g2 = v1->Green + (v2->Green - v1->Green) * (y1 - v1->y) / (v2->y - v1->y);
                        b2 = v1->Blue  + (v2->Blue  - v1->Blue)  * (y1 - v1->y) / (v2->y - v1->y);
                        dx = x2 - x1;
                        if (dx != 0)
                        {
                            db = (b2 - b1) / dx;
                            dg = (g2 - g1) / dx;
                            dr = (r2 - r1) / dx;
                        }
                        pb = pbBits + (x1 - xMin) * 4 + (y1 - yMin) * widthbytes;
                        for( ; x1 < x2; x1++)
                        {
                            *pb++ = bayer_dithering(x1, y1, b1 >> 8);
                            *pb++ = bayer_dithering(x1, y1, g1 >> 8);
                            *pb++ = bayer_dithering(x1, y1, r1 >> 8);
                            pb++;
                            b1 += db;
                            g1 += dg;
                            r1 += dr;
                        }
                    }
                }
                for(y1 = v2->y; y1 < v3->y; y1++)
                {
                    if (v2->x < v3->x)
                    {
                        x1 = v2->x + (v3->x - v2->x) * (y1 - v2->y) / (v3->y - v2->y);
                        r1 = v2->Red   + (v3->Red   - v2->Red)   * (y1 - v2->y) / (v3->y - v2->y);
                        g1 = v2->Green + (v3->Green - v2->Green) * (y1 - v2->y) / (v3->y - v2->y);
                        b1 = v2->Blue  + (v3->Blue  - v2->Blue)  * (y1 - v2->y) / (v3->y - v2->y);
                        x2 = v1->x + (v3->x - v1->x) * (y1 - v1->y) / (v3->y - v1->y);
                        r2 = v1->Red   + (v3->Red   - v1->Red)   * (y1 - v1->y) / (v3->y - v1->y);
                        g2 = v1->Green + (v3->Green - v1->Green) * (y1 - v1->y) / (v3->y - v1->y);
                        b2 = v1->Blue  + (v3->Blue  - v1->Blue)  * (y1 - v1->y) / (v3->y - v1->y);
                        dx = x2 - x1;
                        if (dx != 0)
                        {
                            db = (b2 - b1) / dx;
                            dg = (g2 - g1) / dx;
                            dr = (r2 - r1) / dx;
                        }
                        pb = pbBits + (x1 - xMin) * 4 + (y1 - yMin) * widthbytes;
                        for( ; x1 < x2; x1++)
                        {
                            *pb++ = bayer_dithering(x1, y1, b1 >> 8);
                            *pb++ = bayer_dithering(x1, y1, g1 >> 8);
                            *pb++ = bayer_dithering(x1, y1, r1 >> 8);
                            pb++;
                            b1 += db;
                            g1 += dg;
                            r1 += dr;
                        }
                    }
                    else
                    {
                        x1 = v1->x + (v3->x - v1->x) * (y1 - v1->y) / (v3->y - v1->y);
                        r1 = v1->Red   + (v3->Red   - v1->Red)   * (y1 - v1->y) / (v3->y - v1->y);
                        g1 = v1->Green + (v3->Green - v1->Green) * (y1 - v1->y) / (v3->y - v1->y);
                        b1 = v1->Blue  + (v3->Blue  - v1->Blue)  * (y1 - v1->y) / (v3->y - v1->y);
                        x2 = v2->x + (v3->x - v2->x) * (y1 - v2->y) / (v3->y - v2->y);
                        r2 = v2->Red   + (v3->Red   - v2->Red)   * (y1 - v2->y) / (v3->y - v2->y);
                        g2 = v2->Green + (v3->Green - v2->Green) * (y1 - v2->y) / (v3->y - v2->y);
                        b2 = v2->Blue  + (v3->Blue  - v2->Blue)  * (y1 - v2->y) / (v3->y - v2->y);
                        dx = x2 - x1;
                        if (dx != 0)
                        {
                            db = (b2 - b1) / dx;
                            dg = (g2 - g1) / dx;
                            dr = (r2 - r1) / dx;
                        }
                        pb = pbBits + (x1 - xMin) * 4 + (y1 - yMin) * widthbytes;
                        for( ; x1 < x2; x1++)
                        {
                            *pb++ = bayer_dithering(x1, y1, b1 >> 8);
                            *pb++ = bayer_dithering(x1, y1, g1 >> 8);
                            *pb++ = bayer_dithering(x1, y1, r1 >> 8);
                            pb++;
                            b1 += db;
                            g1 += dg;
                            r1 += dr;
                        }
                    }
                }
            }
            else
            {
                for(y1 = v1->y; y1 < v2->y; y1++)
                {
                    if (v2->x < v3->x)
                    {
                        x1 = v1->x + (v2->x - v1->x) * (y1 - v1->y) / (v2->y - v1->y);
                        r1 = v1->Red   + (v2->Red   - v1->Red)   * (y1 - v1->y) / (v2->y - v1->y);
                        g1 = v1->Green + (v2->Green - v1->Green) * (y1 - v1->y) / (v2->y - v1->y);
                        b1 = v1->Blue  + (v2->Blue  - v1->Blue)  * (y1 - v1->y) / (v2->y - v1->y);
                        a1 = v1->Alpha + (v2->Alpha - v1->Alpha) * (y1 - v1->y) / (v2->y - v1->y);
                        x2 = v1->x + (v3->x - v1->x) * (y1 - v1->y) / (v3->y - v1->y);
                        r2 = v1->Red   + (v3->Red   - v1->Red)   * (y1 - v1->y) / (v3->y - v1->y);
                        g2 = v1->Green + (v3->Green - v1->Green) * (y1 - v1->y) / (v3->y - v1->y);
                        b2 = v1->Blue  + (v3->Blue  - v1->Blue)  * (y1 - v1->y) / (v3->y - v1->y);
                        a2 = v1->Alpha + (v3->Alpha - v1->Alpha) * (y1 - v1->y) / (v3->y - v1->y);
                        dx = x2 - x1;
                        if (dx != 0)
                        {
                            db = (b2 - b1) / dx;
                            dg = (g2 - g1) / dx;
                            dr = (r2 - r1) / dx;
                            da = (a2 - a1) / dx;
                        }
                        pb = pbBits + (x1 - xMin) * 4 + (y1 - yMin) * widthbytes;
                        for( ; x1 < x2; x1++)
                        {
                            *pb++ = b1 >> 8;
                            *pb++ = g1 >> 8;
                            *pb++ = r1 >> 8;
                            *pb++ = a1 >> 8;
                            b1 += db;
                            g1 += dg;
                            r1 += dr;
                            a1 += da;
                        }
                    }
                    else
                    {
                        x1 = v1->x + (v3->x - v1->x) * (y1 - v1->y) / (v3->y - v1->y);
                        r1 = v1->Red   + (v3->Red   - v1->Red)   * (y1 - v1->y) / (v3->y - v1->y);
                        g1 = v1->Green + (v3->Green - v1->Green) * (y1 - v1->y) / (v3->y - v1->y);
                        b1 = v1->Blue  + (v3->Blue  - v1->Blue)  * (y1 - v1->y) / (v3->y - v1->y);
                        a1 = v1->Alpha + (v3->Alpha - v1->Alpha) * (y1 - v1->y) / (v3->y - v1->y);
                        x2 = v1->x + (v2->x - v1->x) * (y1 - v1->y) / (v2->y - v1->y);
                        r2 = v1->Red   + (v2->Red   - v1->Red)   * (y1 - v1->y) / (v2->y - v1->y);
                        g2 = v1->Green + (v2->Green - v1->Green) * (y1 - v1->y) / (v2->y - v1->y);
                        b2 = v1->Blue  + (v2->Blue  - v1->Blue)  * (y1 - v1->y) / (v2->y - v1->y);
                        a2 = v1->Alpha + (v2->Alpha - v1->Alpha) * (y1 - v1->y) / (v2->y - v1->y);
                        dx = x2 - x1;
                        if (dx != 0)
                        {
                            db = (b2 - b1) / dx;
                            dg = (g2 - g1) / dx;
                            dr = (r2 - r1) / dx;
                            da = (a2 - a1) / dx;
                        }
                        pb = pbBits + (x1 - xMin) * 4 + (y1 - yMin) * widthbytes;
                        for( ; x1 < x2; x1++)
                        {
                            *pb++ = b1 >> 8;
                            *pb++ = g1 >> 8;
                            *pb++ = r1 >> 8;
                            *pb++ = a1 >> 8;
                            b1 += db;
                            g1 += dg;
                            r1 += dr;
                            a1 += da;
                        }
                    }
                }
                for(y1 = v2->y; y1 < v3->y; y1++)
                {
                    if (v2->x < v3->x)
                    {
                        x1 = v2->x + (v3->x - v2->x) * (y1 - v2->y) / (v3->y - v2->y);
                        r1 = v2->Red   + (v3->Red   - v2->Red)   * (y1 - v2->y) / (v3->y - v2->y);
                        g1 = v2->Green + (v3->Green - v2->Green) * (y1 - v2->y) / (v3->y - v2->y);
                        b1 = v2->Blue  + (v3->Blue  - v2->Blue)  * (y1 - v2->y) / (v3->y - v2->y);
                        a1 = v2->Alpha + (v3->Alpha - v2->Alpha) * (y1 - v2->y) / (v3->y - v2->y);
                        x2 = v1->x + (v3->x - v1->x) * (y1 - v1->y) / (v3->y - v1->y);
                        r2 = v1->Red   + (v3->Red   - v1->Red)   * (y1 - v1->y) / (v3->y - v1->y);
                        g2 = v1->Green + (v3->Green - v1->Green) * (y1 - v1->y) / (v3->y - v1->y);
                        b2 = v1->Blue  + (v3->Blue  - v1->Blue)  * (y1 - v1->y) / (v3->y - v1->y);
                        a2 = v1->Alpha + (v3->Alpha - v1->Alpha) * (y1 - v1->y) / (v3->y - v1->y);
                        dx = x2 - x1;
                        if (dx != 0)
                        {
                            db = (b2 - b1) / dx;
                            dg = (g2 - g1) / dx;
                            dr = (r2 - r1) / dx;
                            da = (a2 - a1) / dx;
                        }
                        pb = pbBits + (x1 - xMin) * 4 + (y1 - yMin) * widthbytes;
                        for( ; x1 < x2; x1++)
                        {
                            *pb++ = b1 >> 8;
                            *pb++ = g1 >> 8;
                            *pb++ = r1 >> 8;
                            *pb++ = a1 >> 8;
                            b1 += db;
                            g1 += dg;
                            r1 += dr;
                            a1 += da;
                        }
                    }
                    else
                    {
                        x1 = v1->x + (v3->x - v1->x) * (y1 - v1->y) / (v3->y - v1->y);
                        r1 = v1->Red   + (v3->Red   - v1->Red)   * (y1 - v1->y) / (v3->y - v1->y);
                        g1 = v1->Green + (v3->Green - v1->Green) * (y1 - v1->y) / (v3->y - v1->y);
                        b1 = v1->Blue  + (v3->Blue  - v1->Blue)  * (y1 - v1->y) / (v3->y - v1->y);
                        a1 = v1->Alpha + (v3->Alpha - v1->Alpha) * (y1 - v1->y) / (v3->y - v1->y);
                        x2 = v2->x + (v3->x - v2->x) * (y1 - v2->y) / (v3->y - v2->y);
                        r2 = v2->Red   + (v3->Red   - v2->Red)   * (y1 - v2->y) / (v3->y - v2->y);
                        g2 = v2->Green + (v3->Green - v2->Green) * (y1 - v2->y) / (v3->y - v2->y);
                        b2 = v2->Blue  + (v3->Blue  - v2->Blue)  * (y1 - v2->y) / (v3->y - v2->y);
                        a2 = v2->Alpha + (v3->Alpha - v2->Alpha) * (y1 - v2->y) / (v3->y - v2->y);
                        dx = x2 - x1;
                        if (dx != 0)
                        {
                            db = (b2 - b1) / dx;
                            dg = (g2 - g1) / dx;
                            dr = (r2 - r1) / dx;
                            da = (a2 - a1) / dx;
                        }
                        pb = pbBits + (x1 - xMin) * 4 + (y1 - yMin) * widthbytes;
                        for( ; x1 < x2; x1++)
                        {
                            *pb++ = b1 >> 8;
                            *pb++ = g1 >> 8;
                            *pb++ = r1 >> 8;
                            *pb++ = a1 >> 8;
                            b1 += db;
                            g1 += dg;
                            r1 += dr;
                            a1 += da;
                        }
                    }
                }
            }
        }
        break;

    default:
        SelectObject(hdcMem, hbmOld);
        DeleteObject(hbm);
        DeleteDC(hdcMem);
        return FALSE;
    }

    BitBlt(hdc, xMin, yMin, cx, cy, hdcMem, 0, 0, SRCCOPY);
    SelectObject(hdcMem, hbmOld);
    DeleteObject(hbm);
    DeleteDC(hdcMem);
    return TRUE;
}

#ifdef UNITTEST
typedef struct tagBITMAPINFOEX
{
    BITMAPINFOHEADER bmiHeader;
    RGBQUAD          bmiColors[256];
} BITMAPINFOEX, FAR * LPBITMAPINFOEX;

BOOL SaveBitmapToFile(LPCTSTR pszFileName, HBITMAP hbm)
{
    ...
}

#include <stdio.h>

int main(void)
{
    HWND hWnd;
    HDC hDC;
    BITMAPINFOEX bi;
    HBITMAP hbm;
    HGDIOBJ hbmOld;
    LPBYTE pbBits;
    DWORD dw1, dw2;
    TRIVERTEX atv[] = {
        {100,  0, 0xFF00, 0, 0, 0xFF00},
        {0, 150, 0, 0, 0xFF00, 0},
        {200, 200, 0, 0xFF00, 0, 0},
    };
    GRADIENT_TRIANGLE agt[] = {{0, 1, 2}};
    RECT rc = {0, 0, 200, 200};

    ZeroMemory(&bi.bmiHeader, sizeof(BITMAPINFOHEADER));
    bi.bmiHeader.biSize     = sizeof(BITMAPINFOHEADER);
    bi.bmiHeader.biWidth    = 200;
    bi.bmiHeader.biHeight   = 200;
    bi.bmiHeader.biPlanes   = 1;
    bi.bmiHeader.biBitCount = 8;

    hbm = CreateDIBSection(NULL, (BITMAPINFO *)&bi, DIB_RGB_COLORS,
                           (VOID **)&pbBits, NULL, 0);
    hDC = CreateCompatibleDC(NULL);

    hbmOld = SelectObject(hDC, hbm);
    FillRect(hDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
    dw1 = GetTickCount();
    for(int i = 0; i < 10; i++)
        GradientFill95(hDC, atv, 3, agt, 1, GRADIENT_FILL_TRIANGLE);
    dw2 = GetTickCount();
    SelectObject(hDC, hbmOld);
    SaveBitmapToFile("a.bmp", hbm);
    printf("%ld\n", dw2 - dw1);

    hbmOld = SelectObject(hDC, hbm);
    FillRect(hDC, &rc, (HBRUSH)GetStockObject(BLACK_BRUSH));
    dw1 = GetTickCount();
    for(int i = 0; i < 10; i++)
        GradientFill(hDC, atv, 3, agt, 1, GRADIENT_FILL_TRIANGLE);
    dw2 = GetTickCount();
    SelectObject(hDC, hbmOld);
    SaveBitmapToFile("b.bmp", hbm);
    printf("%ld\n", dw2 - dw1);

    DeleteObject(hbm);
    DeleteDC(hDC);
    return 0;
}
#endif  /* def UNITTEST */

実行結果:

ソース: gfill.zip


戻る

©片山博文MZ
katayama.hirofumi.mz@gmail.com

inserted by FC2 system