⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 icon.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
        h = &bm->bmiHeader;
        // h->biHeight /= 2;            /* code gen bug */
        if( res->height != 0 ) {
            h->biHeight = res->height;  /* they have height * 2 in this field */
        } else {
            height = h->biHeight;
            height = height / 2;
            h->biHeight = height;
        }
        h->biSizeImage =
            BITS_INTO_BYTES( h->biWidth * h->biBitCount, h->biHeight );
        img->xor_size = h->biSizeImage;
        img->and_size = BITS_INTO_BYTES( h->biWidth, h->biHeight );
        original_and_size = img->and_size;   /* save the sizes for later */
        original_xor_size = img->xor_size;

        /*
         * JPK - for 16x16, 24x24 & 48x48 icons, need to adjust sizes so
         *       they are multiples of 32
        */
        if (img_file->type == ICON_FILE_TYPE) {
            /* 16x16 - double AND size, and XOR size if monochrome */
            if (h->biWidth == 16 && h->biHeight == 16) {
                img->and_size *= 2;
                if (h->biBitCount == 1)
                    img->xor_size *= 2;

            /* 24x24, 48x48 - increase AND size, and XOR size if monochrome */
            } else if (h->biWidth == 24 || h->biWidth == 48) {
                img->and_size = img->and_size * 4 / 3;
                if (h->biBitCount == 1)
                    img->xor_size = img->xor_size * 4 / 3;
            }
        }

        img->xor_mask = MemAlloc( img->xor_size + img->and_size );
        img->and_mask = (char *)img->xor_mask + img->xor_size;
        fseek( fp, res->DIB_offset + BITMAP_SIZE( h ), SEEK_SET );
        fread( img->xor_mask, img->xor_size + img->and_size, 1, fp );

        if (img_file->type == ICON_FILE_TYPE) {
            if (h->biWidth == 16 && h->biHeight == 16) {
                int ii, jj;

                /*
                 * fix the AND size that was double above and drop every other
                 * pair of bytes from the AND mask
                */
                // img->and_size /= 2;
                img->and_size = original_and_size;
                for (ii = 0, jj = 0; ii < img->and_size; )
                {
                    img->and_mask[ii] = img->and_mask[jj];
                    img->and_mask[ii+1] = img->and_mask[jj+1];
                    ii += 2;
                    jj += 4;
                }
                if (h->biBitCount == 1) {
                    /* do the same for the XOR size and mask */
                    img->xor_size = original_xor_size;
                    for (ii = 0, jj = 0; ii < img->xor_size; )
                    {
                        img->xor_mask[ii] = img->xor_mask[jj];
                        img->xor_mask[ii+1] = img->xor_mask[jj+1];
                        ii += 2;
                        jj += 4;
                    }
                }

            } else if (h->biWidth == 24 || h->biWidth == 48) {
                int ii, jj;

                /*
                 * fix the AND size that was increased above and drop every other
                 * pair of bytes from the AND mask
                */
                img->and_size = original_and_size;
                if (h->biWidth == 48) {  /* don't shift bytes if its 24x24 */
                    for (ii = 0, jj = 0; ii < img->and_size; )
                    {
                        img->and_mask[ii] = img->and_mask[jj];
                        img->and_mask[ii+1] = img->and_mask[jj+1];
                        img->and_mask[ii+2] = img->and_mask[jj+2];
                        if (h->biWidth == 48) {
                            img->and_mask[ii+3] = img->and_mask[jj+3];
                            img->and_mask[ii+4] = img->and_mask[jj+4];
                            img->and_mask[ii+5] = img->and_mask[jj+5];
                            ii += 6;
                            jj += 8;
                        } else {
                            ii += 3;
                            jj += 4;
                        }
                    }
                    if (h->biBitCount == 1) {
                        /* do the same for the XOR size and mask */
                        // img->xor_size = img->xor_size * 3 / 4;
                        img->xor_size = original_xor_size;
                        for (ii = 0, jj = 0; ii < img->xor_size; )
                        {
                            img->xor_mask[ii] = img->xor_mask[jj];
                            img->xor_mask[ii+1] = img->xor_mask[jj+1];
                            img->xor_mask[ii+2] = img->xor_mask[jj+2];
                            if (h->biWidth == 48) {
                                img->xor_mask[ii+3] = img->xor_mask[jj+3];
                                img->xor_mask[ii+4] = img->xor_mask[jj+4];
                                img->xor_mask[ii+5] = img->xor_mask[jj+5];
                                ii += 6;
                                jj += 8;
                            } else {
                                ii += 3;
                                jj += 4;
                            }
                        }
                    }
                }
            }
        }
        reverseAndBits(h->biWidth, h->biHeight, img->and_mask);
        return( img );
    }
    return( NULL );
} /* ImgResourceToImg */

