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 int output_y
= 0;
60 #define lcd_printf(...) \
62 rb->lcd_putsxyf(0, output_y, __VA_ARGS__); \
63 rb->lcd_update_rect(0, output_y, LCD_WIDTH, font_h); \
67 /* this is the plugin entry point */
68 enum plugin_status
plugin_start(const void* parameter
)
70 size_t plugin_buf_len
;
71 unsigned char * plugin_buf
=
72 (unsigned char *)rb
->plugin_get_buffer(&plugin_buf_len
);
73 static char filename
[MAX_PATH
];
80 if(!parameter
) return PLUGIN_ERROR
;
82 rb
->strcpy(filename
, parameter
);
83 rb
->lcd_set_drawmode(DRMODE_SOLID
|DRMODE_INVERSEVID
);
84 rb
->lcd_fillrect(0, 0, LCD_WIDTH
, LCD_HEIGHT
);
85 rb
->lcd_set_drawmode(DRMODE_SOLID
);
86 rb
->lcd_getstringsize("A", NULL
, &font_h
);
87 int fd
= rb
->open(filename
, O_RDONLY
);
90 lcd_printf("file open failed: %d", fd
);
93 unsigned long filesize
= rb
->filesize(fd
);
94 if (filesize
> plugin_buf_len
)
96 lcd_printf("file too large");
99 plugin_buf_len
-= filesize
;
100 unsigned char *jpeg_buf
= plugin_buf
;
101 plugin_buf
+= filesize
;
102 rb
->read(fd
, jpeg_buf
, filesize
);
104 bm
.data
= plugin_buf
;
105 struct dim jpeg_size
;
106 get_jpeg_dim_mem(jpeg_buf
, filesize
, &jpeg_size
);
107 lcd_printf("jpeg file size: %dx%d",jpeg_size
.width
, jpeg_size
.height
);
108 bm
.width
= jpeg_size
.width
;
109 bm
.height
= jpeg_size
.height
;
110 char *size_str
[] = { "1/1", "1/2", "1/4", "1/8" };
112 for (i
= 0; i
< 4; i
++)
114 lcd_printf("timing %s decode", size_str
[i
]);
115 ret
= decode_jpeg_mem(jpeg_buf
, filesize
, &bm
, plugin_buf_len
,
116 FORMAT_NATIVE
|FORMAT_RESIZE
|FORMAT_KEEP_ASPECT
,
122 t2
= *(rb
->current_tick
);
123 while (t2
!= (t1
= *(rb
->current_tick
)));
124 t_end
= t1
+ 10 * HZ
;
126 decode_jpeg_mem(jpeg_buf
, filesize
, &bm
, plugin_buf_len
,
127 FORMAT_NATIVE
|FORMAT_RESIZE
|FORMAT_KEEP_ASPECT
,
130 t2
= *(rb
->current_tick
);
131 } while (TIME_BEFORE(t2
, t_end
) || count
< 10);
138 lcd_printf("%01d.%03d secs/decode", (int)t1
, (int)t2
);
141 if (!(bm
.width
&& bm
.height
))
144 lcd_printf("insufficient memory");
148 while (rb
->get_action(CONTEXT_STD
,1) != ACTION_STD_OK
) rb
->yield();