Build doom on clipv2 and clip+
[kugel-rb.git] / apps / plugins / test_mem_jpeg.c
blobd6eda771add4a3ec00ac797d5f2f08cca6972e85
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 #include "lib/mylcd.h"
28 PLUGIN_HEADER
30 /* different graphics libraries */
31 #if LCD_DEPTH < 8
32 #define USEGSLIB
33 GREY_INFO_STRUCT
34 #define CFORMAT &format_grey
35 #else
36 #define CFORMAT &format_native
37 #endif
39 /* this is the plugin entry point */
40 enum plugin_status plugin_start(const void* parameter)
42 size_t plugin_buf_len;
43 unsigned char * plugin_buf =
44 (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len);
45 static char filename[MAX_PATH];
46 struct bitmap bm = {
47 .width = LCD_WIDTH,
48 .height = LCD_HEIGHT,
50 int ret;
52 if(!parameter) return PLUGIN_ERROR;
54 rb->strcpy(filename, parameter);
56 #ifdef USEGSLIB
57 long greysize;
58 if (!grey_init(plugin_buf, plugin_buf_len, GREY_ON_COP,
59 LCD_WIDTH, LCD_HEIGHT, &greysize))
61 rb->splash(HZ, "grey buf error");
62 return PLUGIN_ERROR;
64 plugin_buf += greysize;
65 plugin_buf_len -= greysize;
66 #endif
67 int fd = rb->open(filename, O_RDONLY);
68 if (fd < 0)
69 return PLUGIN_ERROR;
70 unsigned long filesize = rb->filesize(fd);
71 if (filesize > plugin_buf_len)
72 return PLUGIN_ERROR;
73 plugin_buf_len -= filesize;
74 unsigned char *jpeg_buf = plugin_buf;
75 plugin_buf += filesize;
76 rb->read(fd, jpeg_buf, filesize);
77 rb->close(fd);
78 bm.data = plugin_buf;
79 ret = decode_jpeg_mem(jpeg_buf, filesize, &bm, plugin_buf_len,
80 FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
81 CFORMAT);
82 if (ret < 1)
83 return PLUGIN_ERROR;
84 #ifdef USEGSLIB
85 grey_show(true);
86 grey_ub_gray_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1,
87 (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height);
88 #else
89 rb->lcd_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1,
90 (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height);
91 #endif
92 mylcd_ub_update();
93 while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield();
94 #ifdef USEGSLIB
95 grey_release();
96 #endif
97 return PLUGIN_OK;