Coldfire targets: Restore EMAC status after using the EMAC for bitmap resizing. Fixes...
[maemo-rb.git] / apps / recorder / bmp.h
blobc6a34dfd94f2295cadf29529e9cbb85a318f3c12
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 by Daniel Stenberg
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #ifndef _BMP_H_
22 #define _BMP_H_
24 #include "config.h"
25 #include "lcd.h"
26 #include "inttypes.h"
27 #include "resize.h"
28 #ifdef HAVE_REMOTE_LCD
29 #include "lcd-remote.h"
30 #endif
32 #define ARRAY_SIZE(array) (int)(sizeof(array)/(sizeof(array[0])))
34 #define IMG_NORESIZE 0
35 #define IMG_RESIZE 1
36 #define BM_MAX_WIDTH (((LCD_WIDTH) + 7) & ~7)
38 struct uint8_rgb {
39 uint8_t blue;
40 uint8_t green;
41 uint8_t red;
44 struct dim {
45 short width;
46 short height;
49 struct rowset {
50 short rowstep;
51 short rowstart;
52 short rowstop;
55 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
56 extern const unsigned char dither_table[16];
57 #define DITHERY(y) (dither_table[(y) & 15] & 0xAA)
58 #define DITHERX(x) (dither_table[(x) & 15])
59 #define DITHERXDY(x,dy) (DITHERX(x) ^ dy)
60 #define DITHERDXY(dx,y) (dx ^ DITHERY(y))
61 #define DITHERXY(x,y) (DITHERX(x) ^ DITHERY(y))
62 #endif
64 /* The /256 version has a mean squared variance from YUV luma of <1 grey level.
65 The /8 version is a good deal less accurate, but sufficient on mono as we
66 don't support HQ output or dithering there, yet.
68 static inline unsigned brightness(struct uint8_rgb color)
70 #if LCD_DEPTH > 1 || defined(PLUGIN)
71 return (77 * (unsigned)color.red + 150 * (unsigned)color.green
72 + 29 * (unsigned)color.blue) / 256;
73 #else
74 return (2 * (unsigned)color.red + 5 * (unsigned)color.green
75 + (unsigned)color.blue) / 8;
76 #endif
79 #if ((LCD_DEPTH == 2) && (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)) \
80 || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH == 2) \
81 && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED))
82 extern const unsigned short vi_pattern[4];
83 #endif
85 /* Number of rows of data in a mono bitmap height pixels tall */
86 #define MONO_BM_HEIGHT(height) (((height) + 7) >> 3)
88 /* Number of rows of datain a LCD native bitmap height pixels tall */
89 #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
90 #if LCD_DEPTH == 1 || \
91 (LCD_DEPTH == 2 && LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)
92 #define LCD_BM_HEIGHT(height) (((height) + 7) >> 3)
93 #elif LCD_DEPTH == 2 && LCD_PIXELFORMAT == VERTICAL_PACKING
94 #define LCD_BM_HEIGHT(height) (((height) + 3) >> 2)
95 #else
96 #define LCD_BM_HEIGHT(height) (height)
97 #endif
99 /* Number of rows of data in a remote native bitmap height pixels tall. */
100 #ifdef HAVE_REMOTE_LCD
101 #if LCD_REMOTE_DEPTH == 1 || \
102 (LCD_REMOTE_DEPTH == 2 && LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED)
103 #define LCD_REMOTE_BM_HEIGHT(height) (((height) + 7) >> 3)
104 #elif LCD_REMOTE_DEPTH == 2 && LCD_REMOTE_PIXELFORMAT == VERTICAL_PACKING
105 #define LCD_REMOTE_BM_HEIGHT(height) (((height) + 3) >> 2)
106 #else
107 #define LCD_REMOTE_BM_HEIGHT(height) (height)
108 #endif
109 #define NATIVE_BM_HEIGHT(height,remote) ((remote) ? \
110 LCD_REMOTE_BM_HEIGHT(height) : LCD_BM_HEIGHT(height))
111 #else
112 #define NATIVE_BM_HEIGHT(height,remote) LCD_BM_HEIGHT(height)
113 #endif
115 /* Convenience macro to calculate rows based on height, remote vs main LCD,
116 and format
118 #define BM_HEIGHT(height,format,remote) ((format) == FORMAT_MONO ? \
119 MONO_BM_HEIGHT(height) : NATIVE_BM_HEIGHT(height,remote))
120 #else
121 #define BM_HEIGHT(height,format,remote) MONO_BM_HEIGHT(height)
122 #endif
124 /* Number of data elements in a mono bitmap width pixels wide */
125 #define MONO_BM_WIDTH(width) (width)
127 /* Number of data elements in a LCD native bitmap width pixels wide */
128 #if LCD_DEPTH > 1
129 #if LCD_DEPTH == 2 && LCD_PIXELFORMAT == HORIZONTAL_PACKING
130 #define LCD_BM_WIDTH(width) (((width) + 3) >> 2)
131 #else
132 #define LCD_BM_WIDTH(width) (width)
133 #endif
135 /* Number of data elements in a remote native bitmap width pixels wide */
136 #ifdef HAVE_LCD_REMOTE
137 #if LCD_REMOTE_DEPTH == 2 && LCD_REMOTE_PIXELFORMAT == HORIZONTAL_PACKING
138 #define LCD_REMOTE_BM_WIDTH(width) (((width) + 3) >> 2)
139 #else
140 #define LCD_REMOTE_BM_WIDTH(width) (width)
141 #endif
142 #define NATIVE_BM_WIDTH(width,remote) ((remote) ? \
143 LCD_REMOTE_BM_WIDTH(width) : LCD_BM_WIDTH(width))
144 #else
145 #define NATIVE_BM_WIDTH(width,remote) LCD_BM_WIDTH(width)
146 #endif
148 /* Convenience macro to calculate elements based on height, remote vs native
149 main LCD, and format
151 #define BM_WIDTH(width,format,remote) ((format) == FORMAT_MONO ? \
152 MONO_BM_WIDTH(width) : NATIVE_BM_WIDTH(width,remote))
153 #else
154 #define BM_WIDTH(width,format,remote) MONO_BM_WIDTH(width)
155 #endif
157 /* Size in bytes of a mono bitmap of dimensions width*height */
158 #define MONO_BM_SIZE(width,height) (MONO_BM_WIDTH(width) * \
159 MONO_BM_HEIGHT(height) * FB_DATA_SZ)
161 /* Size in bytes of a native bitmap of dimensions width*height */
162 #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
163 #if defined(HAVE_REMOTE_LCD) && FB_DATA_SZ != FB_RDATA_SZ
164 #define NATIVE_BM_SIZE(width,height,format,remote) \
165 (((remote) ? FB_RDATA_SZ : FB_DATA_SZ) * BM_WIDTH(width,format,remote) \
166 * BM_HEIGHT(height,format,remote))
167 #else
168 #define NATIVE_BM_SIZE(width,height,format,remote) \
169 (FB_DATA_SZ * BM_WIDTH(width,format,remote) * \
170 BM_HEIGHT(height,format,remote))
171 #endif
173 /* Convenience macro to calculate size in bytes based on height, remote vs
174 main LCD, and format
176 #define BM_SIZE(width,height,format,remote) (((format) == FORMAT_MONO) ? \
177 MONO_BM_SIZE(width,height) : NATIVE_BM_SIZE(width,height,format,remote))
178 #else
179 #define BM_SIZE(width,height,format,remote) MONO_BM_SIZE(width,height)
180 #endif
182 /* Size in bytes needed to load and scale a bitmap with target size up to
183 width*height, including overhead to allow for buffer alignment.
185 #ifdef HAVE_LCD_COLOR
186 #define BM_SCALED_SIZE(width,height,format,remote) \
187 (BM_SIZE(width,height,format,remote) + \
188 (remote ? 0 : BM_WIDTH(width,format,remote) * sizeof(uint32_t) * 9 + 3))
189 #else
190 #define BM_SCALED_SIZE(width,height,format,remote) \
191 (BM_SIZE(width,height,format,remote) + \
192 (width * sizeof(uint32_t) * 3 + 3))
193 #endif
195 /*********************************************************************
196 * read_bmp_file()
198 * Reads a 8bit BMP file and puts the data in a 1-pixel-per-byte
199 * array.
200 * Returns < 0 for error, or number of bytes used from the bitmap buffer
202 **********************************************/
203 int read_bmp_file(const char* filename,
204 struct bitmap *bm,
205 int maxsize,
206 int format,
207 const struct custom_format *cformat);
209 int read_bmp_fd(int fd,
210 struct bitmap *bm,
211 int maxsize,
212 int format,
213 const struct custom_format *cformat);
215 #if LCD_DEPTH > 1 && (defined(PLUGIN) || defined(HAVE_BMP_SCALING) || defined(HAVE_JPEG))
216 void output_row_8_native(uint32_t row, void * row_in,
217 struct scaler_context *ctx);
218 #endif
219 #endif