1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
28 #ifdef HAVE_REMOTE_LCD
29 #include "lcd-remote.h"
32 #define ARRAY_SIZE(array) (int)(sizeof(array)/(sizeof(array[0])))
34 #define IMG_NORESIZE 0
36 #define BM_MAX_WIDTH (((LCD_WIDTH) + 7) & ~7)
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))
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;
75 return (2 * (unsigned)color
.red
+ 5 * (unsigned)color
.green
76 + (unsigned)color
.blue
) / 8;
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];
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)
97 #define LCD_BM_HEIGHT(height) (height)
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)
108 #define LCD_REMOTE_BM_HEIGHT(height) (height)
110 #define NATIVE_BM_HEIGHT(height,remote) ((remote) ? \
111 LCD_REMOTE_BM_HEIGHT(height) : LCD_BM_HEIGHT(height))
113 #define NATIVE_BM_HEIGHT(height,remote) LCD_BM_HEIGHT(height)
116 /* Convenience macro to calculate rows based on height, remote vs main LCD,
119 #define BM_HEIGHT(height,format,remote) ((format) == FORMAT_MONO ? \
120 MONO_BM_HEIGHT(height) : NATIVE_BM_HEIGHT(height,remote))
122 #define BM_HEIGHT(height,format,remote) MONO_BM_HEIGHT(height)
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 */
130 #if LCD_DEPTH == 2 && LCD_PIXELFORMAT == HORIZONTAL_PACKING
131 #define LCD_BM_WIDTH(width) (((width) + 3) >> 2)
133 #define LCD_BM_WIDTH(width) (width)
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)
141 #define LCD_REMOTE_BM_WIDTH(width) (width)
143 #define NATIVE_BM_WIDTH(width,remote) ((remote) ? \
144 LCD_REMOTE_BM_WIDTH(width) : LCD_BM_WIDTH(width))
146 #define NATIVE_BM_WIDTH(width,remote) LCD_BM_WIDTH(width)
149 /* Convenience macro to calculate elements based on height, remote vs native
152 #define BM_WIDTH(width,format,remote) ((format) == FORMAT_MONO ? \
153 MONO_BM_WIDTH(width) : NATIVE_BM_WIDTH(width,remote))
155 #define BM_WIDTH(width,format,remote) MONO_BM_WIDTH(width)
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))
169 #define NATIVE_BM_SIZE(width,height,format,remote) \
170 (FB_DATA_SZ * BM_WIDTH(width,format,remote) * \
171 BM_HEIGHT(height,format,remote))
174 /* Convenience macro to calculate size in bytes based on height, remote vs
177 #define BM_SIZE(width,height,format,remote) (((format) == FORMAT_MONO) ? \
178 MONO_BM_SIZE(width,height) : NATIVE_BM_SIZE(width,height,format,remote))
180 #define BM_SIZE(width,height,format,remote) MONO_BM_SIZE(width,height)
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))
191 #define BM_SCALED_SIZE(width,height,format,remote) \
192 (BM_SIZE(width,height,format,remote) + \
193 (width * sizeof(uint32_t) * 3 + 3))
196 /*********************************************************************
199 * Reads a 8bit BMP file and puts the data in a 1-pixel-per-byte
201 * Returns < 0 for error, or number of bytes used from the bitmap buffer
203 **********************************************/
204 int read_bmp_file(const char* filename
,
208 const struct custom_format
*cformat
);
210 int read_bmp_fd(int fd
,
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
);