skin tags: fix the id3 track/disc numbers in conditionals
[maemo-rb.git] / apps / recorder / bmp.h
blob3ddc3b66df6d615c9e3d2d5b2b6622bd2da68666
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;
42 uint8_t alpha;
45 struct dim {
46 short width;
47 short height;
50 struct rowset {
51 short rowstep;
52 short rowstart;
53 short rowstop;
56 #if (LCD_DEPTH > 1) || defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH > 1)
57 extern const unsigned char dither_table[16];
58 #define DITHERY(y) (dither_table[(y) & 15] & 0xAA)
59 #define DITHERX(x) (dither_table[(x) & 15])
60 #define DITHERXDY(x,dy) (DITHERX(x) ^ dy)
61 #define DITHERDXY(dx,y) (dx ^ DITHERY(y))
62 #define DITHERXY(x,y) (DITHERX(x) ^ DITHERY(y))
63 #endif
65 /* The /256 version has a mean squared variance from YUV luma of <1 grey level.
66 The /8 version is a good deal less accurate, but sufficient on mono as we
67 don't support HQ output or dithering there, yet.
69 static inline unsigned brightness(struct uint8_rgb color)
71 #if LCD_DEPTH > 1 || defined(PLUGIN)
72 return (77 * (unsigned)color.red + 150 * (unsigned)color.green
73 + 29 * (unsigned)color.blue) / 256;
74 #else
75 return (2 * (unsigned)color.red + 5 * (unsigned)color.green
76 + (unsigned)color.blue) / 8;
77 #endif
80 #if ((LCD_DEPTH == 2) && (LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)) \
81 || (defined(HAVE_REMOTE_LCD) && (LCD_REMOTE_DEPTH == 2) \
82 && (LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED))
83 extern const unsigned short vi_pattern[4];
84 #endif
86 /* Number of rows of data in a mono bitmap height pixels tall */
87 #define MONO_BM_HEIGHT(height) (((height) + 7) >> 3)
89 /* Number of rows of datain a LCD native bitmap height pixels tall */
90 #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
91 #if LCD_DEPTH == 1 || \
92 (LCD_DEPTH == 2 && LCD_PIXELFORMAT == VERTICAL_INTERLEAVED)
93 #define LCD_BM_HEIGHT(height) (((height) + 7) >> 3)
94 #elif LCD_DEPTH == 2 && LCD_PIXELFORMAT == VERTICAL_PACKING
95 #define LCD_BM_HEIGHT(height) (((height) + 3) >> 2)
96 #else
97 #define LCD_BM_HEIGHT(height) (height)
98 #endif
100 /* Number of rows of data in a remote native bitmap height pixels tall. */
101 #ifdef HAVE_REMOTE_LCD
102 #if LCD_REMOTE_DEPTH == 1 || \
103 (LCD_REMOTE_DEPTH == 2 && LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED)
104 #define LCD_REMOTE_BM_HEIGHT(height) (((height) + 7) >> 3)
105 #elif LCD_REMOTE_DEPTH == 2 && LCD_REMOTE_PIXELFORMAT == VERTICAL_PACKING
106 #define LCD_REMOTE_BM_HEIGHT(height) (((height) + 3) >> 2)
107 #else
108 #define LCD_REMOTE_BM_HEIGHT(height) (height)
109 #endif
110 #define NATIVE_BM_HEIGHT(height,remote) ((remote) ? \
111 LCD_REMOTE_BM_HEIGHT(height) : LCD_BM_HEIGHT(height))
112 #else
113 #define NATIVE_BM_HEIGHT(height,remote) LCD_BM_HEIGHT(height)
114 #endif
116 /* Convenience macro to calculate rows based on height, remote vs main LCD,
117 and format
119 #define BM_HEIGHT(height,format,remote) ((format) == FORMAT_MONO ? \
120 MONO_BM_HEIGHT(height) : NATIVE_BM_HEIGHT(height,remote))
121 #else
122 #define BM_HEIGHT(height,format,remote) MONO_BM_HEIGHT(height)
123 #endif
125 /* Number of data elements in a mono bitmap width pixels wide */
126 #define MONO_BM_WIDTH(width) (width)
128 /* Number of data elements in a LCD native bitmap width pixels wide */
129 #if LCD_DEPTH > 1
130 #if LCD_DEPTH == 2 && LCD_PIXELFORMAT == HORIZONTAL_PACKING
131 #define LCD_BM_WIDTH(width) (((width) + 3) >> 2)
132 #else
133 #define LCD_BM_WIDTH(width) (width)
134 #endif
136 /* Number of data elements in a remote native bitmap width pixels wide */
137 #ifdef HAVE_REMOTE_LCD
138 #if LCD_REMOTE_DEPTH == 2 && LCD_REMOTE_PIXELFORMAT == HORIZONTAL_PACKING
139 #define LCD_REMOTE_BM_WIDTH(width) (((width) + 3) >> 2)
140 #else
141 #define LCD_REMOTE_BM_WIDTH(width) (width)
142 #endif
143 #define NATIVE_BM_WIDTH(width,remote) ((remote) ? \
144 LCD_REMOTE_BM_WIDTH(width) : LCD_BM_WIDTH(width))
145 #else
146 #define NATIVE_BM_WIDTH(width,remote) LCD_BM_WIDTH(width)
147 #endif
149 /* Convenience macro to calculate elements based on height, remote vs native
150 main LCD, and format
152 #define BM_WIDTH(width,format,remote) ((format) == FORMAT_MONO ? \
153 MONO_BM_WIDTH(width) : NATIVE_BM_WIDTH(width,remote))
154 #else
155 #define BM_WIDTH(width,format,remote) MONO_BM_WIDTH(width)
156 #endif
158 /* Size in bytes of a mono bitmap of dimensions width*height */
159 #define MONO_BM_SIZE(width,height) (MONO_BM_WIDTH(width) * \
160 MONO_BM_HEIGHT(height) * FB_DATA_SZ)
162 /* Size in bytes of a native bitmap of dimensions width*height */
163 #if LCD_DEPTH > 1 || (defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1)
164 #if defined(HAVE_REMOTE_LCD) && FB_DATA_SZ != FB_RDATA_SZ
165 #define NATIVE_BM_SIZE(width,height,format,remote) \
166 (((remote) ? FB_RDATA_SZ : FB_DATA_SZ) * BM_WIDTH(width,format,remote) \
167 * BM_HEIGHT(height,format,remote))
168 #else
169 #define NATIVE_BM_SIZE(width,height,format,remote) \
170 (FB_DATA_SZ * BM_WIDTH(width,format,remote) * \
171 BM_HEIGHT(height,format,remote))
172 #endif
174 /* Convenience macro to calculate size in bytes based on height, remote vs
175 main LCD, and format
177 #define BM_SIZE(width,height,format,remote) (((format) == FORMAT_MONO) ? \
178 MONO_BM_SIZE(width,height) : NATIVE_BM_SIZE(width,height,format,remote))
179 #else
180 #define BM_SIZE(width,height,format,remote) MONO_BM_SIZE(width,height)
181 #endif
183 /* Size in bytes needed to load and scale a bitmap with target size up to
184 width*height, including overhead to allow for buffer alignment.
186 #ifdef HAVE_LCD_COLOR
187 #define BM_SCALED_SIZE(width,height,format,remote) \
188 (BM_SIZE(width,height,format,remote) + \
189 (remote ? 0 : BM_WIDTH(width,format,remote) * sizeof(uint32_t) * 9 + 3))
190 #else
191 #define BM_SCALED_SIZE(width,height,format,remote) \
192 (BM_SIZE(width,height,format,remote) + \
193 (width * sizeof(uint32_t) * 3 + 3))
194 #endif
196 /*********************************************************************
197 * read_bmp_file()
199 * Reads a 8bit BMP file and puts the data in a 1-pixel-per-byte
200 * array.
201 * Returns < 0 for error, or number of bytes used from the bitmap buffer
203 **********************************************/
204 int read_bmp_file(const char* filename,
205 struct bitmap *bm,
206 int maxsize,
207 int format,
208 const struct custom_format *cformat);
210 int read_bmp_fd(int fd,
211 struct bitmap *bm,
212 int maxsize,
213 int format,
214 const struct custom_format *cformat);
216 #if LCD_DEPTH > 1 && (defined(PLUGIN) || defined(HAVE_BMP_SCALING) || defined(HAVE_JPEG))
217 void output_row_8_native(uint32_t row, void * row_in,
218 struct scaler_context *ctx);
219 #endif
220 #endif