summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted/sdl/lcd-remote-bitmap.c
blob: 9972f3e423a85e09b7886a04b6666c673f6b249c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2006 Dan Everton
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#include "sim-ui-defines.h"
#include "lcd-sdl.h"
#include "lcd-remote-bitmap.h"
#include "screendump.h"
#include "system.h" /* background */

SDL_Surface *remote_surface = 0;

SDL_Color remote_bl_color_dark    = {RED_CMP(LCD_REMOTE_BL_DARKCOLOR),
                                     GREEN_CMP(LCD_REMOTE_BL_DARKCOLOR),
                                     BLUE_CMP(LCD_REMOTE_BL_DARKCOLOR), 0};
SDL_Color remote_bl_color_bright  = {RED_CMP(LCD_REMOTE_BL_BRIGHTCOLOR),
                                     GREEN_CMP(LCD_REMOTE_BL_BRIGHTCOLOR),
                                     BLUE_CMP(LCD_REMOTE_BL_BRIGHTCOLOR), 0};
SDL_Color remote_color_dark    = {RED_CMP(LCD_REMOTE_DARKCOLOR),
                                  GREEN_CMP(LCD_REMOTE_DARKCOLOR),
                                  BLUE_CMP(LCD_REMOTE_DARKCOLOR), 0};
SDL_Color remote_color_bright  = {RED_CMP(LCD_REMOTE_BRIGHTCOLOR),
                                  GREEN_CMP(LCD_REMOTE_BRIGHTCOLOR),
                                  BLUE_CMP(LCD_REMOTE_BRIGHTCOLOR), 0};

#define NUM_SHADES  129

#if LCD_REMOTE_DEPTH == 2
/* Only defined for positive, non-split LCD for now */
static const unsigned char colorindex[4] = {128, 85, 43, 0};
#endif

static unsigned long get_lcd_remote_pixel(int x, int y)
{
#if LCD_REMOTE_DEPTH == 1
    return lcd_remote_framebuffer[y/8][x] & (1 << (y & 7)) ? 0 : (NUM_SHADES-1);
#elif LCD_REMOTE_DEPTH == 2
#if LCD_REMOTE_PIXELFORMAT == VERTICAL_INTERLEAVED
    unsigned bits = (lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 0x0101;
    return colorindex[(bits | (bits >> 7)) & 3];
#endif
#endif
}

void lcd_remote_update (void)
{
    lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT);
}

void lcd_remote_update_rect(int x_start, int y_start, int width, int height)
{
    if (remote_surface)
    {
        sdl_update_rect(remote_surface, x_start, y_start, width, height,
            LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, get_lcd_remote_pixel);
        sdl_gui_update(remote_surface, x_start, y_start, width, height,
            LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, background ? UI_REMOTE_POSX : 0,
            background ? UI_REMOTE_POSY : LCD_HEIGHT);
    }
}

void sim_remote_backlight(int value)
{
    if (remote_surface)
    {
        if (value > 0) 
        {
            sdl_set_gradient(remote_surface, &remote_bl_color_dark,
                             &remote_bl_color_bright, 0, NUM_SHADES);
        } 
        else
        {
            sdl_set_gradient(remote_surface, &remote_color_dark,
                             &remote_color_bright, 0, NUM_SHADES);
        }
        sdl_gui_update(remote_surface, 0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
                       LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
                       background ? UI_REMOTE_POSX : 0,
                       background? UI_REMOTE_POSY : LCD_HEIGHT);
    }
}

/* initialise simulator lcd remote driver */
void sim_lcd_remote_init(void)
{
    remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
                                          LCD_REMOTE_WIDTH * display_zoom,
                                          LCD_REMOTE_HEIGHT * display_zoom,
                                          8, 0, 0, 0, 0);

    sdl_set_gradient(remote_surface, &remote_bl_color_dark,
                     &remote_bl_color_bright, 0, NUM_SHADES);
}