diff options
author | Andrew Mahone <andrew.mahone@gmail.com> | 2009-05-01 23:24:23 +0000 |
---|---|---|
committer | Andrew Mahone <andrew.mahone@gmail.com> | 2009-05-01 23:24:23 +0000 |
commit | 60d420938372477226184fb9012de7f6b4ea2d83 (patch) | |
tree | 086926f469d87635a483bfff55ea50898bdd0e1c /apps/plugins | |
parent | b22516f995ef4a448251b883b0737d4aa0abdb84 (diff) | |
download | rockbox-60d420938372477226184fb9012de7f6b4ea2d83.tar.gz rockbox-60d420938372477226184fb9012de7f6b4ea2d83.zip |
Add core JPEG reader, adapted from the JPEG plugin's decoder, with some changes to prevent include conflicts between the two decoders.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20836 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/jpeg/jpeg_decoder.h | 68 | ||||
-rw-r--r-- | apps/plugins/test_core_jpeg.c | 89 | ||||
-rw-r--r-- | apps/plugins/viewers.config | 3 |
3 files changed, 93 insertions, 67 deletions
diff --git a/apps/plugins/jpeg/jpeg_decoder.h b/apps/plugins/jpeg/jpeg_decoder.h index f4dbeaa147..b86bdaf001 100644 --- a/apps/plugins/jpeg/jpeg_decoder.h +++ b/apps/plugins/jpeg/jpeg_decoder.h | |||
@@ -27,62 +27,7 @@ | |||
27 | 27 | ||
28 | #ifndef _JPEG_JPEG_DECODER_H | 28 | #ifndef _JPEG_JPEG_DECODER_H |
29 | #define _JPEG_JPEG_DECODER_H | 29 | #define _JPEG_JPEG_DECODER_H |
30 | 30 | #include "jpeg_common.h" | |
31 | #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */ | ||
32 | |||
33 | struct derived_tbl | ||
34 | { | ||
35 | /* Basic tables: (element [0] of each array is unused) */ | ||
36 | long mincode[17]; /* smallest code of length k */ | ||
37 | long maxcode[18]; /* largest code of length k (-1 if none) */ | ||
38 | /* (maxcode[17] is a sentinel to ensure huff_DECODE terminates) */ | ||
39 | int valptr[17]; /* huffval[] index of 1st symbol of length k */ | ||
40 | |||
41 | /* Back link to public Huffman table (needed only in slow_DECODE) */ | ||
42 | int* pub; | ||
43 | |||
44 | /* Lookahead tables: indexed by the next HUFF_LOOKAHEAD bits of | ||
45 | the input data stream. If the next Huffman code is no more | ||
46 | than HUFF_LOOKAHEAD bits long, we can obtain its length and | ||
47 | the corresponding symbol directly from these tables. */ | ||
48 | int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */ | ||
49 | unsigned char look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */ | ||
50 | }; | ||
51 | |||
52 | #define QUANT_TABLE_LENGTH 64 | ||
53 | |||
54 | /* for type of Huffman table */ | ||
55 | #define DC_LEN 28 | ||
56 | #define AC_LEN 178 | ||
57 | |||
58 | struct huffman_table | ||
59 | { /* length and code according to JFIF format */ | ||
60 | int huffmancodes_dc[DC_LEN]; | ||
61 | int huffmancodes_ac[AC_LEN]; | ||
62 | }; | ||
63 | |||
64 | struct frame_component | ||
65 | { | ||
66 | int ID; | ||
67 | int horizontal_sampling; | ||
68 | int vertical_sampling; | ||
69 | int quanttable_select; | ||
70 | }; | ||
71 | |||
72 | struct scan_component | ||
73 | { | ||
74 | int ID; | ||
75 | int DC_select; | ||
76 | int AC_select; | ||
77 | }; | ||
78 | |||
79 | struct bitstream | ||
80 | { | ||
81 | unsigned long get_buffer; /* current bit-extraction buffer */ | ||
82 | int bits_left; /* # of unused bits in it */ | ||
83 | unsigned char* next_input_byte; | ||
84 | unsigned char* input_end; /* upper limit +1 */ | ||
85 | }; | ||
86 | 31 | ||
87 | struct jpeg | 32 | struct jpeg |
88 | { | 33 | { |
@@ -113,17 +58,6 @@ struct jpeg | |||
113 | int subsample_y[3]; | 58 | int subsample_y[3]; |
114 | }; | 59 | }; |
115 | 60 | ||
116 | |||
117 | /* possible return flags for process_markers() */ | ||
118 | #define HUFFTAB 0x0001 /* with huffman table */ | ||
119 | #define QUANTTAB 0x0002 /* with quantization table */ | ||
120 | #define APP0_JFIF 0x0004 /* with APP0 segment following JFIF standard */ | ||
121 | #define FILL_FF 0x0008 /* with 0xFF padding bytes at begin/end */ | ||
122 | #define SOF0 0x0010 /* with SOF0-Segment */ | ||
123 | #define DHT 0x0020 /* with Definition of huffman tables */ | ||
124 | #define SOS 0x0040 /* with Start-of-Scan segment */ | ||
125 | #define DQT 0x0080 /* with definition of quantization table */ | ||
126 | |||
127 | /* various helper functions */ | 61 | /* various helper functions */ |
128 | void default_huff_tbl(struct jpeg* p_jpeg); | 62 | void default_huff_tbl(struct jpeg* p_jpeg); |
129 | void build_lut(struct jpeg* p_jpeg); | 63 | void build_lut(struct jpeg* p_jpeg); |
diff --git a/apps/plugins/test_core_jpeg.c b/apps/plugins/test_core_jpeg.c new file mode 100644 index 0000000000..5df69b5792 --- /dev/null +++ b/apps/plugins/test_core_jpeg.c | |||
@@ -0,0 +1,89 @@ | |||
1 | /***************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// __ \_/ ___\| |/ /| __ \ / __ \ \/ / | ||
5 | * Jukebox | | ( (__) ) \___| ( | \_\ ( (__) ) ( | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2008 Andrew Mahone | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "plugin.h" | ||
23 | #include "lib/grey.h" | ||
24 | PLUGIN_HEADER | ||
25 | |||
26 | /* different graphics libraries */ | ||
27 | #if LCD_DEPTH < 8 | ||
28 | #define USEGSLIB | ||
29 | GREY_INFO_STRUCT | ||
30 | #define MYLCD(fn) grey_ub_ ## fn | ||
31 | #define MYLCD_UPDATE() | ||
32 | #define MYXLCD(fn) grey_ub_ ## fn | ||
33 | #define CFORMAT &format_grey | ||
34 | #else | ||
35 | #define MYLCD(fn) rb->lcd_ ## fn | ||
36 | #define MYLCD_UPDATE() rb->lcd_update(); | ||
37 | #define MYXLCD(fn) xlcd_ ## fn | ||
38 | #define CFORMAT NULL | ||
39 | #endif | ||
40 | |||
41 | /* this is the plugin entry point */ | ||
42 | enum plugin_status plugin_start(const void* parameter) | ||
43 | { | ||
44 | size_t plugin_buf_len; | ||
45 | unsigned char * plugin_buf = | ||
46 | (unsigned char *)rb->plugin_get_buffer(&plugin_buf_len); | ||
47 | static char filename[MAX_PATH]; | ||
48 | struct bitmap bm = { | ||
49 | .width = LCD_WIDTH, | ||
50 | .height = LCD_HEIGHT, | ||
51 | }; | ||
52 | int ret; | ||
53 | |||
54 | if(!parameter) return PLUGIN_ERROR; | ||
55 | |||
56 | rb->strcpy(filename, parameter); | ||
57 | |||
58 | #ifdef USEGSLIB | ||
59 | long greysize; | ||
60 | if (!grey_init(plugin_buf, plugin_buf_len, GREY_ON_COP, | ||
61 | LCD_WIDTH, LCD_HEIGHT, &greysize)) | ||
62 | { | ||
63 | rb->splash(HZ, "grey buf error"); | ||
64 | return PLUGIN_ERROR; | ||
65 | } | ||
66 | plugin_buf += greysize; | ||
67 | plugin_buf_len -= greysize; | ||
68 | #endif | ||
69 | bm.data = plugin_buf; | ||
70 | ret = rb->read_jpeg_file(filename, &bm, plugin_buf_len, | ||
71 | FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT, | ||
72 | CFORMAT); | ||
73 | if (ret < 1) | ||
74 | return PLUGIN_ERROR; | ||
75 | #ifdef USEGSLIB | ||
76 | grey_show(true); | ||
77 | grey_ub_gray_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1, | ||
78 | (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height); | ||
79 | #else | ||
80 | rb->lcd_bitmap((fb_data *)bm.data, (LCD_WIDTH - bm.width) >> 1, | ||
81 | (LCD_HEIGHT - bm.height) >> 1, bm.width, bm.height); | ||
82 | #endif | ||
83 | MYLCD_UPDATE(); | ||
84 | while (rb->get_action(CONTEXT_STD,1) != ACTION_STD_OK) rb->yield(); | ||
85 | #ifdef USEGSLIB | ||
86 | grey_release(); | ||
87 | #endif | ||
88 | return PLUGIN_OK; | ||
89 | } | ||
diff --git a/apps/plugins/viewers.config b/apps/plugins/viewers.config index ff77dd85b6..09d0455c22 100644 --- a/apps/plugins/viewers.config +++ b/apps/plugins/viewers.config | |||
@@ -27,6 +27,9 @@ wav,viewers/wavplay,9 | |||
27 | wav,viewers/wavview,10 | 27 | wav,viewers/wavview,10 |
28 | wav,viewers/test_codec,- | 28 | wav,viewers/test_codec,- |
29 | bmp,viewers/test_greylib_bitmap_scale,- | 29 | bmp,viewers/test_greylib_bitmap_scale,- |
30 | jpeg,viewers/test_core_jpeg,- | ||
31 | jpe,viewers/test_core_jpeg,- | ||
32 | jpg,viewers/test_core_jpeg,- | ||
30 | bmp,apps/rockpaint,11 | 33 | bmp,apps/rockpaint,11 |
31 | bmp,games/sliding_puzzle,11 | 34 | bmp,games/sliding_puzzle,11 |
32 | mpg,viewers/mpegplayer,4 | 35 | mpg,viewers/mpegplayer,4 |