Add support for the next/prev side buttons to mpegplayer on the Gigabeat S to control...
[kugel-rb.git] / apps / plugins / test_mem_jpeg.c
blob50969c3503bef90966125ebd5e7621988a968fea
1 /*****************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ /
5 * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) (
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 Andrew Mahone
12 * In-memory JPEG decode test.
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/grey.h"
26 #include "lib/jpeg_mem.h"
27 PLUGIN_HEADER
29 /* different graphics libraries */
30 #if LCD_DEPTH < 8
31 #define USEGSLIB
32 GREY_INFO_STRUCT
33 #define MYLCD(fn) grey_ub_ ## fn
34 #define MYLCD_UPDATE()
35 #define MYXLCD(fn) grey_ub_ ## fn
36 #define CFORMAT &format_grey
37 #else
38 #define MYLCD(fn) rb->lcd_ ## fn
39 #define MYLCD_UPDATE() rb->lcd_update();
40 #define MYXLCD(fn) xlcd_ ## fn
41 #define CFORMAT &format_native
42 #endif
44 /* this is the plugin entry point */
45 enum plugin_status plugin_start(const void* parameter)
47 size_t plugin_buf_len;
48 unsigned char * plugin_buf =
49 (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len);
50 static char filename[MAX_PATH];
51 struct bitmap bm = {
52 .width = LCD_WIDTH,
53 .height = LCD_HEIGHT,
55 int ret;
57 if(!parameter) return PLUGIN_ERROR;
59 rb->strcpy(filename, parameter);
61 #ifdef USEGSLIB
62 long greysize;
63 if (!grey_init(plugin_buf, plugin_buf_len, GREY_ON_COP,
64 LCD_WIDTH, LCD_HEIGHT, &greysize))
66 rb->splash(HZ, "grey buf error");
67 return PLUGIN_ERROR;
69 plugin_buf += greysize;
70 plugin_buf_len -= greysize;
71 #endif
72 int fd = rb->open(filename, O_RDONLY);
73 if (fd < 0)
74 return PLUGIN_ERROR;
75 unsigned long filesize = rb->filesize(fd);
76 if (filesize > plugin_buf_len)
77 return PLUGIN_ERROR;
78 plugin_buf_len -= filesize;
79 unsigned char *jpeg_buf = plugin_buf;
80 plugin_buf += filesize;
81 rb->read(fd, jpeg_buf, filesize);
82 rb->close(fd);
83 bm.data = plugin_buf;
84 ret = decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len,
85 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
86 CFORMAT);
87 if (ret < 1)
88 return PLUGIN_ERROR;
89 #ifdef USEGSLIB
90 grey_show(true);
91 grey_ub_gray_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1,
92 (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height);
93 #else
94 rb->lcd_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1,
95 (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height);
96 #endif
97 MYLCD_UPDATE();
98 while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield();
99 #ifdef USEGSLIB
100 grey_release();
101 #endif
102 return PLUGIN_OK;