an_img *ImgResourceToImgData( BYTE *data, unsigned *pos,
                              an_img_file *img_file, unsigned i )
{
    an_img_resource    *res;
    BITMAPINFO          *bm;
    BITMAPINFOHEADER    *h;
    an_img              *img;

    if( !data || !pos ) {
        return( NULL );
    }

    if( i >= img_file->count ) {
        return( NULL );
    }
    res = &img_file->resources[ i ];
    *pos = res->DIB_offset;

    bm = ReadImgBitmapData( data, pos );
    if( bm ) {
        img = MemAlloc( sizeof( an_img ) );
        img->bm = bm;
        h = &bm->bmiHeader;
        // h->biHeight /= 2;            /* code gen bug */
        h->biHeight = res->height;      /* they have height * 2 in this field */
        h->biSizeImage =
            BITS_INTO_BYTES( h->biWidth * h->biBitCount, h->biHeight );
        img->xor_size = h->biSizeImage;
        img->and_size = BITS_INTO_BYTES( h->biWidth, h->biHeight );
        img->xor_mask = MemAlloc( img->xor_size + img->and_size );
        img->and_mask = (char *)img->xor_mask + img->xor_size;
        *pos = res->DIB_offset + BITMAP_SIZE( h );
        memcpy( img->xor_mask, data + *pos, img->xor_size + img->and_size );
        reverseAndBits(h->biWidth, h->biHeight, img->and_mask);
        return( img );
    }
    return( NULL );
} /* ImgResourceToImgData */

/*
 * ImageFini - frees up memory allocated for an image structure.
 */

void ImageFini( an_img *img )
{
    MemFree( img->bm );
    MemFree( img->xor_mask );
    MemFree( img );
} /* ImageFini */

/*
 * ImgToXorBitmap - creates a bitmap which contains the part of an image
 * which is to be XOR'd against the background.
 */

HBITMAP ImgToXorBitmap( HDC hdc, an_img *img )
{
    HBITMAP             bitmap_handle = NULL;
    HPALETTE            new_palette, old_palette;
    BITMAPINFOHEADER    *h;

    h = &(img->bm->bmiHeader);
#if 1
    if( h->biBitCount == 1 ) {
        // this is really just a patch until this is figured out
        reverseAndBits( h->biWidth, h->biHeight, img->xor_mask );
        bitmap_handle = CreateBitmap( h->biWidth, h->biHeight, 1, 1,
                                                            img->xor_mask );
    } else {
        new_palette = CreateDIBPalette( img->bm );
        if( new_palette ) {
            old_palette = SelectPalette( hdc, new_palette, FALSE );
            RealizePalette( hdc );
            bitmap_handle = CreateDIBitmap( hdc, &img->bm->bmiHeader, CBM_INIT,
                img->xor_mask, img->bm, DIB_RGB_COLORS );
            SelectPalette( hdc, old_palette, FALSE );
            DeleteObject( new_palette );
        }
    }
#else
    new_palette = CreateDIBPalette( img->bm );
    if( new_palette ) {
        old_palette = SelectPalette( hdc, new_palette, FALSE );
        RealizePalette( hdc );
        bitmap_handle = CreateDIBitmap( hdc, &img->bm->bmiHeader, CBM_INIT,
            img->xor_mask, img->bm, DIB_RGB_COLORS );
        SelectPalette( hdc, old_palette, FALSE );
        DeleteObject( new_palette );
    }
#endif
    return( bitmap_handle );
} /* ImgToXorBitmap */

/*
 * ImgToAndBitmap - creates the bitmap which allows an image to have a
 * tranparent border around the central image.
 */

HBITMAP ImgToAndBitmap( HDC hdc, an_img *img )
{
    HBITMAP             bitmap_handle;
    BITMAPINFOHEADER    *h;

    hdc = hdc;
    h = &(img->bm->bmiHeader);
    bitmap_handle = CreateBitmap( h->biWidth, h->biHeight, 1, 1,
                                                            img->and_mask );
    return( bitmap_handle );
} /* ImgToAndBitmap */

/*
 * ImageClose - closes an image file which was opened with ImageOpen.
 */

void ImageClose( an_img_file *img_file )
{
    MemFree( img_file );
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -