Пример #1
0
static struct rtgui_image_palette *rtgui_image_bmp_load_palette(
    struct rtgui_filerw *file,
    rt_uint32_t colorsUsed,
    rt_bool_t alpha)
{
    /* Load the palette, if any */
    rt_uint32_t i;
    struct rtgui_image_palette *palette;

    palette = rtgui_image_palette_create(colorsUsed);
    if (palette == RT_NULL)
    {
        return RT_NULL;
    }

	palette->ncolors = colorsUsed;
    if (alpha)
    {
        rt_uint8_t temp[4];
        for (i = 0; i < colorsUsed; i++)
        {
            if (rtgui_filerw_read(file, (void *)&temp, 1, 4) != 4)
            {
                rtgui_free(palette);
                return RT_NULL;
            }
            palette->colors[i] = RTGUI_ARGB(temp[3], temp[2], temp[1], temp[0]);
        }
    }
    else
    {
        rt_uint8_t temp[3];
        for (i = 0; i < colorsUsed; i++)
        {
            if (rtgui_filerw_read(file, (void *)&temp, 1, 3) != 3)
            {
                rtgui_free(palette);
                return RT_NULL;
            }
            palette->colors[i] = RTGUI_RGB(temp[2], temp[1], temp[0]);
        }
    }

    return palette;
}
Пример #2
0
static struct rtgui_image_palette* rtgui_image_bmp_load_palette(struct rtgui_image_bmp_header* header, struct rtgui_filerw* src)
{
	/* Load the palette, if any */
	rt_size_t i;
	struct rtgui_image_palette* palette;

	if (header->biClrUsed == 0)
		header->biClrUsed = 1 << header->biBitCount;

	palette = rtgui_image_palette_create(header->biClrUsed);
	if (palette == RT_NULL) return RT_NULL;

	if ( header->biSize == 12 )
	{
		rt_uint8_t r, g, b;
		for ( i = 0; i < (int)header->biClrUsed; ++i )
		{
			rtgui_filerw_read(src, &b, 1, 1);
			rtgui_filerw_read(src, &g, 1, 1);
			rtgui_filerw_read(src, &r, 1, 1);
			palette->colors[i] = RTGUI_RGB(r, g, b);
		}
	}
	else
	{
		rt_uint8_t r, g, b, a;
		for ( i = 0; i < (int)header->biClrUsed; ++i )
		{
			rtgui_filerw_read(src, &b, 1, 1);
			rtgui_filerw_read(src, &g, 1, 1);
			rtgui_filerw_read(src, &r, 1, 1);
			rtgui_filerw_read(src, &a, 1, 1);
			palette->colors[i] = RTGUI_ARGB(a, r, g, b);
		}
	}

	return palette;
}