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

📄 abl_bmp.c

📁 SHARP_ARM720T_LH79524/5软件开发包_支持TFT_LCD_NAND_FLASH_ETH_USB
💻 C
📖 第 1 页 / 共 2 页
字号:
 * Function: bmp_get_color_table
 *
 * Purpose: Returns a pointer to the color table
 *
 * Processing:
 *     A call to bmp_is_header_valid is performed to determine the BMP
 *     file type. If the BMP file type is BPP1, BPP4, or BPP8, then the
 *     color table is assigned a pointer after the BMP header
 *     information.
 *
 * Parameters:
 *     bmp_data : Pointer to a BMP data structure.
 *
 * Outputs: Nothing
 *
 * Returns: A pointer to the color table, or 0x0 if one does not exist
 *
 * Notes:
 *     1, 4, and 8 bit per pixel BMP images have color tables.
 *
 **********************************************************************/
BMP_COLOR_TABLE_T *bmp_get_color_table(BMP_T *bmp_data)
{
    BMP_STORAGE_T bmp_colors;
    BMP_COLOR_TABLE_T *table_ptr = (BMP_COLOR_TABLE_T *) 0x0;

    /* Get BMP structure type */
    bmp_colors = bmp_is_header_valid(bmp_data);

    /* Does a color table exist? */
    if ((bmp_colors >= BPP1) && (bmp_colors <= BPP8))
    {
        /* Color table exists, return pointer */
        table_ptr = (BMP_COLOR_TABLE_T *) bmp_data->ct_data;
    }

    return table_ptr;
}

/***********************************************************************
 *
 * Function: bmp_get_image_data
 *
 * Purpose: Returns a pointer to the BMP image data.
 *
 * Processing:
 *     A call to bmp_is_header_valid is performed to determine the BMP
 *     file type. Based on the BMP file type, the number of entries in
 *     the color table is computed. The pointer to the image data is
 *     computed at the end of the header plus an offset for the color
 *     table.
 *
 * Parameters:
 *     bmp_data : Pointer to a BMP data structure.
 *
 * Outputs: Nothing
 *
 * Returns: A pointer to the BMP image data.
 *
 * Notes: None
 *
 **********************************************************************/
void *bmp_get_image_data(BMP_T *bmp_data)
{
    INT_32 ctsize;

    /* Skip past color table */
    switch (bmp_is_header_valid(bmp_data))
    {
        case BPP1:
            /* Color table size is 2 entries */
            ctsize = 2;
            break;

        case BPP4:
            /* Color table size is 16 entries */
            ctsize = 16;
            break;

        case BPP8:
            /* Color table size is 256 entries */
            ctsize = bmp_data->buclrused;
            break;

        default:
            /* No color table */
            ctsize = 0;
    }

    return (void *) ((UNS_32) bmp_data->ct_data +
        ctsize * sizeof (BMP_COLOR_TABLE_T));
}

/***********************************************************************
 *
 * Function: bmp_convert_color
 *
 * Purpose: Converts a BMP color table entry to a COLOR_T color
 *
 * Processing:
 *     A color table entry (or raw 24-bit entry) is converted into the
 *     native (compiled) color type by masking and shifting the red,
 *     green, and blue components of color and computing the closest
 *     color in the native format (either 233, 555, or 565).
 *
 * Parameters: 
 *     color_entry : Color table entry pointer
 *
 * Outputs: None
 *
 * Returns: A converted color_type entry from the color data
 *
 * Notes:
 *     Not valid for 16-bit or 32-bit color formats.
 *
 **********************************************************************/
COLOR_T bmp_convert_color(BMP_COLOR_TABLE_T *color_entry)
{
    COLOR_T cv_color, r, g, b;

    /* Scale colors to color_type color */
    r = (COLOR_T)
        ((UNS_32) color_entry->red * (REDMASK >> REDSHIFT) / 256);
    g = (COLOR_T)
        ((UNS_32) color_entry->green * (GREENMASK >> GREENSHIFT) / 256);
    b = (COLOR_T)
        ((UNS_32) color_entry->blue * (BLUEMASK >> BLUESHIFT) / 256);
    cv_color = (b << BLUESHIFT) + (g << GREENSHIFT) + (r << REDSHIFT);

    return cv_color;
}

