sync with github bd3351e572
As always, full log is in GitHub. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@2234 bbd45198-f89e-11dd-88c7-29a3b14d5316
This commit is contained in:
parent
f7fbd6bc6d
commit
08e05eb3b4
@ -1,4 +1,4 @@
|
||||
Import('RTT_ROOT')
|
||||
import os
|
||||
from building import *
|
||||
|
||||
common_src = Split("""
|
||||
@ -72,10 +72,10 @@ widgets/panel.c
|
||||
# The set of source files associated with this SConscript file.
|
||||
src = common_src + server_src + widgets_src
|
||||
|
||||
path = [RTT_ROOT + '/components/rtgui/include',
|
||||
RTT_ROOT + '/components/rtgui/common',
|
||||
RTT_ROOT + '/components/rtgui/server',
|
||||
RTT_ROOT + '/components/rtgui/widgets']
|
||||
cwd = GetCurrentDir()
|
||||
dirs = ['include', 'common', 'server', 'widgets']
|
||||
path = [os.path.join(cwd, i) for i in dirs]
|
||||
|
||||
group = DefineGroup('RTGUI', src, depend = ['RT_USING_RTGUI'], CPPPATH = path)
|
||||
|
||||
Return('group')
|
||||
|
@ -251,21 +251,7 @@ static int mem_read(struct rtgui_filerw *context, void *ptr, rt_size_t size, rt_
|
||||
|
||||
static int mem_write(struct rtgui_filerw *context, const void *ptr, rt_size_t size, rt_size_t num)
|
||||
{
|
||||
#if 0
|
||||
struct rtgui_filerw_mem* mem = (struct rtgui_filerw_mem*)context;
|
||||
|
||||
if ((mem->mem_position + (num * size)) > mem->mem_end)
|
||||
{
|
||||
num = (mem->mem_end - mem->mem_position)/size;
|
||||
}
|
||||
|
||||
rt_memcpy(mem->mem_position, ptr, num*size);
|
||||
mem->mem_position += num*size;
|
||||
|
||||
return num;
|
||||
#else
|
||||
return 0; /* not support memory write */
|
||||
#endif
|
||||
}
|
||||
|
||||
static int mem_tell(struct rtgui_filerw* context)
|
||||
|
@ -82,7 +82,7 @@ static struct rtgui_image_engine* rtgui_image_get_engine(const char* type)
|
||||
}
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
static struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
|
||||
struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn)
|
||||
{
|
||||
struct rtgui_list_node *node;
|
||||
struct rtgui_image_engine *engine;
|
||||
|
@ -33,22 +33,19 @@ struct rtgui_image_bmp
|
||||
{
|
||||
rt_bool_t is_loaded;
|
||||
rt_uint8_t *pixels;
|
||||
struct rtgui_filerw* filerw;
|
||||
struct rtgui_filerw *filerw;
|
||||
rt_uint32_t w, h;
|
||||
rt_uint32_t pixel_offset;
|
||||
rt_uint32_t pitch; rt_uint8_t scale;
|
||||
rt_uint32_t pitch;
|
||||
rt_uint8_t scale;
|
||||
rt_uint8_t bit_per_pixel;
|
||||
rt_uint8_t pad;
|
||||
};
|
||||
|
||||
/* static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file,
|
||||
rt_uint32_t *width, rt_uint32_t *height);
|
||||
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image,
|
||||
struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load); */
|
||||
static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file);
|
||||
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load);
|
||||
static void rtgui_image_bmp_unload(struct rtgui_image* image);
|
||||
static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect);
|
||||
static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw *file);
|
||||
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
|
||||
static void rtgui_image_bmp_unload(struct rtgui_image *image);
|
||||
static void rtgui_image_bmp_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
|
||||
|
||||
|
||||
struct rtgui_image_engine rtgui_image_bmp_engine =
|
||||
@ -61,16 +58,14 @@ struct rtgui_image_engine rtgui_image_bmp_engine =
|
||||
rtgui_image_bmp_blit
|
||||
};
|
||||
|
||||
static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file)
|
||||
//static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file,
|
||||
// rt_uint32_t *width, rt_uint32_t *height)
|
||||
static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw *file)
|
||||
{
|
||||
rt_uint8_t buffer[18];
|
||||
rt_bool_t is_bmp = RT_FALSE;
|
||||
|
||||
do
|
||||
{
|
||||
if (!file )
|
||||
if (!file)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -92,34 +87,33 @@ static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file)
|
||||
|
||||
/* Read BMP header size */
|
||||
if (*(rt_uint32_t *)&buffer[14] == 12)
|
||||
{ /* Bitmap Header Version 2.x */
|
||||
{
|
||||
/* Bitmap Header Version 2.x */
|
||||
if (rtgui_filerw_read(file, (void *)buffer, 8, 1) != 8)
|
||||
{
|
||||
break;
|
||||
}
|
||||
/* Read image size */
|
||||
// *width = (rt_uint32_t)*(rt_uint16_t *)&buffer[0];
|
||||
// *height = (rt_uint32_t)*(rt_uint16_t *)&buffer[2];
|
||||
is_bmp = RT_TRUE;
|
||||
}
|
||||
else
|
||||
{ /* Bitmap Header Version bigger than 2.x */
|
||||
{
|
||||
/* Bitmap Header Version bigger than 2.x */
|
||||
if (rtgui_filerw_read(file, (void *)buffer, 8, 1) != 8)
|
||||
{
|
||||
break;
|
||||
}
|
||||
/* Read image size */
|
||||
// *width = *(rt_uint32_t *)&buffer[0];
|
||||
// *height = *(rt_uint32_t *)&buffer[4];
|
||||
is_bmp = RT_TRUE;
|
||||
}
|
||||
} while(0);
|
||||
}
|
||||
while (0);
|
||||
|
||||
return is_bmp;
|
||||
}
|
||||
|
||||
static struct rtgui_image_palette* rtgui_image_bmp_load_palette(
|
||||
struct rtgui_filerw* file,
|
||||
static struct rtgui_image_palette *rtgui_image_bmp_load_palette(
|
||||
struct rtgui_filerw *file,
|
||||
rt_uint32_t colorsUsed,
|
||||
rt_bool_t alpha)
|
||||
{
|
||||
@ -163,13 +157,11 @@ static struct rtgui_image_palette* rtgui_image_bmp_load_palette(
|
||||
return palette;
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load)
|
||||
//static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image,
|
||||
// struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load)
|
||||
static rt_bool_t rtgui_image_bmp_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
|
||||
{
|
||||
rt_uint8_t scale = 2;
|
||||
rt_uint8_t scale = 0;
|
||||
rt_uint8_t *wrkBuffer;
|
||||
struct rtgui_image_bmp* bmp;
|
||||
struct rtgui_image_bmp *bmp;
|
||||
rt_uint32_t bmpHeaderSize;
|
||||
rt_uint32_t colorsUsed;
|
||||
|
||||
@ -187,7 +179,7 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
|
||||
break;
|
||||
}
|
||||
|
||||
bmp = (struct rtgui_image_bmp*)rtgui_malloc(sizeof(struct rtgui_image_bmp));
|
||||
bmp = (struct rtgui_image_bmp *)rtgui_malloc(sizeof(struct rtgui_image_bmp));
|
||||
if (bmp == RT_NULL)
|
||||
{
|
||||
break;
|
||||
@ -216,19 +208,21 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
|
||||
// rt_kprintf("BMP: bmpHeaderSize %d\n", bmpHeaderSize);
|
||||
colorsUsed = 0;
|
||||
if (bmpHeaderSize == 12)
|
||||
{ /* Bitmap Header Version 2.x */
|
||||
{
|
||||
/* Bitmap Header Version 2.x */
|
||||
if (rtgui_filerw_read(file, (void *)wrkBuffer, 8, 1) != 8)
|
||||
{
|
||||
break;
|
||||
}
|
||||
/* Read image size */
|
||||
bmp->w = (rt_uint32_t)*(rt_uint16_t *)&wrkBuffer[0];
|
||||
bmp->h = (rt_uint32_t)*(rt_uint16_t *)&wrkBuffer[2];
|
||||
bmp->w = (rt_uint32_t) * (rt_uint16_t *)&wrkBuffer[0];
|
||||
bmp->h = (rt_uint32_t) * (rt_uint16_t *)&wrkBuffer[2];
|
||||
/* Read bits per pixel */
|
||||
bmp->bit_per_pixel = (rt_uint8_t)*(rt_uint16_t *)&wrkBuffer[6];
|
||||
bmp->bit_per_pixel = (rt_uint8_t) * (rt_uint16_t *)&wrkBuffer[6];
|
||||
}
|
||||
else
|
||||
{ /* Bitmap Header Version bigger than 2.x */
|
||||
{
|
||||
/* Bitmap Header Version bigger than 2.x */
|
||||
rt_uint32_t compression;
|
||||
|
||||
if (rtgui_filerw_read(file, (void *)wrkBuffer, 36, 1) != 36)
|
||||
@ -239,7 +233,7 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
|
||||
bmp->w = *(rt_uint32_t *)&wrkBuffer[0];
|
||||
bmp->h = *(rt_uint32_t *)&wrkBuffer[4];
|
||||
/* Read bits per pixel */
|
||||
bmp->bit_per_pixel = (rt_uint8_t)*(rt_uint16_t *)&wrkBuffer[10];
|
||||
bmp->bit_per_pixel = (rt_uint8_t) * (rt_uint16_t *)&wrkBuffer[10];
|
||||
if (bmp->bit_per_pixel > 32)
|
||||
{
|
||||
rt_kprintf("BMP err: unsupported format\n");
|
||||
@ -364,7 +358,7 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
|
||||
{
|
||||
dst = bmp->pixels + (image->h - y - 1) * imageWidth;
|
||||
readIndex = 0;
|
||||
skipLength= 0;
|
||||
skipLength = 0;
|
||||
|
||||
/* Process a line */
|
||||
while (readIndex < bmp->pitch)
|
||||
@ -446,7 +440,7 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
|
||||
/* Skip padding bytes */
|
||||
if (bmp->pad)
|
||||
{
|
||||
if ( rtgui_filerw_seek(file, bmp->pad, RTGUI_FILE_SEEK_CUR) < 0)
|
||||
if (rtgui_filerw_seek(file, bmp->pad, RTGUI_FILE_SEEK_CUR) < 0)
|
||||
{
|
||||
error = RT_TRUE;
|
||||
break;
|
||||
@ -478,7 +472,8 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
|
||||
/* Release memory */
|
||||
rt_free(wrkBuffer);
|
||||
return RT_TRUE;
|
||||
} while(0);
|
||||
}
|
||||
while (0);
|
||||
|
||||
/* Release memory */
|
||||
rt_free(wrkBuffer);
|
||||
@ -488,13 +483,13 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
static void rtgui_image_bmp_unload(struct rtgui_image* image)
|
||||
static void rtgui_image_bmp_unload(struct rtgui_image *image)
|
||||
{
|
||||
struct rtgui_image_bmp* bmp;
|
||||
struct rtgui_image_bmp *bmp;
|
||||
|
||||
if (image != RT_NULL)
|
||||
{
|
||||
bmp = (struct rtgui_image_bmp*)image->data;
|
||||
bmp = (struct rtgui_image_bmp *)image->data;
|
||||
|
||||
/* Release memory */
|
||||
rtgui_free(bmp->pixels);
|
||||
@ -508,15 +503,15 @@ static void rtgui_image_bmp_unload(struct rtgui_image* image)
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* dst_rect)
|
||||
static void rtgui_image_bmp_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *dst_rect)
|
||||
{
|
||||
rt_uint16_t w, h;
|
||||
struct rtgui_image_bmp* bmp;
|
||||
struct rtgui_image_bmp *bmp;
|
||||
rt_uint8_t bytePerPixel;
|
||||
rt_uint32_t imageWidth;
|
||||
rt_bool_t error;
|
||||
|
||||
bmp = (struct rtgui_image_bmp*)image->data;
|
||||
bmp = (struct rtgui_image_bmp *)image->data;
|
||||
RT_ASSERT(image != RT_NULL || dc != RT_NULL || dst_rect != RT_NULL || bmp != RT_NULL);
|
||||
|
||||
bytePerPixel = bmp->bit_per_pixel / 8;
|
||||
@ -560,19 +555,25 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
rt_uint8_t skipLength;
|
||||
rt_uint16_t x, y;
|
||||
rt_int8_t scale1, scale2;
|
||||
|
||||
wrkBuffer = (rt_uint8_t *)rt_malloc(BMP_WORKING_BUFFER_SIZE);
|
||||
if (wrkBuffer == RT_NULL)
|
||||
{
|
||||
rt_kprintf("BMP err: no mem (%d)\n", BMP_WORKING_BUFFER_SIZE);
|
||||
break;
|
||||
}
|
||||
rt_uint16_t y_start = dst_rect->y1 + h - 1;
|
||||
|
||||
/* Read the pixels. Note that the bmp image is upside down */
|
||||
if (rtgui_filerw_seek(bmp->filerw, bmp->pixel_offset, RTGUI_FILE_SEEK_SET) < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
/* the image is upside down. So we need to start from middle if the
|
||||
* image is higher than the dst_rect. */
|
||||
if (image->h > rtgui_rect_height(*dst_rect))
|
||||
{
|
||||
int hdelta = image->h - rtgui_rect_height(*dst_rect);
|
||||
if (rtgui_filerw_seek(bmp->filerw, hdelta * (bmp->pitch + bmp->pad) * (1 << bmp->scale),
|
||||
RTGUI_FILE_SEEK_CUR) < 0)
|
||||
{
|
||||
error = RT_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (bmp->bit_per_pixel == 1)
|
||||
{
|
||||
@ -601,19 +602,28 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
}
|
||||
}
|
||||
|
||||
wrkBuffer = (rt_uint8_t *)rt_malloc(
|
||||
(BMP_WORKING_BUFFER_SIZE > bmp->pitch) ? \
|
||||
bmp->pitch : BMP_WORKING_BUFFER_SIZE);
|
||||
if (wrkBuffer == RT_NULL)
|
||||
{
|
||||
rt_kprintf("BMP err: no mem (%d)\n", BMP_WORKING_BUFFER_SIZE);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Process whole image */
|
||||
y = 0;
|
||||
while (y < image->h)
|
||||
while (y < h)
|
||||
{
|
||||
x = 0;
|
||||
readIndex = 0;
|
||||
skipLength= 0;
|
||||
skipLength = 0;
|
||||
|
||||
/* Process a line */
|
||||
while (readIndex < bmp->pitch)
|
||||
{
|
||||
/* Put progress indicator */
|
||||
rt_kprintf("\r%lu%%", y * 100UL / image->h);
|
||||
rt_kprintf("\r%lu%%", y * 100UL / h);
|
||||
|
||||
/* Read data to buffer */
|
||||
readLength = (BMP_WORKING_BUFFER_SIZE > (bmp->pitch - readIndex)) ? \
|
||||
@ -629,18 +639,19 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
/* Process read buffer */
|
||||
if (bmp->bit_per_pixel == 1)
|
||||
{
|
||||
rt_uint8_t j;
|
||||
rtgui_color_t color;
|
||||
|
||||
for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << scale1)
|
||||
{
|
||||
rt_uint8_t j;
|
||||
for (j = 0; j < 8; j += 1 << scale2)
|
||||
{
|
||||
rtgui_color_t color;
|
||||
color = image->palette->colors[(wrkBuffer[loadIndex] & (1 << (7 - j))) >> (7 - j)];
|
||||
rtgui_dc_draw_color_point(dc,
|
||||
dst_rect->x1 + x++,
|
||||
dst_rect->y1 + image->h - y,
|
||||
y_start - y,
|
||||
color);
|
||||
if (x >= w)
|
||||
break;
|
||||
}
|
||||
if (scale1 && (readLength % (1 << scale1)))
|
||||
{
|
||||
@ -650,18 +661,19 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
}
|
||||
else if (bmp->bit_per_pixel == 4)
|
||||
{
|
||||
rt_uint8_t j;
|
||||
rtgui_color_t color;
|
||||
|
||||
for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << scale1)
|
||||
{
|
||||
rt_uint8_t j;
|
||||
for (j = 0; j < 8; j += 1 << (2 + scale2))
|
||||
{
|
||||
rtgui_color_t color;
|
||||
color = image->palette->colors[(wrkBuffer[loadIndex] & (0x0F << (4 - j))) >> (4 - j)];
|
||||
rtgui_dc_draw_color_point(dc,
|
||||
dst_rect->x1 + x++,
|
||||
dst_rect->y1 + image->h - y,
|
||||
y_start - y,
|
||||
color);
|
||||
if (x >= w)
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scale1 && (readLength % (1 << scale1)))
|
||||
@ -671,15 +683,16 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
}
|
||||
else if (bmp->bit_per_pixel == 8)
|
||||
{
|
||||
rtgui_color_t color;
|
||||
|
||||
for (loadIndex = skipLength; loadIndex < readLength; loadIndex += 1 << bmp->scale)
|
||||
{
|
||||
rtgui_color_t color;
|
||||
color = image->palette->colors[wrkBuffer[loadIndex]];
|
||||
rtgui_dc_draw_color_point(dc,
|
||||
dst_rect->x1 + x++,
|
||||
dst_rect->y1 + image->h - y,
|
||||
y_start - y,
|
||||
color);
|
||||
if (x >= w)
|
||||
break;
|
||||
}
|
||||
if (readLength % (1 << bmp->scale))
|
||||
{
|
||||
@ -713,9 +726,11 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
blit_line(temp, &wrkBuffer[loadIndex], bytePerPixel);
|
||||
dc->engine->blit_line(dc,
|
||||
dst_rect->x1 + x, dst_rect->x1 + x + 1,
|
||||
dst_rect->y1 + image->h - y,
|
||||
y_start - y,
|
||||
temp);
|
||||
x++;
|
||||
if (x >= w)
|
||||
break;
|
||||
}
|
||||
if (readLength % (1 << bmp->scale))
|
||||
{
|
||||
@ -732,7 +747,7 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
/* Skip padding bytes */
|
||||
if (bmp->pad)
|
||||
{
|
||||
if ( rtgui_filerw_seek(bmp->filerw, bmp->pad, RTGUI_FILE_SEEK_CUR) < 0)
|
||||
if (rtgui_filerw_seek(bmp->filerw, bmp->pad, RTGUI_FILE_SEEK_CUR) < 0)
|
||||
{
|
||||
error = RT_TRUE;
|
||||
break;
|
||||
@ -761,7 +776,7 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
else
|
||||
{
|
||||
rt_uint16_t x, y;
|
||||
rt_uint8_t* ptr;
|
||||
rt_uint8_t *ptr;
|
||||
|
||||
for (y = 0; y < h; y ++)
|
||||
{
|
||||
@ -813,7 +828,8 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
|
||||
}
|
||||
}
|
||||
// rt_kprintf("BMP: blit ok\n");
|
||||
} while(0);
|
||||
}
|
||||
while (0);
|
||||
}
|
||||
|
||||
void rtgui_image_bmp_init()
|
||||
|
@ -19,10 +19,10 @@
|
||||
#include <dfs_posix.h>
|
||||
#endif
|
||||
|
||||
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file);
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load);
|
||||
static void rtgui_image_jpeg_unload(struct rtgui_image* image);
|
||||
static void rtgui_image_jpeg_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect);
|
||||
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file);
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
|
||||
static void rtgui_image_jpeg_unload(struct rtgui_image *image);
|
||||
static void rtgui_image_jpeg_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect);
|
||||
|
||||
struct rtgui_jpeg_error_mgr
|
||||
{
|
||||
@ -33,7 +33,7 @@ struct rtgui_image_jpeg
|
||||
{
|
||||
rt_bool_t is_loaded;
|
||||
|
||||
struct rtgui_filerw* filerw;
|
||||
struct rtgui_filerw *filerw;
|
||||
|
||||
/* jpeg structure */
|
||||
struct jpeg_decompress_struct cinfo;
|
||||
@ -64,10 +64,11 @@ struct rtgui_image_engine rtgui_image_jpg_engine =
|
||||
};
|
||||
|
||||
#define INPUT_BUFFER_SIZE 4096
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
struct jpeg_source_mgr pub;
|
||||
|
||||
struct rtgui_filerw* ctx;
|
||||
struct rtgui_filerw *ctx;
|
||||
rt_uint8_t buffer[INPUT_BUFFER_SIZE];
|
||||
} rtgui_jpeg_source_mgr;
|
||||
|
||||
@ -75,7 +76,7 @@ typedef struct {
|
||||
* Initialize source --- called by jpeg_read_header
|
||||
* before any data is actually read.
|
||||
*/
|
||||
static void init_source (j_decompress_ptr cinfo)
|
||||
static void init_source(j_decompress_ptr cinfo)
|
||||
{
|
||||
/* We don't actually need to do anything */
|
||||
return;
|
||||
@ -84,9 +85,9 @@ static void init_source (j_decompress_ptr cinfo)
|
||||
/*
|
||||
* Fill the input buffer --- called whenever buffer is emptied.
|
||||
*/
|
||||
static boolean fill_input_buffer (j_decompress_ptr cinfo)
|
||||
static boolean fill_input_buffer(j_decompress_ptr cinfo)
|
||||
{
|
||||
rtgui_jpeg_source_mgr * src = (rtgui_jpeg_source_mgr *) cinfo->src;
|
||||
rtgui_jpeg_source_mgr *src = (rtgui_jpeg_source_mgr *) cinfo->src;
|
||||
int nbytes;
|
||||
|
||||
nbytes = rtgui_filerw_read(src->ctx, src->buffer, 1, INPUT_BUFFER_SIZE);
|
||||
@ -116,9 +117,9 @@ static boolean fill_input_buffer (j_decompress_ptr cinfo)
|
||||
* Arranging for additional bytes to be discarded before reloading the input
|
||||
* buffer is the application writer's problem.
|
||||
*/
|
||||
static void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
||||
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
|
||||
{
|
||||
rtgui_jpeg_source_mgr * src = (rtgui_jpeg_source_mgr *) cinfo->src;
|
||||
rtgui_jpeg_source_mgr *src = (rtgui_jpeg_source_mgr *) cinfo->src;
|
||||
|
||||
/* Just a dumb implementation for now. Could use fseek() except
|
||||
* it doesn't work on pipes. Not clear that being smart is worth
|
||||
@ -143,7 +144,7 @@ static void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
|
||||
* Terminate source --- called by jpeg_finish_decompress
|
||||
* after all data has been read.
|
||||
*/
|
||||
static void term_source (j_decompress_ptr cinfo)
|
||||
static void term_source(j_decompress_ptr cinfo)
|
||||
{
|
||||
/* We don't actually need to do anything */
|
||||
return;
|
||||
@ -165,9 +166,10 @@ static void rtgui_jpeg_filerw_src_init(j_decompress_ptr cinfo, struct rtgui_file
|
||||
* This makes it unsafe to use this manager and a different source
|
||||
* manager serially with the same JPEG object. Caveat programmer.
|
||||
*/
|
||||
if (cinfo->src == NULL) { /* first time for this JPEG object? */
|
||||
if (cinfo->src == NULL) /* first time for this JPEG object? */
|
||||
{
|
||||
cinfo->src = (struct jpeg_source_mgr *)
|
||||
(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
(*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT,
|
||||
sizeof(rtgui_jpeg_source_mgr));
|
||||
src = (rtgui_jpeg_source_mgr *) cinfo->src;
|
||||
}
|
||||
@ -184,16 +186,16 @@ static void rtgui_jpeg_filerw_src_init(j_decompress_ptr cinfo, struct rtgui_file
|
||||
}
|
||||
|
||||
/* get line data of a jpeg image */
|
||||
static rt_uint8_t *rtgui_image_get_line(struct rtgui_image* image, int h)
|
||||
static rt_uint8_t *rtgui_image_get_line(struct rtgui_image *image, int h)
|
||||
{
|
||||
struct rtgui_image_jpeg* jpeg;
|
||||
struct rtgui_image_jpeg *jpeg;
|
||||
rt_uint8_t *result_ptr;
|
||||
|
||||
JSAMPARRAY buffer; /* Output row buffer */
|
||||
int row_stride;
|
||||
|
||||
RT_ASSERT(image != RT_NULL);
|
||||
jpeg = (struct rtgui_image_jpeg*) image->data;
|
||||
jpeg = (struct rtgui_image_jpeg *) image->data;
|
||||
RT_ASSERT(jpeg != RT_NULL);
|
||||
|
||||
if (h < 0 || h > image->h) return RT_NULL;
|
||||
@ -222,22 +224,22 @@ static rt_uint8_t *rtgui_image_get_line(struct rtgui_image* image, int h)
|
||||
int index;
|
||||
rtgui_color_t *ptr;
|
||||
|
||||
ptr = (rtgui_color_t*)jpeg->line_pixels;
|
||||
ptr = (rtgui_color_t *)jpeg->line_pixels;
|
||||
for (index = 0; index < image->w; index ++)
|
||||
ptr[index] = RTGUI_ARGB(0, buffer[0][index*3], buffer[0][index*3+1], buffer[0][index*3+2]);
|
||||
ptr[index] = RTGUI_ARGB(0, buffer[0][index * 3], buffer[0][index * 3 + 1], buffer[0][index * 3 + 2]);
|
||||
}
|
||||
|
||||
return jpeg->line_pixels;
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_jpeg_loadall(struct rtgui_image* image)
|
||||
static rt_bool_t rtgui_image_jpeg_loadall(struct rtgui_image *image)
|
||||
{
|
||||
struct rtgui_image_jpeg* jpeg;
|
||||
rt_uint8_t* line_ptr;
|
||||
struct rtgui_image_jpeg *jpeg;
|
||||
rt_uint8_t *line_ptr;
|
||||
JSAMPARRAY buffer; /* Output row buffer */
|
||||
int row_stride;
|
||||
|
||||
jpeg = (struct rtgui_image_jpeg*) image->data;
|
||||
jpeg = (struct rtgui_image_jpeg *) image->data;
|
||||
RT_ASSERT(jpeg != RT_NULL);
|
||||
|
||||
/* already load */
|
||||
@ -269,9 +271,9 @@ static rt_bool_t rtgui_image_jpeg_loadall(struct rtgui_image* image)
|
||||
int index;
|
||||
rtgui_color_t *ptr;
|
||||
|
||||
ptr = (rtgui_color_t*)line_ptr;
|
||||
ptr = (rtgui_color_t *)line_ptr;
|
||||
for (index = 0; index < image->w; index ++)
|
||||
ptr[index] = RTGUI_ARGB(0, buffer[0][index*3], buffer[0][index*3+1], buffer[0][index*3+2]);
|
||||
ptr[index] = RTGUI_ARGB(0, buffer[0][index * 3], buffer[0][index * 3 + 1], buffer[0][index * 3 + 2]);
|
||||
}
|
||||
|
||||
/* move to next line */
|
||||
@ -303,11 +305,11 @@ static void output_no_message(j_common_ptr cinfo)
|
||||
/* do nothing */
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load)
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
|
||||
{
|
||||
struct rtgui_image_jpeg* jpeg;
|
||||
struct rtgui_image_jpeg *jpeg;
|
||||
|
||||
jpeg = (struct rtgui_image_jpeg*) rtgui_malloc(sizeof(struct rtgui_image_jpeg));
|
||||
jpeg = (struct rtgui_image_jpeg *) rtgui_malloc(sizeof(struct rtgui_image_jpeg));
|
||||
if (jpeg == RT_NULL) return RT_FALSE;
|
||||
|
||||
jpeg->filerw = file;
|
||||
@ -361,13 +363,13 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_f
|
||||
}
|
||||
|
||||
|
||||
static void rtgui_image_jpeg_unload(struct rtgui_image* image)
|
||||
static void rtgui_image_jpeg_unload(struct rtgui_image *image)
|
||||
{
|
||||
if (image != RT_NULL)
|
||||
{
|
||||
struct rtgui_image_jpeg* jpeg;
|
||||
struct rtgui_image_jpeg *jpeg;
|
||||
|
||||
jpeg = (struct rtgui_image_jpeg*) image->data;
|
||||
jpeg = (struct rtgui_image_jpeg *) image->data;
|
||||
RT_ASSERT(jpeg != RT_NULL);
|
||||
|
||||
if (jpeg->is_loaded == RT_TRUE)
|
||||
@ -383,20 +385,20 @@ static void rtgui_image_jpeg_unload(struct rtgui_image* image)
|
||||
}
|
||||
}
|
||||
|
||||
static void rtgui_image_jpeg_blit(struct rtgui_image* image, struct rtgui_dc* dc, struct rtgui_rect* rect)
|
||||
static void rtgui_image_jpeg_blit(struct rtgui_image *image, struct rtgui_dc *dc, struct rtgui_rect *rect)
|
||||
{
|
||||
rt_uint16_t x, y;
|
||||
rtgui_color_t* ptr;
|
||||
struct rtgui_image_jpeg* jpeg;
|
||||
rtgui_color_t *ptr;
|
||||
struct rtgui_image_jpeg *jpeg;
|
||||
|
||||
RT_ASSERT(image != RT_NULL && dc != RT_NULL && rect != RT_NULL);
|
||||
|
||||
jpeg = (struct rtgui_image_jpeg*) image->data;
|
||||
jpeg = (struct rtgui_image_jpeg *) image->data;
|
||||
RT_ASSERT(jpeg != RT_NULL);
|
||||
|
||||
if (jpeg->pixels != RT_NULL)
|
||||
{
|
||||
ptr = (rtgui_color_t*) jpeg->pixels;
|
||||
ptr = (rtgui_color_t *) jpeg->pixels;
|
||||
|
||||
/* draw each point within dc */
|
||||
for (y = 0; y < image->h; y ++)
|
||||
@ -417,12 +419,12 @@ static void rtgui_image_jpeg_blit(struct rtgui_image* image, struct rtgui_dc* dc
|
||||
else
|
||||
{
|
||||
/* seek to the begin of file */
|
||||
rtgui_filerw_seek(jpeg->filerw, 0, SEEK_SET);
|
||||
rtgui_filerw_seek(jpeg->filerw, 0, RTGUI_FILE_SEEK_SET);
|
||||
|
||||
/* decompress line and line */
|
||||
for (y = 0; y < image->h; y ++)
|
||||
{
|
||||
ptr = (rtgui_color_t*)rtgui_image_get_line(image, y);
|
||||
ptr = (rtgui_color_t *)rtgui_image_get_line(image, y);
|
||||
for (x = 0; x < image->w; x++)
|
||||
{
|
||||
/* not alpha */
|
||||
@ -438,7 +440,7 @@ static void rtgui_image_jpeg_blit(struct rtgui_image* image, struct rtgui_dc* dc
|
||||
}
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
|
||||
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file)
|
||||
{
|
||||
int start;
|
||||
rt_bool_t is_JPG;
|
||||
@ -452,39 +454,58 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
|
||||
in_scan = 0;
|
||||
|
||||
/* seek to the begining of file */
|
||||
rtgui_filerw_seek(file, 0, SEEK_SET);
|
||||
rtgui_filerw_seek(file, 0, RTGUI_FILE_SEEK_SET);
|
||||
|
||||
if ( rtgui_filerw_read(file, magic, 2, 1) ) {
|
||||
if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) {
|
||||
if (rtgui_filerw_read(file, magic, 2, 1))
|
||||
{
|
||||
if ((magic[0] == 0xFF) && (magic[1] == 0xD8))
|
||||
{
|
||||
is_JPG = RT_TRUE;
|
||||
while (is_JPG == RT_TRUE) {
|
||||
if(rtgui_filerw_read(file, magic, 1, 2) != 2) {
|
||||
while (is_JPG == RT_TRUE)
|
||||
{
|
||||
if (rtgui_filerw_read(file, magic, 1, 2) != 2)
|
||||
{
|
||||
is_JPG = RT_FALSE;
|
||||
} else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
|
||||
}
|
||||
else if ((magic[0] != 0xFF) && (in_scan == 0))
|
||||
{
|
||||
is_JPG = RT_FALSE;
|
||||
} else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) {
|
||||
}
|
||||
else if ((magic[0] != 0xFF) || (magic[1] == 0xFF))
|
||||
{
|
||||
/* Extra padding in JPEG (legal) */
|
||||
/* or this is data and we are scanning */
|
||||
rtgui_filerw_seek(file, -1, SEEK_CUR);
|
||||
} else if(magic[1] == 0xD9) {
|
||||
rtgui_filerw_seek(file, -1, RTGUI_FILE_SEEK_CUR);
|
||||
}
|
||||
else if (magic[1] == 0xD9)
|
||||
{
|
||||
/* Got to end of good JPEG */
|
||||
break;
|
||||
} else if( (in_scan == 1) && (magic[1] == 0x00) ) {
|
||||
}
|
||||
else if ((in_scan == 1) && (magic[1] == 0x00))
|
||||
{
|
||||
/* This is an encoded 0xFF within the data */
|
||||
} else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
|
||||
}
|
||||
else if ((magic[1] >= 0xD0) && (magic[1] < 0xD9))
|
||||
{
|
||||
/* These have nothing else */
|
||||
} else if(rtgui_filerw_read(file, magic+2, 1, 2) != 2) {
|
||||
}
|
||||
else if (rtgui_filerw_read(file, magic + 2, 1, 2) != 2)
|
||||
{
|
||||
is_JPG = RT_FALSE;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Yes, it's big-endian */
|
||||
rt_uint32_t start;
|
||||
rt_uint32_t size;
|
||||
rt_uint32_t end;
|
||||
start = rtgui_filerw_tell(file);
|
||||
size = (magic[2] << 8) + magic[3];
|
||||
end = rtgui_filerw_seek(file, size-2, SEEK_CUR);
|
||||
if ( end != start + size - 2 ) is_JPG = RT_FALSE;
|
||||
if ( magic[1] == 0xDA ) {
|
||||
end = rtgui_filerw_seek(file, size - 2, RTGUI_FILE_SEEK_CUR);
|
||||
if (end != start + size - 2) is_JPG = RT_FALSE;
|
||||
if (magic[1] == 0xDA)
|
||||
{
|
||||
/* Now comes the actual JPEG meat */
|
||||
/* It is a JPEG. */
|
||||
break;
|
||||
@ -493,7 +514,7 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
|
||||
}
|
||||
}
|
||||
}
|
||||
rtgui_filerw_seek(file, start, SEEK_SET);
|
||||
rtgui_filerw_seek(file, start, RTGUI_FILE_SEEK_SET);
|
||||
|
||||
return is_JPG;
|
||||
}
|
||||
@ -537,7 +558,7 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
struct rtgui_image_jpeg
|
||||
{
|
||||
struct rtgui_filerw* filerw;
|
||||
struct rtgui_filerw *filerw;
|
||||
struct rtgui_dc *dc;
|
||||
rt_uint16_t dst_x, dst_y;
|
||||
rt_uint16_t dst_w, dst_h;
|
||||
@ -558,15 +579,11 @@ struct rtgui_image_jpeg
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
/* static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file,
|
||||
rt_uint16_t *width, rt_uint16_t *height);
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image,
|
||||
struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load); */
|
||||
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file);
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load);
|
||||
static void rtgui_image_jpeg_unload(struct rtgui_image* image);
|
||||
static void rtgui_image_jpeg_blit(struct rtgui_image* image,
|
||||
struct rtgui_dc* dc, struct rtgui_rect* dst_rect);
|
||||
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file);
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load);
|
||||
static void rtgui_image_jpeg_unload(struct rtgui_image *image);
|
||||
static void rtgui_image_jpeg_blit(struct rtgui_image *image,
|
||||
struct rtgui_dc *dc, struct rtgui_rect *dst_rect);
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
struct rtgui_image_engine rtgui_image_jpeg_engine =
|
||||
@ -645,6 +662,14 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
|
||||
{
|
||||
rtgui_blit_line_func blit_line = RT_NULL;
|
||||
|
||||
/* we decompress from top to bottom if the block is beyond the right
|
||||
* boundary, just continue to next block. However, if the block is
|
||||
* beyond the bottom boundary, we don't need to decompress the rest. */
|
||||
if (rect->left > jpeg->dst_w)
|
||||
return 1;
|
||||
if (rect->top > jpeg->dst_h)
|
||||
return 0;
|
||||
|
||||
w = rect->right < jpeg->dst_w ? rect->right : jpeg->dst_w;
|
||||
w = w - rect->left + 1;
|
||||
h = rect->bottom < jpeg->dst_h ? rect->bottom : jpeg->dst_h;
|
||||
@ -669,7 +694,7 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
|
||||
{
|
||||
blit_line(line_buf, src, w * jpeg->byte_per_pixel);
|
||||
jpeg->dc->engine->blit_line(jpeg->dc,
|
||||
jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w - 1,
|
||||
jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w,
|
||||
jpeg->dst_y + rect->top + y,
|
||||
line_buf);
|
||||
src += rectWidth;
|
||||
@ -680,7 +705,7 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
jpeg->dc->engine->blit_line(jpeg->dc,
|
||||
jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w - 1,
|
||||
jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w,
|
||||
jpeg->dst_y + rect->top + y,
|
||||
src);
|
||||
src += rectWidth;
|
||||
@ -690,22 +715,20 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
|
||||
return 1; /* Continue to decompress */
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
|
||||
//static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file,
|
||||
// rt_uint32_t *width, rt_uint32_t *height)
|
||||
static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw *file)
|
||||
{
|
||||
rt_bool_t is_JPG;
|
||||
JDEC tjpgd;
|
||||
void *pool;
|
||||
|
||||
if (!file)
|
||||
{
|
||||
return RT_FALSE;
|
||||
}
|
||||
|
||||
is_JPG = RT_FALSE;
|
||||
do
|
||||
{
|
||||
if (!file )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
pool = rt_malloc(TJPGD_WORKING_BUFFER_SIZE);
|
||||
if (pool == RT_NULL)
|
||||
{
|
||||
@ -713,7 +736,7 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
|
||||
break;
|
||||
}
|
||||
|
||||
if (rtgui_filerw_seek(file, 0, SEEK_SET) == -1)
|
||||
if (rtgui_filerw_seek(file, 0, RTGUI_FILE_SEEK_SET) == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -721,24 +744,21 @@ static rt_bool_t rtgui_image_jpeg_check(struct rtgui_filerw* file)
|
||||
if (jd_prepare(&tjpgd, tjpgd_in_func, pool,
|
||||
TJPGD_WORKING_BUFFER_SIZE, (void *)&file) == JDR_OK)
|
||||
{
|
||||
// *width = (rt_uint32_t)tjpgd.width;
|
||||
// *height = (rt_uint32_t)tjpgd.height;
|
||||
is_JPG = RT_TRUE;
|
||||
}
|
||||
|
||||
rt_kprintf("TJPGD: check OK\n");
|
||||
} while(0);
|
||||
}
|
||||
while (0);
|
||||
|
||||
rt_free(pool);
|
||||
|
||||
return is_JPG;
|
||||
}
|
||||
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_filerw* file, rt_bool_t load)
|
||||
//static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image,
|
||||
// struct rtgui_filerw* file, rt_uint8_t scale, rt_bool_t load)
|
||||
static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image *image, struct rtgui_filerw *file, rt_bool_t load)
|
||||
{
|
||||
rt_uint8_t scale = 2;
|
||||
rt_uint8_t scale = 0;
|
||||
rt_bool_t res = RT_FALSE;
|
||||
struct rtgui_image_jpeg *jpeg;
|
||||
JRESULT ret;
|
||||
@ -774,7 +794,7 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_f
|
||||
break;
|
||||
}
|
||||
|
||||
if (rtgui_filerw_seek(jpeg->filerw, 0, SEEK_SET) == -1)
|
||||
if (rtgui_filerw_seek(jpeg->filerw, 0, RTGUI_FILE_SEEK_SET) == -1)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@ -821,7 +841,8 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_f
|
||||
rt_kprintf("TJPGD: load to RAM\n");
|
||||
}
|
||||
res = RT_TRUE;
|
||||
} while(0);
|
||||
}
|
||||
while (0);
|
||||
|
||||
if (!res || jpeg->is_loaded)
|
||||
{
|
||||
@ -838,13 +859,13 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_f
|
||||
}
|
||||
|
||||
|
||||
static void rtgui_image_jpeg_unload(struct rtgui_image* image)
|
||||
static void rtgui_image_jpeg_unload(struct rtgui_image *image)
|
||||
{
|
||||
if (image != RT_NULL)
|
||||
{
|
||||
struct rtgui_image_jpeg* jpeg;
|
||||
struct rtgui_image_jpeg *jpeg;
|
||||
|
||||
jpeg = (struct rtgui_image_jpeg*) image->data;
|
||||
jpeg = (struct rtgui_image_jpeg *) image->data;
|
||||
RT_ASSERT(jpeg != RT_NULL);
|
||||
|
||||
if (jpeg->to_buffer == RT_TRUE)
|
||||
@ -868,8 +889,8 @@ static void rtgui_image_jpeg_unload(struct rtgui_image* image)
|
||||
rt_kprintf("TJPGD: unload\n");
|
||||
}
|
||||
|
||||
static void rtgui_image_jpeg_blit(struct rtgui_image* image,
|
||||
struct rtgui_dc* dc, struct rtgui_rect* dst_rect)
|
||||
static void rtgui_image_jpeg_blit(struct rtgui_image *image,
|
||||
struct rtgui_dc *dc, struct rtgui_rect *dst_rect)
|
||||
{
|
||||
rt_uint16_t w, h, y;
|
||||
struct rtgui_image_jpeg *jpeg;
|
||||
@ -884,7 +905,7 @@ static void rtgui_image_jpeg_blit(struct rtgui_image* image,
|
||||
{
|
||||
break;
|
||||
}
|
||||
jpeg->dc= dc;
|
||||
jpeg->dc = dc;
|
||||
|
||||
/* the minimum rect */
|
||||
if (image->w < rtgui_rect_width(*dst_rect))
|
||||
@ -921,7 +942,7 @@ static void rtgui_image_jpeg_blit(struct rtgui_image* image,
|
||||
}
|
||||
else
|
||||
{
|
||||
rt_uint8_t* src = jpeg->pixels;
|
||||
rt_uint8_t *src = jpeg->pixels;
|
||||
rt_uint16_t imageWidth = image->w * jpeg->byte_per_pixel;
|
||||
rtgui_blit_line_func blit_line = RT_NULL;
|
||||
|
||||
@ -960,14 +981,15 @@ static void rtgui_image_jpeg_blit(struct rtgui_image* image,
|
||||
for (y = 0; y < h; y++)
|
||||
{
|
||||
dc->engine->blit_line(dc,
|
||||
dst_rect->x1, dst_rect->x1 + w - 1,
|
||||
dst_rect->x1, dst_rect->x1 + w,
|
||||
dst_rect->y1 + y,
|
||||
src);
|
||||
src += imageWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while(0);
|
||||
}
|
||||
while (0);
|
||||
}
|
||||
#endif /* defined(RTGUI_IMAGE_TJPGD) */
|
||||
/***************************************************************************//**
|
||||
|
@ -60,6 +60,7 @@ typedef struct rtgui_image rtgui_image_t;
|
||||
void rtgui_system_image_init(void);
|
||||
|
||||
#if defined(RTGUI_USING_DFS_FILERW) || defined(RTGUI_USING_STDIO_FILERW)
|
||||
struct rtgui_image_engine* rtgui_image_get_engine_by_filename(const char* fn);
|
||||
struct rtgui_image* rtgui_image_create_from_file(const char* type, const char* filename, rt_bool_t load);
|
||||
struct rtgui_image* rtgui_image_create(const char* filename, rt_bool_t load);
|
||||
#endif
|
||||
|
@ -34,6 +34,7 @@ struct rtgui_notebook* rtgui_notebook_create(const rtgui_rect_t* rect, rt_uint8_
|
||||
void rtgui_notebook_destroy(struct rtgui_notebook* notebook);
|
||||
|
||||
void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, struct rtgui_widget* child);
|
||||
void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index);
|
||||
struct rtgui_widget* rtgui_notebook_get_current(struct rtgui_notebook* notebook);
|
||||
rt_int16_t rtgui_notebook_get_current_index(struct rtgui_notebook* notebook);
|
||||
|
||||
|
@ -133,10 +133,6 @@ void rtgui_win_move(struct rtgui_win* win, int x, int y);
|
||||
/* reset extent of window */
|
||||
void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect);
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box);
|
||||
#endif
|
||||
|
||||
void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
|
||||
void rtgui_win_set_ondeactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler);
|
||||
void rtgui_win_set_onclose(rtgui_win_t* win, rtgui_event_handler_ptr handler);
|
||||
|
@ -231,6 +231,8 @@ void rtgui_notebook_add(struct rtgui_notebook* notebook, const char* label, stru
|
||||
void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
|
||||
{
|
||||
struct rtgui_notebook_tab tab;
|
||||
rt_bool_t need_update = RT_FALSE;
|
||||
|
||||
RT_ASSERT(notebook != RT_NULL);
|
||||
|
||||
if (index < notebook->count)
|
||||
@ -244,8 +246,11 @@ void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (notebook->current == index)
|
||||
need_update = RT_TRUE;
|
||||
|
||||
tab = notebook->childs[index];
|
||||
for (;index < notebook->count - 1; index ++)
|
||||
for (;index < notebook->count - 1; index++)
|
||||
{
|
||||
notebook->childs[index] = notebook->childs[index + 1];
|
||||
}
|
||||
@ -255,16 +260,17 @@ void rtgui_notebook_remove(struct rtgui_notebook* notebook, rt_uint16_t index)
|
||||
sizeof(struct rtgui_notebook_tab) * notebook->count);
|
||||
}
|
||||
|
||||
// FIXME: do we really want to destroy it?
|
||||
rtgui_widget_destroy(tab.widget);
|
||||
rtgui_free(tab.title);
|
||||
|
||||
if (notebook->current == index)
|
||||
if (need_update)
|
||||
{
|
||||
/* update tab */
|
||||
if (notebook->current > notebook->count - 1)
|
||||
notebook->current = notebook->count - 1;
|
||||
|
||||
rtgui_widget_hide(tab.widget);
|
||||
rtgui_widget_show(notebook->childs[notebook->current].widget);
|
||||
rtgui_widget_update(RTGUI_WIDGET(notebook));
|
||||
rtgui_widget_set_parent(tab.widget, RT_NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ static void _rtgui_widget_destructor(rtgui_widget_t *widget)
|
||||
{
|
||||
if (widget == RT_NULL) return;
|
||||
|
||||
if (widget->parent != RT_NULL)
|
||||
if (widget->parent != RT_NULL && RTGUI_IS_CONTAINER(widget->parent))
|
||||
{
|
||||
/* remove widget from parent's children list */
|
||||
rtgui_list_remove(&(RTGUI_CONTAINER(widget->parent)->children), &(widget->sibling));
|
||||
@ -413,8 +413,7 @@ rt_bool_t rtgui_widget_onupdate_toplvl(struct rtgui_object *object, struct rtgui
|
||||
|
||||
rt_bool_t rtgui_widget_event_handler(struct rtgui_object* object, rtgui_event_t* event)
|
||||
{
|
||||
RT_ASSERT(object != RT_NULL);
|
||||
RT_ASSERT(event != RT_NULL);
|
||||
RTGUI_WIDGET_EVENT_HANDLER_PREPARE;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
@ -538,9 +537,10 @@ rt_bool_t rtgui_widget_onshow(struct rtgui_object *object, struct rtgui_event *e
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
|
||||
/* update the clip info of widget */
|
||||
if (!RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(object)))
|
||||
return RT_FALSE;
|
||||
|
||||
RTGUI_WIDGET_UNHIDE(widget);
|
||||
rtgui_widget_update_clip(widget);
|
||||
|
||||
if (widget->on_show != RT_NULL)
|
||||
widget->on_show(RTGUI_OBJECT(widget), RT_NULL);
|
||||
@ -552,6 +552,9 @@ rt_bool_t rtgui_widget_onhide(struct rtgui_object *object, struct rtgui_event *e
|
||||
{
|
||||
struct rtgui_widget *widget = RTGUI_WIDGET(object);
|
||||
|
||||
if (RTGUI_WIDGET_IS_HIDE(RTGUI_WIDGET(object)))
|
||||
return RT_FALSE;
|
||||
|
||||
/* hide this widget */
|
||||
RTGUI_WIDGET_HIDE(widget);
|
||||
|
||||
|
@ -594,16 +594,6 @@ void rtgui_win_set_rect(rtgui_win_t* win, rtgui_rect_t* rect)
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef RTGUI_USING_SMALL_SIZE
|
||||
void rtgui_win_set_box(rtgui_win_t* win, rtgui_box_t* box)
|
||||
{
|
||||
if (win == RT_NULL || box == RT_NULL) return;
|
||||
|
||||
rtgui_container_add_child(RTGUI_CONTAINER(win), RTGUI_WIDGET(box));
|
||||
rtgui_widget_set_rect(RTGUI_WIDGET(box), &(RTGUI_WIDGET(win)->extent));
|
||||
}
|
||||
#endif
|
||||
|
||||
void rtgui_win_set_onactivate(rtgui_win_t* win, rtgui_event_handler_ptr handler)
|
||||
{
|
||||
if (win != RT_NULL)
|
||||
|
Loading…
x
Reference in New Issue
Block a user