📄 abl_bmp.c
字号:
/***********************************************************************
* $Workfile: abl_bmp.c $
* $Revision: 1.1 $
* $Author: WellsK $
* $Date: Sep 02 2003 14:23:54 $
*
* Project: BMP file structures
*
* Description:
* See the bmp.h header file for a description of this package.
*
* This package uses *malloc*. If you want to use this package, you
* should replace malloc with your own dynamic allocation call if
* malloc is an invalid function.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/abl/source/abl_bmp.c-arc $
*
* Rev 1.1 Sep 02 2003 14:23:54 WellsK
* Corrected color table and image return addresses.
*
* Rev 1.0 Jun 09 2003 12:06:26 WellsK
* Initial revision.
*
*
***********************************************************************
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
**********************************************************************/
#include "abl_bmp.h"
#include "abl_heap.h"
/***********************************************************************
* Private functions
**********************************************************************/
/***********************************************************************
*
* Function: bmp_render_w_palette
*
* Purpose: Converts a pelletized (color table) BMP image into a COLOR_T
* image in raw format.
*
* Processing:
* See function.
*
* Parameters:
* bmp_data : pointer to BMP data structure
* buf : pointer of where to place converted image
* pmask : Color table entry mask
* md_shift : incremental mask shift value
* pshift : initial mask shift value
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void bmp_render_w_palette(BMP_T *bmp_data,
COLOR_T *buf,
UNS_8 pmask,
UNS_8 md_shift,
UNS_8 pshift)
{
BMP_COLOR_TABLE_T *color_table;
UNS_8 *image_data;
INT_32 x, xdif, y;
UNS_8 pixel_data, pixel_mask, pixel_shift;
INT_32 table_index, image_start;
UNS_8 mask_shift;
COLOR_T *fbuf;
/* Get pointers to color table and image data */
color_table = bmp_get_color_table(bmp_data);
image_start = (INT_32) bmp_get_image_data(bmp_data);
image_data = (UNS_8 *) image_start;
/* Clear initial pixel mask */
pixel_mask = 0x0;
/* Convert Y axis first */
y = bmp_data->biheight - 1;
while (y >= 0)
{
/* Reset buf to start from left to right */
fbuf = buf + (bmp_data->biwidth * y);
/* Render a single line */
x = bmp_data->biwidth - 1;
while (x >= 0)
{
/* A byte contains data for up to 8 pixels, once the
pixel mask has reached 0x0, load a new byte and reset
the mask */
if (pixel_mask == 0x0)
{
/* Reset pixel mask and shift value */
pixel_mask = pmask;
pixel_shift = pshift;
mask_shift = md_shift;
/* get a new byte and increment image pointer */
pixel_data = *image_data;
image_data++;
}
/* Determine index into color table */
table_index = (INT_32)
((pixel_data & pixel_mask) >> mask_shift);
/* Use the appropriate index in the color table */
*fbuf = bmp_convert_color(&color_table [table_index]);
fbuf++;
/* Update x coordinate */
x--;
/* Shift pixel mask to next bit */
pixel_mask = pixel_mask >> pixel_shift;
mask_shift = mask_shift - pshift;
}
y--;
/* Since a horizontal line is 'padded' to end on a 32-bit
boundary, the image pointer may need to be adjusted for the
next line */
x = ((INT_32) image_data - image_start) / 4;
xdif = x * 4;
image_data = image_data + (((INT_32) image_data -
image_start) - xdif);
/* Clear pixel_mask to reset pixel mask and shift values */
pixel_mask = 0x0;
}
}
/***********************************************************************
*
* Function: bmp_render24
*
* Purpose: Converts a raw 24-bit RGB image to a COLOR_T raw image.
*
* Processing:
* See function.
*
* Parameters:
* bmp_data : pointer to BMP data structure
* buf : pointer of where to place converted image
*
* Outputs: None
*
* Returns: Nothing
*
* Notes: None
*
**********************************************************************/
void bmp_render24 (BMP_T *bmp_data,
COLOR_T *buf)
{
BMP24_COLOR_TABLE_T *image_data;
INT_32 x, y;
COLOR_T *fbuf;
/* Get pointer to image data - each pixel entry can be considered
a color table / palette entry */
image_data =
(BMP24_COLOR_TABLE_T *) bmp_get_image_data(bmp_data);
/* Convert Y axis first */
y = bmp_data->biheight - 1;
while (y >= 0)
{
/* Reset buf to start from left to right */
fbuf = buf + (bmp_data->biwidth * y);
/* Render a single line */
x = bmp_data->biwidth - 1;
while (x >= 0)
{
/* Use the appropriate index in the color table */
*fbuf = bmp_convert_color(
(BMP_COLOR_TABLE_T *) image_data);
/* Update source to next pixel data set */
image_data++;
fbuf++;
/* Update x coordinate */
x--;
}
/* Since a horizontal line is 'padded' to end on a 32-bit
boundary, the image pointer may need to be adjusted for the
next line */
x = bmp_data->biwidth / 4;
x = x * 4;
image_data = (BMP24_COLOR_TABLE_T *) ((INT_32) image_data +
(bmp_data->biwidth - x));
y--;
}
}
/***********************************************************************
* Public functions
**********************************************************************/
/***********************************************************************
*
* Function: bmp_is_header_valid
*
* Purpose: Determine if the structure is a BMP structure
*
* Processing:
* The header type (bftype) is examined to match 'BM'. If it matches
* and the file type is uncompressed, then the color depth is
* examined and the return value set to the appropriate color depth
* enumeration. If an unsupported type is found, type INVALID_BMP
* will be returned.
*
* Parameters:
* bmp_data : Pointer to a BMP data structure.
*
* Outputs: None
*
* Returns:
* Enumeration that defines the BMP color depth, or INVALID_BMP if
* the BMP type is unsupported.
*
* Notes: None
*
**********************************************************************/
BMP_STORAGE_T bmp_is_header_valid(BMP_T *bmp_data)
{
BMP_STORAGE_T retval = INVALID_BMP;
/* Does the structure have the bitmap identifier? */
if ((bmp_data->bftype [0] == BMP_ID0) &&
(bmp_data->bftype [1] == BMP_ID1))
{
/* Compression field must be empty! */
if ((bmp_data->bicompressn == BI_RGB) ||
(bmp_data->bicompressn == BI_RGBA))
{
switch (bmp_data->bibitcount)
{
case 1:
/* 1 bit per pixel */
retval = BPP1;
break;
case 4:
/* 4 bits per pixel */
retval = BPP4;
break;
case 8:
/* 8 bits per pixel */
retval = BPP8;
break;
case 24:
/* 24 bits per pixel */
retval = BPP24;
break;
default:
/* No other modes are valid, keep invalid flag */
break;
}
}
}
return retval;
}
/***********************************************************************
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -