diff options
| author | Andrew Mahone <andrew.mahone@gmail.com> | 2009-05-08 03:46:48 +0000 |
|---|---|---|
| committer | Andrew Mahone <andrew.mahone@gmail.com> | 2009-05-08 03:46:48 +0000 |
| commit | a75c72c169f64ecb0799934f1da148bdf497b8a9 (patch) | |
| tree | b0ad37ce0f6519bb44536a0bf6fc72fc76628542 /apps/plugins | |
| parent | c91e73e922fc2a229c39a9b686d77d5cba47c95a (diff) | |
| download | rockbox-a75c72c169f64ecb0799934f1da148bdf497b8a9.zip rockbox-a75c72c169f64ecb0799934f1da148bdf497b8a9.tar.gz rockbox-a75c72c169f64ecb0799934f1da148bdf497b8a9.tar.bz2 rockbox-a75c72c169f64ecb0799934f1da148bdf497b8a9.tar.xz | |
Plugin JPEG decoder for data in memory, along with test_mem_jpeg.c and bench_mem_jpeg.c plugins to test and benchmark it, and a line-length clean up in jpeg_load.c.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20871 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
| -rw-r--r-- | apps/plugins/bench_mem_jpeg.c | 150 | ||||
| -rw-r--r-- | apps/plugins/lib/SOURCES | 3 | ||||
| -rw-r--r-- | apps/plugins/lib/jpeg_mem.h | 41 | ||||
| -rw-r--r-- | apps/plugins/lib/pluginlib_jpeg_mem.c | 29 | ||||
| -rw-r--r-- | apps/plugins/test_mem_jpeg.c | 103 | ||||
| -rw-r--r-- | apps/plugins/viewers.config | 6 |
6 files changed, 330 insertions, 2 deletions
diff --git a/apps/plugins/bench_mem_jpeg.c b/apps/plugins/bench_mem_jpeg.c new file mode 100644 index 0000000..958e520 --- /dev/null +++ b/apps/plugins/bench_mem_jpeg.c @@ -0,0 +1,150 @@ +/***************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ / + * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) ( + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 Andrew Mahone + * + * In-memory JPEG decode benchmark. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "plugin.h" +#include "lib/jpeg_mem.h" +PLUGIN_HEADER + +/* a null output plugin to save memory and better isolate decode cost */ +static unsigned int get_size_null(struct bitmap *bm) +{ + (void) bm; + return 1; +} + +static void output_row_null(uint32_t row, void * row_in, + struct scaler_context *ctx) +{ + (void) row; + (void) row_in; + (void) ctx; + return; +} + +const struct custom_format format_null = { +#ifdef HAVE_LCD_COLOR + .output_row = { + output_row_null, + output_row_null + }, +#else + .output_row = output_row_null, +#endif + .get_size = get_size_null +}; + +static char output_buf[256]; +static int output_y = 0; +static int font_h; + +#define lcd_printf(...) \ +do { \ + rb->snprintf(output_buf, sizeof(output_buf), __VA_ARGS__); \ + rb->lcd_putsxy(0, output_y, output_buf); \ + rb->lcd_update_rect(0, output_y, LCD_WIDTH, font_h); \ + output_y += font_h; \ +} while (0) + +/* this is the plugin entry point */ +enum plugin_status plugin_start(const void* parameter) +{ + size_t plugin_buf_len; + unsigned char * plugin_buf = + (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len); + static char filename[MAX_PATH]; + struct bitmap bm = { + .width = LCD_WIDTH, + .height = LCD_HEIGHT, + }; + int ret; + + if(!parameter) return PLUGIN_ERROR; + + rb->strcpy(filename, parameter); + rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID); + rb->lcd_fillrect(0, 0, LCD_WIDTH, LCD_HEIGHT); + rb->lcd_set_drawmode(DRMODE_SOLID); + rb->lcd_getstringsize("A", NULL, &font_h); + int fd = rb->open(filename, O_RDONLY); + if (fd < 0) + { + lcd_printf("file open failed: %d", fd); + goto wait; + } + unsigned long filesize = rb->filesize(fd); + if (filesize > plugin_buf_len) + { + lcd_printf("file too large"); + goto wait; + } + plugin_buf_len -= filesize; + unsigned char *jpeg_buf = plugin_buf; + plugin_buf += filesize; + rb->read(fd, jpeg_buf, filesize); + rb->close(fd); + bm.data = plugin_buf; + struct dim jpeg_size; + get_jpeg_dim_mem(jpeg_buf, filesize, &jpeg_size); + lcd_printf("jpeg file size: %dx%d",jpeg_size.width, jpeg_size.height); + bm.width = jpeg_size.width; + bm.height = jpeg_size.height; + char *size_str[] = { "1/1", "1/2", "1/4", "1/8" }; + int i; + for (i = 0; i < 4; i++) + { + lcd_printf("timing %s decode", size_str[i]); + ret = decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len, + FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT, + &format_null); + if (ret == 1) + { + long t1, t2; + int count = 0; + t2 = *(rb->current_tick); + while (t2 != (t1 = *(rb->current_tick))); + do { + decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len, + FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT, + &format_null); + count++; + t2 = *(rb->current_tick); + } while (t2 - t1 < HZ || count < 10); + t2 -= t1; + t2 *= 10; + t2 += count >> 1; + t2 /= count; + t1 = t2 / 1000; + t2 -= t1 * 1000; + lcd_printf("%01d.%03d secs/decode", (int)t1, (int)t2); + bm.width >>= 1; + bm.height >>= 1; + if (!(bm.width && bm.height)) + break; + } else + lcd_printf("insufficient memory"); + } + +wait: + while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield(); + return PLUGIN_OK; +} diff --git a/apps/plugins/lib/SOURCES b/apps/plugins/lib/SOURCES index 889fb79..21a35d4 100644 --- a/apps/plugins/lib/SOURCES +++ b/apps/plugins/lib/SOURCES @@ -27,9 +27,8 @@ playergfx.c profile_plugin.c #endif #ifdef HAVE_LCD_BITMAP -#if !defined(HAVE_BMP_SCALING) || !defined(HAVE_JPEG) +pluginlib_jpeg_mem.c pluginlib_resize.c -#endif #ifndef HAVE_JPEG pluginlib_jpeg_load.c #endif diff --git a/apps/plugins/lib/jpeg_mem.h b/apps/plugins/lib/jpeg_mem.h new file mode 100644 index 0000000..8636f70 --- /dev/null +++ b/apps/plugins/lib/jpeg_mem.h @@ -0,0 +1,41 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2009 by Andrew Mahone +* +* Header for the in-memory JPEG decoder. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +* KIND, either express or implied. +* +****************************************************************************/ + +#include "plugin.h" +#include "resize.h" +#include "bmp.h" +#include "jpeg_common.h" + +#ifndef _JPEG_MEM_H +#define _JPEG_MEM_H + +int get_jpeg_dim_mem(unsigned char *data, unsigned long len, + struct dim *size); + +int decode_jpeg_mem(unsigned char *data, unsigned long len, + struct bitmap *bm, + int maxsize, + int format, + const struct custom_format *cformat); + +#endif /* _JPEG_MEM_H */ diff --git a/apps/plugins/lib/pluginlib_jpeg_mem.c b/apps/plugins/lib/pluginlib_jpeg_mem.c new file mode 100644 index 0000000..4a6c1bb --- /dev/null +++ b/apps/plugins/lib/pluginlib_jpeg_mem.c @@ -0,0 +1,29 @@ +/*************************************************************************** +* __________ __ ___. +* Open \______ \ ____ ____ | | _\_ |__ _______ ___ +* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +* \/ \/ \/ \/ \/ +* $Id$ +* +* Copyright (C) 2009 by Andrew Mahone +* +* This is a wrapper for the core jpeg_load.c, to provide the from-memory +* version of the decoder. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY +* KIND, either express or implied. +* +****************************************************************************/ + +#include <plugin.h> +#include "wrappers.h" +#define JPEG_FROM_MEM + +#include "../../recorder/jpeg_load.c" diff --git a/apps/plugins/test_mem_jpeg.c b/apps/plugins/test_mem_jpeg.c new file mode 100644 index 0000000..50969c3 --- /dev/null +++ b/apps/plugins/test_mem_jpeg.c @@ -0,0 +1,103 @@ +/***************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ / + * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) ( + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2009 Andrew Mahone + * + * In-memory JPEG decode test. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "plugin.h" +#include "lib/grey.h" +#include "lib/jpeg_mem.h" +PLUGIN_HEADER + +/* different graphics libraries */ +#if LCD_DEPTH < 8 +#define USEGSLIB +GREY_INFO_STRUCT +#define MYLCD(fn) grey_ub_ ## fn +#define MYLCD_UPDATE() +#define MYXLCD(fn) grey_ub_ ## fn +#define CFORMAT &format_grey +#else +#define MYLCD(fn) rb->lcd_ ## fn +#define MYLCD_UPDATE() rb->lcd_update(); +#define MYXLCD(fn) xlcd_ ## fn +#define CFORMAT &format_native +#endif + +/* this is the plugin entry point */ +enum plugin_status plugin_start(const void* parameter) +{ + size_t plugin_buf_len; + unsigned char * plugin_buf = + (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len); + static char filename[MAX_PATH]; + struct bitmap bm = { + .width = LCD_WIDTH, + .height = LCD_HEIGHT, + }; + int ret; + + if(!parameter) return PLUGIN_ERROR; + + rb->strcpy(filename, parameter); + +#ifdef USEGSLIB + long greysize; + if (!grey_init(plugin_buf, plugin_buf_len, GREY_ON_COP, + LCD_WIDTH, LCD_HEIGHT, &greysize)) + { + rb->splash(HZ, "grey buf error"); + return PLUGIN_ERROR; + } + plugin_buf += greysize; + plugin_buf_len -= greysize; +#endif + int fd = rb->open(filename, O_RDONLY); + if (fd < 0) + return PLUGIN_ERROR; + unsigned long filesize = rb->filesize(fd); + if (filesize > plugin_buf_len) + return PLUGIN_ERROR; + plugin_buf_len -= filesize; + unsigned char *jpeg_buf = plugin_buf; + plugin_buf += filesize; + rb->read(fd, jpeg_buf, filesize); + rb->close(fd); + bm.data = plugin_buf; + ret = decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len, + FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT, + CFORMAT); + if (ret < 1) + return PLUGIN_ERROR; +#ifdef USEGSLIB + grey_show(true); + grey_ub_gray_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1, + (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height); +#else + rb->lcd_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1, + (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height); +#endif + MYLCD_UPDATE(); + while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield(); +#ifdef USEGSLIB + grey_release(); +#endif + return PLUGIN_OK; +} diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config index 09d0455..939a0a5 100644 --- a/apps/plugins/viewers.config +++ b/apps/plugins/viewers.config @@ -30,6 +30,12 @@ bmp,viewers/test_greylib_bitmap_scale,- jpeg,viewers/test_core_jpeg,- jpe,viewers/test_core_jpeg,- jpg,viewers/test_core_jpeg,- +jpeg,viewers/test_mem_jpeg,- +jpe,viewers/test_mem_jpeg,- +jpg,viewers/test_mem_jpeg,- +jpeg,viewers/bench_mem_jpeg,- +jpe,viewers/bench_mem_jpeg,- +jpg,viewers/bench_mem_jpeg,- bmp,apps/rockpaint,11 bmp,games/sliding_puzzle,11 mpg,viewers/mpegplayer,4 |