Do some #ifdef'ing to make the Player happy.
[kugel-rb.git] / apps / gui / backdrop.c
blobc220d0649355a95f950e3a5173a803d5a596cf8e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Dave Chapman
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 ****************************************************************************/
22 #include <stdio.h>
23 #include "config.h"
24 #include "lcd.h"
25 #ifdef HAVE_REMOTE_LCD
26 #include "lcd-remote.h"
27 #endif
28 #include "backdrop.h"
30 static fb_data main_backdrop[LCD_FBHEIGHT][LCD_FBWIDTH]
31 __attribute__ ((aligned (16)));
32 static fb_data skin_backdrop[LCD_FBHEIGHT][LCD_FBWIDTH]
33 __attribute__ ((aligned (16)));
35 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
36 static fb_remote_data
37 remote_skin_backdrop[LCD_REMOTE_FBHEIGHT][LCD_REMOTE_FBWIDTH];
38 static bool remote_skin_backdrop_valid = false;
39 #endif
41 static bool main_backdrop_valid = false;
42 static bool skin_backdrop_valid = false;
44 /* load a backdrop into a buffer */
45 static bool load_backdrop(const char* filename, fb_data* backdrop_buffer)
47 struct bitmap bm;
48 int ret;
50 /* load the image */
51 bm.data=(char*)backdrop_buffer;
52 ret = read_bmp_file(filename, &bm, sizeof(main_backdrop),
53 FORMAT_NATIVE | FORMAT_DITHER, NULL);
55 return ((ret > 0)
56 && (bm.width == LCD_WIDTH) && (bm.height == LCD_HEIGHT));
59 static bool load_main_backdrop(const char* filename)
61 main_backdrop_valid = load_backdrop(filename, &main_backdrop[0][0]);
62 return main_backdrop_valid;
65 static inline bool load_skin_backdrop(const char* filename)
67 skin_backdrop_valid = load_backdrop(filename, &skin_backdrop[0][0]);
68 return skin_backdrop_valid;
71 static inline void unload_main_backdrop(void)
73 main_backdrop_valid = false;
76 static inline void unload_skin_backdrop(void)
78 skin_backdrop_valid = false;
81 static inline void show_main_backdrop(void)
83 lcd_set_backdrop(main_backdrop_valid ? &main_backdrop[0][0] : NULL);
86 static void show_skin_backdrop(void)
88 /* if no wps backdrop, fall back to main backdrop */
89 if(skin_backdrop_valid)
91 lcd_set_backdrop(&skin_backdrop[0][0]);
93 else
95 show_main_backdrop();
99 /* api functions */
101 bool backdrop_load(enum backdrop_type bdrop, const char* filename)
103 if (bdrop == BACKDROP_MAIN)
104 return load_main_backdrop(filename);
105 else if (bdrop == BACKDROP_SKIN_WPS)
106 return load_skin_backdrop(filename);
107 else
108 return false;
111 void backdrop_unload(enum backdrop_type bdrop)
113 if (bdrop == BACKDROP_MAIN)
114 unload_main_backdrop();
115 else if (bdrop == BACKDROP_SKIN_WPS)
116 unload_skin_backdrop();
119 void backdrop_show(enum backdrop_type bdrop)
121 if (bdrop == BACKDROP_MAIN)
122 show_main_backdrop();
123 else if (bdrop == BACKDROP_SKIN_WPS)
124 show_skin_backdrop();
128 #if defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
130 static bool load_remote_backdrop(const char* filename,
131 fb_remote_data* backdrop_buffer)
133 struct bitmap bm;
134 int ret;
136 /* load the image */
137 bm.data=(char*)backdrop_buffer;
138 ret = read_bmp_file(filename, &bm, sizeof(main_backdrop),
139 FORMAT_NATIVE | FORMAT_DITHER | FORMAT_REMOTE, NULL);
141 return ((ret > 0)
142 && (bm.width == LCD_REMOTE_WIDTH)
143 && (bm.height == LCD_REMOTE_HEIGHT));
146 static inline bool load_remote_skin_backdrop(const char* filename)
148 remote_skin_backdrop_valid =
149 load_remote_backdrop(filename, &remote_skin_backdrop[0][0]);
150 return remote_skin_backdrop_valid;
153 static inline void unload_remote_skin_backdrop(void)
155 remote_skin_backdrop_valid = false;
158 static inline void show_remote_main_backdrop(void)
160 lcd_remote_set_backdrop(NULL);
163 static inline void show_remote_skin_backdrop(void)
165 /* if no wps backdrop, fall back to main backdrop */
166 if(remote_skin_backdrop_valid)
168 lcd_remote_set_backdrop(&remote_skin_backdrop[0][0]);
170 else
172 show_remote_main_backdrop();
177 /* api functions */
178 bool remote_backdrop_load(enum backdrop_type bdrop,
179 const char *filename)
181 if (bdrop == BACKDROP_SKIN_WPS)
182 return load_remote_skin_backdrop(filename);
183 else if (bdrop == BACKDROP_MAIN)
184 return true;
185 else
186 return false;
189 void remote_backdrop_show(enum backdrop_type bdrop)
191 if (bdrop == BACKDROP_MAIN)
192 show_remote_main_backdrop();
193 else if (bdrop == BACKDROP_SKIN_WPS)
194 show_remote_skin_backdrop();
197 void remote_backdrop_unload(enum backdrop_type bdrop)
199 if (bdrop != BACKDROP_MAIN)
200 unload_remote_skin_backdrop();
204 #endif