summaryrefslogtreecommitdiff
path: root/components/rtgui
diff options
context:
space:
mode:
Diffstat (limited to 'components/rtgui')
-rw-r--r--components/rtgui/SConscript10
-rw-r--r--components/rtgui/common/filerw.c14
-rw-r--r--components/rtgui/common/image.c2
-rw-r--r--components/rtgui/common/image_bmp.c326
-rw-r--r--components/rtgui/common/image_jpg.c780
-rw-r--r--components/rtgui/include/rtgui/image.h1
-rw-r--r--components/rtgui/include/rtgui/widgets/notebook.h1
-rw-r--r--components/rtgui/include/rtgui/widgets/window.h4
-rw-r--r--components/rtgui/widgets/notebook.c16
-rw-r--r--components/rtgui/widgets/widget.c13
-rw-r--r--components/rtgui/widgets/window.c10
11 files changed, 599 insertions, 578 deletions
diff --git a/components/rtgui/SConscript b/components/rtgui/SConscript
index 0192454551..3aae1f0adb 100644
--- a/components/rtgui/SConscript
+++ b/components/rtgui/SConscript
@@ -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')
diff --git a/components/rtgui/common/filerw.c b/components/rtgui/common/filerw.c
index 8fd8073970..dd7ab18f20 100644
--- a/components/rtgui/common/filerw.c
+++ b/components/rtgui/common/filerw.c
@@ -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)
diff --git a/components/rtgui/common/image.c b/components/rtgui/common/image.c
index 358ba2bff5..424c684729 100644
--- a/components/rtgui/common/image.c
+++ b/components/rtgui/common/image.c
@@ -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;
diff --git a/components/rtgui/common/image_bmp.c b/components/rtgui/common/image_bmp.c
index b8519f3930..a5ef3e9e87 100644
--- a/components/rtgui/common/image_bmp.c
+++ b/components/rtgui/common/image_bmp.c
@@ -1,8 +1,8 @@
/*
* Change Logs:
* Date Author Notes
- * 2012-01-24 onelife Reimplement to improve efficiency and add
- * features. The new decoder uses configurable fixed size working buffer and
+ * 2012-01-24 onelife Reimplement to improve efficiency and add
+ * features. The new decoder uses configurable fixed size working buffer and
* provides scaledown function.
*/
#include <rtthread.h>
@@ -19,58 +19,53 @@
#ifdef RTGUI_IMAGE_BMP
/* Compression encodings for BMP files */
#ifndef BI_RGB
-#define BI_RGB 0
-#define BI_RLE8 1
-#define BI_RLE4 2
-#define BI_BITFIELDS 3
+#define BI_RGB 0
+#define BI_RLE8 1
+#define BI_RLE4 2
+#define BI_BITFIELDS 3
#endif
#define BMP_WORKING_BUFFER_SIZE (384) /* In multiple of 12 and bigger than 48 */
#define BMP_MAX_SCALING_FACTOR (10) // TODO: find the max value!
-#define hw_driver (rtgui_graphic_driver_get_default())
+#define hw_driver (rtgui_graphic_driver_get_default())
struct rtgui_image_bmp
{
- rt_bool_t is_loaded;
- rt_uint8_t *pixels;
- struct rtgui_filerw* filerw;
- rt_uint32_t w, h;
- rt_uint32_t pixel_offset;
- rt_uint32_t pitch; rt_uint8_t scale;
- rt_uint8_t bit_per_pixel;
- rt_uint8_t pad;
+ rt_bool_t is_loaded;
+ rt_uint8_t *pixels;
+ struct rtgui_filerw *filerw;
+ rt_uint32_t w, h;
+ rt_uint32_t pixel_offset;
+ 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 =
{
- "bmp",
- { RT_NULL },
- rtgui_image_bmp_check,
- rtgui_image_bmp_load,
- rtgui_image_bmp_unload,
- rtgui_image_bmp_blit
+ "bmp",
+ { RT_NULL },
+ rtgui_image_bmp_check,
+ rtgui_image_bmp_load,
+ rtgui_image_bmp_unload,
+ 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;
+ rt_uint8_t buffer[18];
+ rt_bool_t is_bmp = RT_FALSE;
do
{
- if (!file )
+ if (!file)
{
break;
}
@@ -85,47 +80,46 @@ static rt_bool_t rtgui_image_bmp_check(struct rtgui_filerw* file)
break;
}
/* Read file type */
- if (buffer[0] != 'B' || buffer[1] != 'M')
- {
- break;
- }
+ if (buffer[0] != 'B' || buffer[1] != 'M')
+ {
+ break;
+ }
/* 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;
+ 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)
{
- /* Load the palette, if any */
- rt_uint32_t i;
- struct rtgui_image_palette *palette;
+ /* Load the palette, if any */
+ rt_uint32_t i;
+ struct rtgui_image_palette *palette;
palette = rtgui_image_palette_create(colorsUsed);
if (palette == RT_NULL)
@@ -135,41 +129,39 @@ static struct rtgui_image_palette* rtgui_image_bmp_load_palette(
if (alpha)
{
- rt_uint8_t temp[4];
- for (i = 0; i < colorsUsed; i++)
- {
+ 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]);
- }
+ 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++)
- {
+ 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]);
- }
+ palette->colors[i] = RTGUI_RGB(temp[2], temp[1], temp[0]);
+ }
}
- return 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;
@@ -203,10 +195,10 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
break;
}
/* Read file type */
- if (wrkBuffer[0] != 'B' || wrkBuffer[1] != 'M')
- {
- break;
- }
+ if (wrkBuffer[0] != 'B' || wrkBuffer[1] != 'M')
+ {
+ break;
+ }
// rt_kprintf("BMP: format ok\n");
/* Read pixel array offset */
bmp->pixel_offset = *(rt_uint32_t *)&wrkBuffer[10];
@@ -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");
@@ -269,7 +263,7 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
}
image->palette = rtgui_image_bmp_load_palette(file, colorsUsed,
- bmpHeaderSize > 12 ? RT_TRUE : RT_FALSE);
+ bmpHeaderSize > 12 ? RT_TRUE : RT_FALSE);
if (image->palette == RT_NULL)
{
break;
@@ -281,11 +275,11 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
bmp->scale = scale;
if (bmp->bit_per_pixel == 1)
{
- bmp->pitch = (bmp->w + 7) >> 3;
+ bmp->pitch = (bmp->w + 7) >> 3;
}
else if (bmp->bit_per_pixel == 4)
{
- bmp->pitch = (bmp->w + 1) >> 1;
+ bmp->pitch = (bmp->w + 1) >> 1;
}
else
{
@@ -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)
@@ -374,7 +368,7 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
/* Read data to buffer */
readLength = (BMP_WORKING_BUFFER_SIZE > (bmp->pitch - readIndex)) ? \
- (bmp->pitch - readIndex) : BMP_WORKING_BUFFER_SIZE;
+ (bmp->pitch - readIndex) : BMP_WORKING_BUFFER_SIZE;
if (rtgui_filerw_read(file, (void *)wrkBuffer, 1, readLength) != readLength)
{
rt_kprintf("BMP err: read failed\n");
@@ -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;
@@ -457,7 +451,7 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
if (bmp->scale)
{
if (rtgui_filerw_seek(file, (bmp->pitch + bmp->pad) * ((1 << bmp->scale) - 1),
- RTGUI_FILE_SEEK_CUR) < 0)
+ RTGUI_FILE_SEEK_CUR) < 0)
{
error = RT_TRUE;
break;
@@ -475,48 +469,49 @@ static rt_bool_t rtgui_image_bmp_load(struct rtgui_image* image, struct rtgui_fi
// rt_kprintf("BMP: load to RAM\n");
}
- /* Release memory */
+ /* Release memory */
rt_free(wrkBuffer);
- return RT_TRUE;
- } while(0);
+ return RT_TRUE;
+ }
+ while (0);
/* Release memory */
rt_free(wrkBuffer);
- rtgui_free(image->palette);
- rtgui_free(bmp->pixels);
- rtgui_free(bmp);
- return RT_FALSE;
+ rtgui_free(image->palette);
+ rtgui_free(bmp->pixels);
+ rtgui_free(bmp);
+ 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;
+ if (image != RT_NULL)
+ {
+ bmp = (struct rtgui_image_bmp *)image->data;
- /* Release memory */
- rtgui_free(bmp->pixels);
- if (bmp->filerw != RT_NULL)
- {
+ /* Release memory */
+ rtgui_free(bmp->pixels);
+ if (bmp->filerw != RT_NULL)
+ {
/* Close file */
- rtgui_filerw_close(bmp->filerw);
- bmp->filerw = RT_NULL;
- }
- rtgui_free(bmp);
- }
+ rtgui_filerw_close(bmp->filerw);
+ bmp->filerw = RT_NULL;
+ }
+ rtgui_free(bmp);
+ }
}
-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,23 +602,32 @@ 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)) ? \
- (bmp->pitch - readIndex) : BMP_WORKING_BUFFER_SIZE;
+ (bmp->pitch - readIndex) : BMP_WORKING_BUFFER_SIZE;
if (rtgui_filerw_read(bmp->filerw, (void *)wrkBuffer, 1, readLength) != readLength)
{
rt_kprintf("BMP err: read failed\n");
@@ -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,
- color);
+ dst_rect->x1 + x++,
+ 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,
- color);
+ dst_rect->x1 + x++,
+ 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,
- color);
+ dst_rect->x1 + x++,
+ y_start - y,
+ color);
+ if (x >= w)
+ break;
}
if (readLength % (1 << bmp->scale))
{
@@ -707,15 +720,17 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
}
for (loadIndex = skipLength;
- loadIndex < readLength;
- loadIndex += bytePerPixel << bmp->scale)
+ loadIndex < readLength;
+ loadIndex += bytePerPixel << bmp->scale)
{
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,
- temp);
+ dst_rect->x1 + x, dst_rect->x1 + x + 1,
+ 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;
@@ -743,7 +758,7 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
if (bmp->scale)
{
if (rtgui_filerw_seek(bmp->filerw, (bmp->pitch + bmp->pad) * ((1 << bmp->scale) - 1),
- RTGUI_FILE_SEEK_CUR) < 0)
+ 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 ++)
{
@@ -775,9 +790,9 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
{
color = image->palette->colors[*(ptr++)];
rtgui_dc_draw_color_point(dc,
- dst_rect->x1 + x,
- dst_rect->y1 + y,
- color);
+ dst_rect->x1 + x,
+ dst_rect->y1 + y,
+ color);
}
}
else
@@ -805,20 +820,21 @@ static void rtgui_image_bmp_blit(struct rtgui_image* image, struct rtgui_dc* dc,
blit_line(temp, ptr, bytePerPixel);
ptr += bytePerPixel;
dc->engine->blit_line(dc,
- dst_rect->x1 + x, dst_rect->x1 + x + 1,
- dst_rect->y1 + y,
- temp);
+ dst_rect->x1 + x, dst_rect->x1 + x + 1,
+ dst_rect->y1 + y,
+ temp);
}
}
}
}
// rt_kprintf("BMP: blit ok\n");
- } while(0);
+ }
+ while (0);
}
void rtgui_image_bmp_init()
{
- /* register bmp on image system */
- rtgui_image_register_engine(&rtgui_image_bmp_engine);
+ /* register bmp on image system */
+ rtgui_image_register_engine(&rtgui_image_bmp_engine);
}
#endif
diff --git a/components/rtgui/common/image_jpg.c b/components/rtgui/common/image_jpg.c
index 0980fc68d1..1710c06360 100644
--- a/components/rtgui/common/image_jpg.c
+++ b/components/rtgui/common/image_jpg.c
@@ -19,89 +19,90 @@
#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
{
- struct jpeg_error_mgr pub; /* "public" fields */
+ struct jpeg_error_mgr pub; /* "public" fields */
};
struct rtgui_image_jpeg
{
- rt_bool_t is_loaded;
+ rt_bool_t is_loaded;
- struct rtgui_filerw* filerw;
+ struct rtgui_filerw *filerw;
- /* jpeg structure */
- struct jpeg_decompress_struct cinfo;
- struct rtgui_jpeg_error_mgr errmgr;
+ /* jpeg structure */
+ struct jpeg_decompress_struct cinfo;
+ struct rtgui_jpeg_error_mgr errmgr;
- rt_uint8_t *pixels;
- rt_uint8_t *line_pixels;
+ rt_uint8_t *pixels;
+ rt_uint8_t *line_pixels;
};
struct rtgui_image_engine rtgui_image_jpeg_engine =
{
- "jpeg",
- {RT_NULL},
- rtgui_image_jpeg_check,
- rtgui_image_jpeg_load,
- rtgui_image_jpeg_unload,
- rtgui_image_jpeg_blit
+ "jpeg",
+ {RT_NULL},
+ rtgui_image_jpeg_check,
+ rtgui_image_jpeg_load,
+ rtgui_image_jpeg_unload,
+ rtgui_image_jpeg_blit
};
struct rtgui_image_engine rtgui_image_jpg_engine =
{
- "jpg",
- {RT_NULL},
- rtgui_image_jpeg_check,
- rtgui_image_jpeg_load,
- rtgui_image_jpeg_unload,
- rtgui_image_jpeg_blit
+ "jpg",
+ {RT_NULL},
+ rtgui_image_jpeg_check,
+ rtgui_image_jpeg_load,
+ rtgui_image_jpeg_unload,
+ rtgui_image_jpeg_blit
};
-#define INPUT_BUFFER_SIZE 4096
-typedef struct {
- struct jpeg_source_mgr pub;
+#define INPUT_BUFFER_SIZE 4096
+typedef struct
+{
+ struct jpeg_source_mgr pub;
- struct rtgui_filerw* ctx;
- rt_uint8_t buffer[INPUT_BUFFER_SIZE];
+ struct rtgui_filerw *ctx;
+ rt_uint8_t buffer[INPUT_BUFFER_SIZE];
} rtgui_jpeg_source_mgr;
/*
* 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;
+ /* We don't actually need to do anything */
+ return;
}
/*
* 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;
- int nbytes;
+ 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);
- if (nbytes <= 0)
- {
- /* Insert a fake EOI marker */
- src->buffer[0] = (rt_uint8_t) 0xFF;
- src->buffer[1] = (rt_uint8_t) JPEG_EOI;
- nbytes = 2;
- }
+ nbytes = rtgui_filerw_read(src->ctx, src->buffer, 1, INPUT_BUFFER_SIZE);
+ if (nbytes <= 0)
+ {
+ /* Insert a fake EOI marker */
+ src->buffer[0] = (rt_uint8_t) 0xFF;
+ src->buffer[1] = (rt_uint8_t) JPEG_EOI;
+ nbytes = 2;
+ }
- src->pub.next_input_byte = src->buffer;
- src->pub.bytes_in_buffer = nbytes;
+ src->pub.next_input_byte = src->buffer;
+ src->pub.bytes_in_buffer = nbytes;
- return TRUE;
+ return TRUE;
}
@@ -116,37 +117,37 @@ 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
- * any trouble anyway --- large skips are infrequent.
- */
- if (num_bytes > 0)
- {
- while (num_bytes > (long) src->pub.bytes_in_buffer)
- {
- num_bytes -= (long) src->pub.bytes_in_buffer;
- (void) src->pub.fill_input_buffer(cinfo);
- /* note we assume that fill_input_buffer will never
- * return FALSE, so suspension need not be handled.
- */
- }
- src->pub.next_input_byte += (size_t) num_bytes;
- src->pub.bytes_in_buffer -= (size_t) num_bytes;
- }
+ /* Just a dumb implementation for now. Could use fseek() except
+ * it doesn't work on pipes. Not clear that being smart is worth
+ * any trouble anyway --- large skips are infrequent.
+ */
+ if (num_bytes > 0)
+ {
+ while (num_bytes > (long) src->pub.bytes_in_buffer)
+ {
+ num_bytes -= (long) src->pub.bytes_in_buffer;
+ (void) src->pub.fill_input_buffer(cinfo);
+ /* note we assume that fill_input_buffer will never
+ * return FALSE, so suspension need not be handled.
+ */
+ }
+ src->pub.next_input_byte += (size_t) num_bytes;
+ src->pub.bytes_in_buffer -= (size_t) 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;
+ /* We don't actually need to do anything */
+ return;
}
/*
@@ -156,142 +157,143 @@ static void term_source (j_decompress_ptr cinfo)
*/
static void rtgui_jpeg_filerw_src_init(j_decompress_ptr cinfo, struct rtgui_filerw *ctx)
{
- rtgui_jpeg_source_mgr *src;
+ rtgui_jpeg_source_mgr *src;
- /* The source object and input buffer are made permanent so that a series
- * of JPEG images can be read from the same file by calling jpeg_stdio_src
- * only before the first one. (If we discarded the buffer at the end of
- * one image, we'd likely lose the start of the next one.)
- * 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? */
- cinfo->src = (struct jpeg_source_mgr *)
- (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
- sizeof(rtgui_jpeg_source_mgr));
- src = (rtgui_jpeg_source_mgr *) cinfo->src;
- }
+ /* The source object and input buffer are made permanent so that a series
+ * of JPEG images can be read from the same file by calling jpeg_stdio_src
+ * only before the first one. (If we discarded the buffer at the end of
+ * one image, we'd likely lose the start of the next one.)
+ * 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? */
+ {
+ cinfo->src = (struct jpeg_source_mgr *)
+ (*cinfo->mem->alloc_small)((j_common_ptr) cinfo, JPOOL_PERMANENT,
+ sizeof(rtgui_jpeg_source_mgr));
+ src = (rtgui_jpeg_source_mgr *) cinfo->src;
+ }
- src = (rtgui_jpeg_source_mgr *) cinfo->src;
- src->pub.init_source = init_source;
- src->pub.fill_input_buffer = fill_input_buffer;
- src->pub.skip_input_data = skip_input_data;
- src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
- src->pub.term_source = term_source;
- src->ctx = ctx;
- src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
- src->pub.next_input_byte = NULL; /* until buffer loaded */
+ src = (rtgui_jpeg_source_mgr *) cinfo->src;
+ src->pub.init_source = init_source;
+ src->pub.fill_input_buffer = fill_input_buffer;
+ src->pub.skip_input_data = skip_input_data;
+ src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
+ src->pub.term_source = term_source;
+ src->ctx = ctx;
+ src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
+ src->pub.next_input_byte = NULL; /* until buffer loaded */
}
/* 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;
- rt_uint8_t *result_ptr;
+ struct rtgui_image_jpeg *jpeg;
+ rt_uint8_t *result_ptr;
- JSAMPARRAY buffer; /* Output row buffer */
- int row_stride;
+ JSAMPARRAY buffer; /* Output row buffer */
+ int row_stride;
- RT_ASSERT(image != RT_NULL);
- jpeg = (struct rtgui_image_jpeg*) image->data;
- RT_ASSERT(jpeg != RT_NULL);
+ RT_ASSERT(image != RT_NULL);
+ jpeg = (struct rtgui_image_jpeg *) image->data;
+ RT_ASSERT(jpeg != RT_NULL);
- if (h < 0 || h > image->h) return RT_NULL;
+ if (h < 0 || h > image->h) return RT_NULL;
- /* if the image is loaded, */
- if (jpeg->is_loaded == RT_TRUE)
- {
- result_ptr = jpeg->pixels + (image->w * sizeof(rtgui_color_t)) * h;
+ /* if the image is loaded, */
+ if (jpeg->is_loaded == RT_TRUE)
+ {
+ result_ptr = jpeg->pixels + (image->w * sizeof(rtgui_color_t)) * h;
- return result_ptr;
- }
+ return result_ptr;
+ }
- if (jpeg->line_pixels == RT_NULL)
- jpeg->line_pixels = rtgui_malloc(image->w * sizeof(rtgui_color_t));
+ if (jpeg->line_pixels == RT_NULL)
+ jpeg->line_pixels = rtgui_malloc(image->w * sizeof(rtgui_color_t));
- row_stride = jpeg->cinfo.output_width * jpeg->cinfo.output_components;
- buffer = (*jpeg->cinfo.mem->alloc_sarray)
- ((j_common_ptr) &jpeg->cinfo, JPOOL_IMAGE, row_stride, 1);
+ row_stride = jpeg->cinfo.output_width * jpeg->cinfo.output_components;
+ buffer = (*jpeg->cinfo.mem->alloc_sarray)
+ ((j_common_ptr) &jpeg->cinfo, JPOOL_IMAGE, row_stride, 1);
- /* decompress line data */
- jpeg->cinfo.output_scanline = h;
- jpeg_read_scanlines(&jpeg->cinfo, buffer, (JDIMENSION) 1);
+ /* decompress line data */
+ jpeg->cinfo.output_scanline = h;
+ jpeg_read_scanlines(&jpeg->cinfo, buffer, (JDIMENSION) 1);
- /* copy pixels memory */
- {
- int index;
- rtgui_color_t *ptr;
+ /* copy pixels memory */
+ {
+ int index;
+ rtgui_color_t *ptr;
- 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 = (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]);
+ }
- return jpeg->line_pixels;
+ 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;
- JSAMPARRAY buffer; /* Output row buffer */
- int row_stride;
+ 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;
- RT_ASSERT(jpeg != RT_NULL);
+ jpeg = (struct rtgui_image_jpeg *) image->data;
+ RT_ASSERT(jpeg != RT_NULL);
- /* already load */
- if (jpeg->pixels != RT_NULL) return RT_TRUE;
+ /* already load */
+ if (jpeg->pixels != RT_NULL) return RT_TRUE;
- /* allocate all pixels */
- jpeg->pixels = rtgui_malloc(image->h * image->w * sizeof(rtgui_color_t));
- if (jpeg->pixels == RT_NULL) return RT_FALSE;
+ /* allocate all pixels */
+ jpeg->pixels = rtgui_malloc(image->h * image->w * sizeof(rtgui_color_t));
+ if (jpeg->pixels == RT_NULL) return RT_FALSE;
- /* reset scan line to zero */
- jpeg->cinfo.output_scanline = 0;
- line_ptr = jpeg->pixels;
+ /* reset scan line to zero */
+ jpeg->cinfo.output_scanline = 0;
+ line_ptr = jpeg->pixels;
- row_stride = jpeg->cinfo.output_width * jpeg->cinfo.output_components;
- buffer = (*jpeg->cinfo.mem->alloc_sarray)
- ((j_common_ptr) &jpeg->cinfo, JPOOL_IMAGE, row_stride, 1);
+ row_stride = jpeg->cinfo.output_width * jpeg->cinfo.output_components;
+ buffer = (*jpeg->cinfo.mem->alloc_sarray)
+ ((j_common_ptr) &jpeg->cinfo, JPOOL_IMAGE, row_stride, 1);
- /* decompress all pixels */
- while (jpeg->cinfo.output_scanline < jpeg->cinfo.output_height)
- {
- /* jpeg_read_scanlines expects an array of pointers to scanlines.
- * Here the array is only one element long, but you could ask for
- * more than one scanline at a time if that's more convenient.
- */
- (void) jpeg_read_scanlines(&jpeg->cinfo, buffer, 1);
+ /* decompress all pixels */
+ while (jpeg->cinfo.output_scanline < jpeg->cinfo.output_height)
+ {
+ /* jpeg_read_scanlines expects an array of pointers to scanlines.
+ * Here the array is only one element long, but you could ask for
+ * more than one scanline at a time if that's more convenient.
+ */
+ (void) jpeg_read_scanlines(&jpeg->cinfo, buffer, 1);
- /* copy pixels memory */
- {
- int index;
- rtgui_color_t *ptr;
+ /* copy pixels memory */
+ {
+ int index;
+ rtgui_color_t *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 = (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]);
+ }
- /* move to next line */
- line_ptr += image->w * sizeof(rtgui_color_t);
- }
+ /* move to next line */
+ line_ptr += image->w * sizeof(rtgui_color_t);
+ }
- /* decompress done */
- rtgui_filerw_close(jpeg->filerw);
- jpeg_finish_decompress(&jpeg->cinfo);
+ /* decompress done */
+ rtgui_filerw_close(jpeg->filerw);
+ jpeg_finish_decompress(&jpeg->cinfo);
- jpeg->is_loaded = RT_TRUE;
- return RT_TRUE;
+ jpeg->is_loaded = RT_TRUE;
+ return RT_TRUE;
}
void rtgui_image_jpeg_init()
{
- /* register jpeg on image system */
- rtgui_image_register_engine(&rtgui_image_jpeg_engine);
- /* register jpg on image system */
- rtgui_image_register_engine(&rtgui_image_jpg_engine);
+ /* register jpeg on image system */
+ rtgui_image_register_engine(&rtgui_image_jpeg_engine);
+ /* register jpg on image system */
+ rtgui_image_register_engine(&rtgui_image_jpg_engine);
}
static void my_error_exit(j_common_ptr cinfo)
@@ -300,202 +302,221 @@ static void my_error_exit(j_common_ptr cinfo)
static void output_no_message(j_common_ptr cinfo)
{
- /* do nothing */
+ /* 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));
- if (jpeg == RT_NULL) return RT_FALSE;
+ jpeg = (struct rtgui_image_jpeg *) rtgui_malloc(sizeof(struct rtgui_image_jpeg));
+ if (jpeg == RT_NULL) return RT_FALSE;
- jpeg->filerw = file;
+ jpeg->filerw = file;
- /* read file header */
- /* Create a decompression structure and load the JPEG header */
- jpeg->cinfo.err = jpeg_std_error(&jpeg->errmgr.pub);
- jpeg->errmgr.pub.error_exit = my_error_exit;
- jpeg->errmgr.pub.output_message = output_no_message;
+ /* read file header */
+ /* Create a decompression structure and load the JPEG header */
+ jpeg->cinfo.err = jpeg_std_error(&jpeg->errmgr.pub);
+ jpeg->errmgr.pub.error_exit = my_error_exit;
+ jpeg->errmgr.pub.output_message = output_no_message;
- jpeg_create_decompress(&jpeg->cinfo);
- rtgui_jpeg_filerw_src_init(&jpeg->cinfo, jpeg->filerw);
- (void)jpeg_read_header(&jpeg->cinfo, TRUE);
+ jpeg_create_decompress(&jpeg->cinfo);
+ rtgui_jpeg_filerw_src_init(&jpeg->cinfo, jpeg->filerw);
+ (void)jpeg_read_header(&jpeg->cinfo, TRUE);
- image->w = jpeg->cinfo.image_width;
- image->h = jpeg->cinfo.image_height;
+ image->w = jpeg->cinfo.image_width;
+ image->h = jpeg->cinfo.image_height;
- /* set image private data and engine */
- image->data = jpeg;
- image->engine = &rtgui_image_jpeg_engine;
+ /* set image private data and engine */
+ image->data = jpeg;
+ image->engine = &rtgui_image_jpeg_engine;
- /* start decompression */
- (void) jpeg_start_decompress(&jpeg->cinfo);
+ /* start decompression */
+ (void) jpeg_start_decompress(&jpeg->cinfo);
- jpeg->cinfo.out_color_space = JCS_RGB;
- jpeg->cinfo.quantize_colors = FALSE;
- /* use fast jpeg */
- jpeg->cinfo.scale_num = 1;
- jpeg->cinfo.scale_denom = 1;
- jpeg->cinfo.dct_method = JDCT_FASTEST;
- jpeg->cinfo.do_fancy_upsampling = FALSE;
+ jpeg->cinfo.out_color_space = JCS_RGB;
+ jpeg->cinfo.quantize_colors = FALSE;
+ /* use fast jpeg */
+ jpeg->cinfo.scale_num = 1;
+ jpeg->cinfo.scale_denom = 1;
+ jpeg->cinfo.dct_method = JDCT_FASTEST;
+ jpeg->cinfo.do_fancy_upsampling = FALSE;
- jpeg->pixels = RT_NULL;
- jpeg->is_loaded = RT_FALSE;
+ jpeg->pixels = RT_NULL;
+ jpeg->is_loaded = RT_FALSE;
- /* allocate line pixels */
- jpeg->line_pixels = rtgui_malloc(image->w * sizeof(rtgui_color_t));
- if (jpeg->line_pixels == RT_NULL)
- {
- /* no memory */
- jpeg_finish_decompress(&jpeg->cinfo);
- rt_free(jpeg);
+ /* allocate line pixels */
+ jpeg->line_pixels = rtgui_malloc(image->w * sizeof(rtgui_color_t));
+ if (jpeg->line_pixels == RT_NULL)
+ {
+ /* no memory */
+ jpeg_finish_decompress(&jpeg->cinfo);
+ rt_free(jpeg);
- return RT_FALSE;
- }
+ return RT_FALSE;
+ }
- if (load == RT_TRUE) rtgui_image_jpeg_loadall(image);
+ if (load == RT_TRUE) rtgui_image_jpeg_loadall(image);
- /* create jpeg image successful */
- return RT_TRUE;
+ /* create jpeg image successful */
+ return RT_TRUE;
}
-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;
+ if (image != RT_NULL)
+ {
+ struct rtgui_image_jpeg *jpeg;
- jpeg = (struct rtgui_image_jpeg*) image->data;
- RT_ASSERT(jpeg != RT_NULL);
+ jpeg = (struct rtgui_image_jpeg *) image->data;
+ RT_ASSERT(jpeg != RT_NULL);
- if (jpeg->is_loaded == RT_TRUE)
- rtgui_free(jpeg->pixels);
- if (jpeg->line_pixels != RT_NULL) rtgui_free(jpeg->line_pixels);
+ if (jpeg->is_loaded == RT_TRUE)
+ rtgui_free(jpeg->pixels);
+ if (jpeg->line_pixels != RT_NULL) rtgui_free(jpeg->line_pixels);
- if (jpeg->is_loaded != RT_TRUE)
- {
- rtgui_filerw_close(jpeg->filerw);
- jpeg_finish_decompress(&jpeg->cinfo);
- }
- rt_free(jpeg);
- }
+ if (jpeg->is_loaded != RT_TRUE)
+ {
+ rtgui_filerw_close(jpeg->filerw);
+ jpeg_finish_decompress(&jpeg->cinfo);
+ }
+ rt_free(jpeg);
+ }
}
-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;
+ rt_uint16_t x, y;
+ rtgui_color_t *ptr;
+ struct rtgui_image_jpeg *jpeg;
- RT_ASSERT(image != RT_NULL && dc != RT_NULL && rect != RT_NULL);
+ RT_ASSERT(image != RT_NULL && dc != RT_NULL && rect != RT_NULL);
- jpeg = (struct rtgui_image_jpeg*) image->data;
- RT_ASSERT(jpeg != RT_NULL);
+ jpeg = (struct rtgui_image_jpeg *) image->data;
+ RT_ASSERT(jpeg != RT_NULL);
- if (jpeg->pixels != RT_NULL)
- {
- ptr = (rtgui_color_t*) jpeg->pixels;
+ if (jpeg->pixels != RT_NULL)
+ {
+ ptr = (rtgui_color_t *) jpeg->pixels;
- /* draw each point within dc */
- for (y = 0; y < image->h; y ++)
- {
- for (x = 0; x < image->w; x++)
- {
- /* not alpha */
- if ((*ptr >> 24) != 255)
- {
- rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, *ptr);
- }
+ /* draw each point within dc */
+ for (y = 0; y < image->h; y ++)
+ {
+ for (x = 0; x < image->w; x++)
+ {
+ /* not alpha */
+ if ((*ptr >> 24) != 255)
+ {
+ rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, *ptr);
+ }
- /* move to next color buffer */
- ptr ++;
- }
- }
- }
- else
- {
- /* seek to the begin of file */
- rtgui_filerw_seek(jpeg->filerw, 0, SEEK_SET);
+ /* move to next color buffer */
+ ptr ++;
+ }
+ }
+ }
+ else
+ {
+ /* seek to the begin of file */
+ 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);
- for (x = 0; x < image->w; x++)
- {
- /* not alpha */
- if ((*ptr >> 24) != 255)
- {
- rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, *ptr);
- }
+ /* decompress line and line */
+ for (y = 0; y < image->h; y ++)
+ {
+ ptr = (rtgui_color_t *)rtgui_image_get_line(image, y);
+ for (x = 0; x < image->w; x++)
+ {
+ /* not alpha */
+ if ((*ptr >> 24) != 255)
+ {
+ rtgui_dc_draw_color_point(dc, x + rect->x1, y + rect->y1, *ptr);
+ }
- /* move to next color buffer */
- ptr ++;
- }
- }
- }
+ /* move to next color buffer */
+ ptr ++;
+ }
+ }
+ }
}
-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;
- int in_scan;
- rt_uint8_t magic[4];
+ int start;
+ rt_bool_t is_JPG;
+ int in_scan;
+ rt_uint8_t magic[4];
- if (file == RT_NULL) return RT_FALSE; /* open file failed */
+ if (file == RT_NULL) return RT_FALSE; /* open file failed */
+
+ start = rtgui_filerw_tell(file);
+ is_JPG = RT_FALSE;
+ in_scan = 0;
- start = rtgui_filerw_tell(file);
- is_JPG = RT_FALSE;
- in_scan = 0;
+ /* seek to the begining of file */
+ rtgui_filerw_seek(file, 0, RTGUI_FILE_SEEK_SET);
- /* seek to the begining of file */
- rtgui_filerw_seek(file, 0, SEEK_SET);
-
- 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) {
- is_JPG = RT_FALSE;
- } else if( (magic[0] != 0xFF) && (in_scan == 0) ) {
- is_JPG = RT_FALSE;
- } 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) {
- /* Got to end of good JPEG */
- break;
- } else if( (in_scan == 1) && (magic[1] == 0x00) ) {
- /* This is an encoded 0xFF within the data */
- } else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) {
- /* These have nothing else */
- } else if(rtgui_filerw_read(file, magic+2, 1, 2) != 2) {
- is_JPG = RT_FALSE;
- } 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 ) {
- /* Now comes the actual JPEG meat */
- /* It is a JPEG. */
- break;
- }
- }
- }
- }
- }
- rtgui_filerw_seek(file, start, SEEK_SET);
+ 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)
+ {
+ is_JPG = RT_FALSE;
+ }
+ else if ((magic[0] != 0xFF) && (in_scan == 0))
+ {
+ is_JPG = RT_FALSE;
+ }
+ 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, RTGUI_FILE_SEEK_CUR);
+ }
+ else if (magic[1] == 0xD9)
+ {
+ /* Got to end of good JPEG */
+ break;
+ }
+ else if ((in_scan == 1) && (magic[1] == 0x00))
+ {
+ /* This is an encoded 0xFF within the data */
+ }
+ else if ((magic[1] >= 0xD0) && (magic[1] < 0xD9))
+ {
+ /* These have nothing else */
+ }
+ else if (rtgui_filerw_read(file, magic + 2, 1, 2) != 2)
+ {
+ is_JPG = RT_FALSE;
+ }
+ 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, 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;
+ }
+ }
+ }
+ }
+ }
+ rtgui_filerw_seek(file, start, RTGUI_FILE_SEEK_SET);
- return is_JPG;
+ return is_JPG;
}
#endif
@@ -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 =
@@ -633,7 +650,7 @@ static UINT tjpgd_out_func(JDEC *jdec, void *bitmap, JRECT *rect)
imageWidth = (jdec->width >> jdec->scale) * jpeg->byte_per_pixel;
dst = jpeg->pixels + rect->top * imageWidth + rect->left * jpeg->byte_per_pixel;
- /* Left-top of destination rectangular */
+ /* Left-top of destination rectangular */
for (h = rect->top; h <= rect->bottom; h++)
{
rt_memcpy(dst, src, rectWidth);
@@ -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,9 +694,9 @@ 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_y + rect->top + y,
- line_buf);
+ jpeg->dst_x + rect->left, jpeg->dst_x + rect->left + w,
+ jpeg->dst_y + rect->top + y,
+ line_buf);
src += rectWidth;
}
}
@@ -680,9 +705,9 @@ 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_y + rect->top + y,
- src);
+ 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;
+ 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,32 +736,29 @@ 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;
}
if (jd_prepare(&tjpgd, tjpgd_in_func, pool,
- TJPGD_WORKING_BUFFER_SIZE, (void *)&file) == JDR_OK)
+ 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,13 +794,13 @@ 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;
}
ret = jd_prepare(&jpeg->tjpgd, tjpgd_in_func, jpeg->pool,
- TJPGD_WORKING_BUFFER_SIZE, (void *)jpeg);
+ TJPGD_WORKING_BUFFER_SIZE, (void *)jpeg);
if (ret != JDR_OK)
{
if (ret == JDR_FMT3)
@@ -801,11 +821,11 @@ static rt_bool_t rtgui_image_jpeg_load(struct rtgui_image* image, struct rtgui_f
if (jpeg->to_buffer == RT_TRUE)
{
jpeg->pixels = (rt_uint8_t *)rtgui_malloc(
- jpeg->byte_per_pixel * image->w * image->h);
+ jpeg->byte_per_pixel * image->w * image->h);
if (jpeg->pixels == RT_NULL)
{
rt_kprintf("TJPGD err: no mem to load (%d)\n",
- jpeg->byte_per_pixel * image->w * image->h);
+ jpeg->byte_per_pixel * image->w * image->h);
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;
@@ -949,9 +970,9 @@ static void rtgui_image_jpeg_blit(struct rtgui_image* image,
blit_line(temp, src, jpeg->byte_per_pixel);
src += jpeg->byte_per_pixel;
dc->engine->blit_line(dc,
- dst_rect->x1 + x, dst_rect->x1 + x,
- dst_rect->y1 + y,
- temp);
+ dst_rect->x1 + x, dst_rect->x1 + x,
+ dst_rect->y1 + y,
+ temp);
}
}
}
@@ -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->y1 + y,
- src);
+ dst_rect->x1, dst_rect->x1 + w,
+ dst_rect->y1 + y,
+ src);
src += imageWidth;
}
}
}
- } while(0);
+ }
+ while (0);
}
#endif /* defined(RTGUI_IMAGE_TJPGD) */
/***************************************************************************//**
diff --git a/components/rtgui/include/rtgui/image.h b/components/rtgui/include/rtgui/image.h
index e876354286..3314c444a0 100644
--- a/components/rtgui/include/rtgui/image.h
+++ b/components/rtgui/include/rtgui/image.h
@@ -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
diff --git a/components/rtgui/include/rtgui/widgets/notebook.h b/components/rtgui/include/rtgui/widgets/notebook.h
index 92fb9e6c4d..881f11fc17 100644
--- a/components/rtgui/include/rtgui/widgets/notebook.h
+++ b/components/rtgui/include/rtgui/widgets/notebook.h
@@ -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);
diff --git a/components/rtgui/include/rtgui/widgets/window.h b/components/rtgui/include/rtgui/widgets/window.h
index ac3c2e7e36..7f2756905e 100644
--- a/components/rtgui/include/rtgui/widgets/window.h
+++ b/components/rtgui/include/rtgui/widgets/window.h
@@ -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);
diff --git a/components/rtgui/widgets/notebook.c b/components/rtgui/widgets/notebook.c
index 1192fd6e70..dcbeac9416 100644
--- a/components/rtgui/widgets/notebook.c
+++ b/components/rtgui/widgets/notebook.c
@@ -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);
}
}
}
diff --git a/components/rtgui/widgets/widget.c b/components/rtgui/widgets/widget.c
index 97ff00fea9..1a62d1666e 100644
--- a/components/rtgui/widgets/widget.c
+++ b/components/rtgui/widgets/widget.c
@@ -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);
diff --git a/components/rtgui/widgets/window.c b/components/rtgui/widgets/window.c
index 515817cd21..96300a5340 100644
--- a/components/rtgui/widgets/window.c
+++ b/components/rtgui/widgets/window.c
@@ -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)