/***********************************************************************
 *
 * Function: bmp_convert_image
 *
 * Purpose: Convert a BMP image to a COLOR_T image
 *
 * Processing:
 *     See function.
 *
 * Parameters: 
 *     bmp_data : pointer to a BMP data structure
 *     xsize    : Pointer to place the horizontal size of the image
 *     ysize    : Pointer to place the vertical size of the image
 *     bufout   : Pointer to where to place the converted image
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes:
 *     Only uncompressed 1, 4, 8, and 24 bit per pixel formats are
 *     supported. Before converting, be sure that the target buffer,
 *     bufout, is large enough for the converted image.
 *
 **********************************************************************/
BMP_STORAGE_T bmp_convert_image(BMP_T *bmp_data,
                                INT_16 *xsize,
                                INT_16 *ysize,
                                COLOR_T *bufout)
{
    BMP_STORAGE_T bmpcolors;

    /* Get BMP image type */
    bmpcolors = bmp_is_header_valid(bmp_data);

    if (bmpcolors != INVALID_BMP)
    {
        /* Save horizontal and vertical sizes */
        *xsize = bmp_data->biwidth;
        *ysize = bmp_data->biheight;

        /* Good table entry */
        switch (bmpcolors)
        {
            case BPP1:
                /* 1 bit per pixel, call function */
                bmp_render_w_palette (bmp_data, bufout, 0x80, 7, 1);
                break;

            case BPP4:
                /* 4 bits per pixel, call function */
                bmp_render_w_palette (bmp_data, bufout, 0xF0, 4, 4);
                break;

            case BPP8:
                /* 8 bits per pixel, call function */
                bmp_render_w_palette (bmp_data, bufout, 0xFF, 0, 8);
                break;

            case BPP24:
                /* 24 bits per pixel, call function */
                bmp_render24 (bmp_data, bufout);
                break;

            default:
                /* Invalid or unsupported BMP image */
                *xsize = 0;
                *ysize = 0;
                break;
        }
    }
    else
    {
        /* Invalid or unsupported BMP image */
        *xsize = 0;
        *ysize = 0;
    }
    
    return bmpcolors;
}

/***********************************************************************
 *
 * Function: bmp_convert_image
 *
 * Purpose: Allocates storage for a new BMP file structure.
 *
 * Processing:
 *     This function computes the required size needed for the BMP
 *     header, color table, and image data, based on the color depth.
 *     Memory for an image (with header and color table) is allocated
 *     and the pointer returned to the caller.
 *
 * Parameters: 
 *     xsize          : Horizontal size of the image storage space
 *     ysize          : Vertical size of the image storage space
 *     bits_per_pixel : number of bits per pixel, used to set the size
 *                      of the buffer and color table (enumerator)
 *
 * Outputs: Nothing
 *
 * Returns:
 *     A pointer to a new allocated BMP structure, or NULL if an error
 *     occurred.
 *
 * Notes:
 *     The bits_per_pixel parameter is important for optimal memory
 *     usage. Setting this value will 'adjust' the sizing of the
 *     allocated BMP structure, modifying the sizes of the color table
 *     and data area. If unsure of the bits per pixel, use BPP24,
 *     extra memory will be allocated for BPP24, but no memory
 *     allocation problems will occur.
 *
 **********************************************************************/
BMP_T *bmp_allocate_structure(INT_32 xsize,
                              INT_32 ysize,
                              BMP_STORAGE_T bits_per_pixel)
{
    INT_32 alloc_size, ctable_size, dentry_size;

    /* Need room for the basic structure size */
    alloc_size = sizeof (BMP_T);

    /* Select size of color table and data area based on bits per
       pixel */
    switch (bits_per_pixel)
    {
        case BPP1:
            ctable_size = 2;
            dentry_size = 1;
            break;

        case BPP4:
            ctable_size = 16;
            dentry_size = 4;
            break;

        case BPP8:
            ctable_size = 256;
            dentry_size = 8;
            break;

        case BPP24:
        default:
            ctable_size = 0;     /* No color table */
            dentry_size = 24;
            break;
    }

    /* Add in data area size, - size based on bits per pixel (8 extra
       bytes are included at the end of the allocated memory for
       safety) */
    alloc_size = alloc_size +
        (ctable_size * sizeof (BMP_COLOR_TABLE_T)) +
        (xsize * ysize * dentry_size / 8) + 8;

    /* Return pointer to allocated structure */
    return (BMP_T *) abl_new(alloc_size);
}

⌨️ 快捷键说明

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