src/leptwin.c
HBITMAP
pixGetWindowsHBITMAP(PIX  *pix)
{
l_int32    width, height, depth;
l_uint32  *data;
HBITMAP    hBitmap = NULL;
BITMAP     bm;
DWORD      imageBitsSize;
PIX       *pixt = NULL;
PIXCMAP   *cmap;

    PROCNAME("pixGetWindowsHBITMAP");
    if (!pix)
        return (HBITMAP)ERROR_PTR("pix not defined", procName, NULL);

    pixGetDimensions(pix, &width, &height, &depth);
    cmap = pixGetColormap(pix);
    
    if (depth == 24) depth = 32;
    if (depth == 2) {
        pixt = pixConvert2To8(pix, 0, 85, 170, 255, TRUE);
        if (!pixt)
            return (HBITMAP)ERROR_PTR("unable to convert pix from 2bpp to 8bpp",
                    procName, NULL);
        depth = pixGetDepth(pixt);
        cmap = pixGetColormap(pixt);
    }

    if (depth < 16) {
        if (!cmap)
            cmap = pixcmapCreateLinear(depth, 1<<depth);
    }

    hBitmap = DSCreateDIBSection(width, height, depth, cmap);
    if (!hBitmap)
        return (HBITMAP)ERROR_PTR("Unable to create HBITMAP", procName, NULL);

        /* By default, Windows assumes bottom up images */
    if (pixt)
        pixt = pixFlipTB(pixt, pixt); 
    else
        pixt = pixFlipTB(NULL, pix);

        /* "standard" color table assumes bit off=black */
    if (depth == 1) {
        pixInvert(pixt, pixt);
    }

        /* Don't byte swap until done manipulating pix! */
    if (depth <= 16)
        pixEndianByteSwap(pixt);

    GetObject (hBitmap, sizeof(BITMAP), &bm);
    imageBitsSize = ImageBitsSize(hBitmap);
    data = pixGetData(pixt);
    if (data) {
        memcpy (bm.bmBits, data, imageBitsSize);
    } else {
        DeleteObject (hBitmap);
        hBitmap = NULL;
    }
    pixDestroy(&pixt);

    return hBitmap;
}
/*!
 *  pixGetWindowsHBITMAP()
 *
 *      Input:  pix
 *      Return: Windows hBitmap, or null on error
 *
 *  Notes:
 *      (1) It's the responsibility of the caller to destroy the
 *          returned hBitmap with a call to DeleteObject (or with
 *          something that eventually calls DeleteObject).
 */
pixGetWindowsHBITMAP()
Input:  pix
Return: Windows hBitmap, or null on error

(1) It's the responsibility of the caller to destroy the
returned hBitmap with a call to DeleteObject (or with
something that eventually calls DeleteObject).
pixGetWindowsHBITMAP () Input : pix Return : Windows hBitmap or null on error ( 1 ) It ' s the responsibility of the caller to destroy the returned hBitmap with a call to DeleteObject ( or with something that eventually calls DeleteObject ) .
HBITMAP
pixGetWindowsHBITMAP(PIX  *pix)
{
l_int32    width, height, depth;
l_uint32  *data;
HBITMAP    hBitmap = NULL;
BITMAP     bm;
DWORD      imageBitsSize;
PIX       *pixt = NULL;
PIXCMAP   *cmap;
    PROCNAME("pixGetWindowsHBITMAP");
    if (!pix)
        return (HBITMAP)ERROR_PTR("pix not defined", procName, NULL);
    pixGetDimensions(pix, &width, &height, &depth);
    cmap = pixGetColormap(pix);
    if (depth == 24) depth = 32;
    if (depth == 2) {
        pixt = pixConvert2To8(pix, 0, 85, 170, 255, TRUE);
        if (!pixt)
            return (HBITMAP)ERROR_PTR("unable to convert pix from 2bpp to 8bpp",
                    procName, NULL);
        depth = pixGetDepth(pixt);
        cmap = pixGetColormap(pixt);
    }
    if (depth < 16) {
        if (!cmap)
            cmap = pixcmapCreateLinear(depth, 1<<depth);
    }
    hBitmap = DSCreateDIBSection(width, height, depth, cmap);
    if (!hBitmap)
        return (HBITMAP)ERROR_PTR("Unable to create HBITMAP", procName, NULL);
    if (pixt)
        pixt = pixFlipTB(pixt, pixt); 
    else
        pixt = pixFlipTB(NULL, pix);
    if (depth == 1) {
        pixInvert(pixt, pixt);
    }
    if (depth <= 16)
        pixEndianByteSwap(pixt);
    GetObject (hBitmap, sizeof(BITMAP), &bm);
    imageBitsSize = ImageBitsSize(hBitmap);
    data = pixGetData(pixt);
    if (data) {
        memcpy (bm.bmBits, data, imageBitsSize);
    } else {
        DeleteObject (hBitmap);
        hBitmap = NULL;
    }
    pixDestroy(&pixt);
    return hBitmap;
}
HBITMAP pixGetWindowsHBITMAP ( PIX * pix ) { l_int32 width , height , depth ; l_uint32 * data ; HBITMAP hBitmap = NULL ; BITMAP bm ; DWORD imageBitsSize ; PIX * pixt = NULL ; PIXCMAP * cmap ; PROCNAME ( " " ) ; if ( ! pix ) return ( HBITMAP ) ERROR_PTR ( " " , procName , NULL ) ; pixGetDimensions ( pix , & width , & height , & depth ) ; cmap = pixGetColormap ( pix ) ; if ( depth == 24 ) depth = 32 ; if ( depth == 2 ) { pixt = pixConvert2To8 ( pix , 0 , 85 , 170 , 255 , TRUE ) ; if ( ! pixt ) return ( HBITMAP ) ERROR_PTR ( " " , procName , NULL ) ; depth = pixGetDepth ( pixt ) ; cmap = pixGetColormap ( pixt ) ; } if ( depth < 16 ) { if ( ! cmap ) cmap = pixcmapCreateLinear ( depth , 1 << depth ) ; } hBitmap = DSCreateDIBSection ( width , height , depth , cmap ) ; if ( ! hBitmap ) return ( HBITMAP ) ERROR_PTR ( " " , procName , NULL ) ; if ( pixt ) pixt = pixFlipTB ( pixt , pixt ) ; else pixt = pixFlipTB ( NULL , pix ) ; if ( depth == 1 ) { pixInvert ( pixt , pixt ) ; } if ( depth <= 16 ) pixEndianByteSwap ( pixt ) ; GetObject ( hBitmap , sizeof ( BITMAP ) , & bm ) ; imageBitsSize = ImageBitsSize ( hBitmap ) ; data = pixGetData ( pixt ) ; if ( data ) { memcpy ( bm . bmBits , data , imageBitsSize ) ; } else { DeleteObject ( hBitmap ) ; hBitmap = NULL ; } pixDestroy ( & pixt ) ; return hBitmap ; }
pixGetWindowsHBITMAP()
      Input:  pix
      Return: Windows hBitmap, or null on error
pixGetWindowsHBITMAP () Input : pix Return : Windows hBitmap or null on error
/* By default, Windows assumes bottom up images */ /* "standard" color table assumes bit off=black */ /* Don't byte swap until done manipulating pix! */