1 /*****************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
25 #include "lib/jpeg_mem.h"
28 /* a null output plugin to save memory and better isolate decode cost */
29 static unsigned int get_size_null(struct bitmap
*bm
)
35 static void output_row_null(uint32_t row
, void * row_in
,
36 struct scaler_context
*ctx
)
44 const struct custom_format format_null
= {
45 .output_row_8
= output_row_null
,
52 .output_row_32
= output_row_null
,
54 .get_size
= get_size_null
57 static char output_buf
[256];
58 static int output_y
= 0;
61 #define lcd_printf(...) \
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); \
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
];
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
);
92 lcd_printf("file open failed: %d", fd
);
95 unsigned long filesize
= rb
->filesize(fd
);
96 if (filesize
> plugin_buf_len
)
98 lcd_printf("file too large");
101 plugin_buf_len
-= filesize
;
102 unsigned char *jpeg_buf
= plugin_buf
;
103 plugin_buf
+= filesize
;
104 rb
->read(fd
, jpeg_buf
, filesize
);
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" };
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
,
124 t2
= *(rb
->current_tick
);
125 while (t2
!= (t1
= *(rb
->current_tick
)));
126 t_end
= t1
+ 10 * HZ
;
128 decode_jpeg_mem(jpeg_buf
, filesize
, &bm
, plugin_buf_len
,
129 FORMAT_NATIVE
|FORMAT_RESIZE
|FORMAT_KEEP_ASPECT
,
132 t2
= *(rb
->current_tick
);
133 } while (TIME_BEFORE(t2
, t_end
) || count
< 10);
140 lcd_printf("%01d.%03d secs/decode", (int)t1
, (int)t2
);
143 if (!(bm
.width
&& bm
.height
))
146 lcd_printf("insufficient memory");
150 while (rb
->get_action(CONTEXT_STD
,1) != ACTION_STD_OK
) rb
->yield();