Fix red in bootloaders
[maemo-rb.git] / apps / plugins / bench_mem_jpeg.c
blob5169286fe34568f5f41ec8b9db592d7b8463f1ef
1 /*****************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Andrew Mahone
12 * In-memory JPEG decode benchmark.
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
22 ****************************************************************************/
24 #include "plugin.h"
25 #include "lib/jpeg_mem.h"
26 PLUGIN_HEADER
28 /* a null output plugin to save memory and better isolate decode cost */
29 static unsigned int get_size_null(struct bitmap *bm)
31 (void) bm;
32 return 1;
35 static void output_row_null(uint32_t row, void * row_in,
36 struct scaler_context *ctx)
38 (void) row;
39 (void) row_in;
40 (void) ctx;
41 return;
44 const struct custom_format format_null = {
45 .output_row_8 = output_row_null,
46 #ifdef HAVE_LCD_COLOR
47 .output_row_32 = {
48 output_row_null,
49 output_row_null
51 #else
52 .output_row_32 = output_row_null,
53 #endif
54 .get_size = get_size_null
57 static char output_buf[256];
58 static int output_y = 0;
59 static int font_h;
61 #define lcd_printf(...) \
62 do { \
63 rb->snprintf(output_buf, sizeof(output_buf), __VA_ARGS__); \
64 rb->lcd_putsxy(0, output_y, output_buf); \
65 rb->lcd_update_rect(0, output_y, LCD_WIDTH, font_h); \
66 output_y += font_h; \
67 } while (0)
69 /* this is the plugin entry point */
70 enum plugin_status plugin_start(const void* parameter)
72 size_t plugin_buf_len;
73 unsigned char * plugin_buf =
74 (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len);
75 static char filename[MAX_PATH];
76 struct bitmap bm = {
77 .width = LCD_WIDTH,
78 .height = LCD_HEIGHT,
80 int ret;
82 if(!parameter) return PLUGIN_ERROR;
84 rb->strcpy(filename, parameter);
85 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
86 rb->lcd_fillrect(0, 0, LCD_WIDTH, LCD_HEIGHT);
87 rb->lcd_set_drawmode(DRMODE_SOLID);
88 rb->lcd_getstringsize("A", NULL, &font_h);
89 int fd = rb->open(filename, O_RDONLY);
90 if (fd < 0)
92 lcd_printf("file open failed: %d", fd);
93 goto wait;
95 unsigned long filesize = rb->filesize(fd);
96 if (filesize > plugin_buf_len)
98 lcd_printf("file too large");
99 goto wait;
101 plugin_buf_len -= filesize;
102 unsigned char *jpeg_buf = plugin_buf;
103 plugin_buf += filesize;
104 rb->read(fd, jpeg_buf, filesize);
105 rb->close(fd);
106 bm.data = plugin_buf;
107 struct dim jpeg_size;
108 get_jpeg_dim_mem(jpeg_buf, filesize, &jpeg_size);
109 lcd_printf("jpeg file size: %dx%d",jpeg_size.width, jpeg_size.height);
110 bm.width = jpeg_size.width;
111 bm.height = jpeg_size.height;
112 char *size_str[] = { "1/1", "1/2", "1/4", "1/8" };
113 int i;
114 for (i = 0; i < 4; i++)
116 lcd_printf("timing %s decode", size_str[i]);
117 ret = decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len,
118 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
119 &format_null);
120 if (ret == 1)
122 long t1, t2, t_end;
123 int count = 0;
124 t2 = *(rb->current_tick);
125 while (t2 != (t1 = *(rb->current_tick)));
126 t_end = t1 + 10 * HZ;
127 do {
128 decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len,
129 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
130 &format_null);
131 count++;
132 t2 = *(rb->current_tick);
133 } while (TIME_BEFORE(t2, t_end) || count < 10);
134 t2 -= t1;
135 t2 *= 10;
136 t2 += count >> 1;
137 t2 /= count;
138 t1 = t2 / 1000;
139 t2 -= t1 * 1000;
140 lcd_printf("%01d.%03d secs/decode", (int)t1, (int)t2);
141 bm.width >>= 1;
142 bm.height >>= 1;
143 if (!(bm.width && bm.height))
144 break;
145 } else
146 lcd_printf("insufficient memory");
149 wait:
150 while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield();
151 return PLUGIN_OK;