blob: f3c2902adf9b17460b47fcb2c1d4bee6813d71fc [file] [log] [blame]
adamdunkelsc0bd88f2003-04-24 13:27:02 +00001/*
2 * Copyright (c) 2003, Adam Dunkels.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials provided
13 * with the distribution.
adamdunkels16a7b262004-07-04 21:15:53 +000014 * 3. The name of the author may not be used to endorse or promote
adamdunkelsc0bd88f2003-04-24 13:27:02 +000015 * products derived from this software without specific prior
16 * written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * This file is part of the Contiki VNC client
31 *
adamdunkels16a7b262004-07-04 21:15:53 +000032 * $Id: vnc-draw.c,v 1.2 2004/07/04 21:15:53 adamdunkels Exp $
adamdunkelsc0bd88f2003-04-24 13:27:02 +000033 *
34 */
35
36
37
38#include "vnc-draw.h"
39
40#include "vnc-conf.h"
41
42
43static unsigned char conv[256];
44
45static unsigned char oratab[8] =
46 { 0x80, 0x40, 0x20, 0x10,
47 0x08, 0x04, 0x02, 0x01 };
48static unsigned char andtab[8] =
49 { 0x7f, 0xbf, 0xdf, 0xef,
50 0xf7, 0xfb, 0xfd, 0xfe };
51
52static u8_t *bitmapptrtab[VNC_CONF_VIEWPORT_HEIGHT];
53
54static unsigned short viewport_x,
55 viewport_y, viewport_w, viewport_h;
56
57u8_t vnc_draw_bitmap[(VNC_CONF_VIEWPORT_WIDTH / 8) *
58 VNC_CONF_VIEWPORT_HEIGHT];
59
60
61
62u16_t vnc_draw_x;
63u16_t vnc_draw_y;
64u8_t *vnc_draw_dataptr;
65u8_t *vnc_draw_bitmapptr;
66u16_t vnc_draw_datalen;
67
68/*-----------------------------------------------------------------------------------*/
69void
70vnc_draw_pixel(u16_t x, u8_t y, u8_t c)
71{
72 u8_t o, a;
73
74 vnc_draw_bitmapptr = bitmapptrtab[y] + (x & 0x1f8);
75
76 if(c) {
77 o = oratab[x & 7];
78 *vnc_draw_bitmapptr = *vnc_draw_bitmapptr | o;
79 } else {
80 a = andtab[x & 7];
81 *vnc_draw_bitmapptr = *vnc_draw_bitmapptr & a;
82 }
83}
84/*-----------------------------------------------------------------------------------*/
85void
86vnc_draw_pixelline(u16_t x, u16_t y, u8_t *data, u16_t datalen)
87{
88 u8_t o, a;
89 register u8_t *bitmapptr;
90
91 vnc_draw_x = x - viewport_x;
92 vnc_draw_y = y - viewport_y;
93
94 /* if(vnc_draw_y & 1) {
95 return;
96 } else {
97 vnc_draw_y /= 2;
98 }*/
99
100
101
102 if(vnc_draw_y >= VNC_CONF_VIEWPORT_HEIGHT ||
103 vnc_draw_x >= VNC_CONF_VIEWPORT_WIDTH) {
104 return;
105 }
106
107 vnc_draw_datalen = datalen;
108
109 if(vnc_draw_datalen + vnc_draw_x >= VNC_CONF_VIEWPORT_WIDTH) {
110 vnc_draw_datalen = VNC_CONF_VIEWPORT_WIDTH - vnc_draw_x;
111 if(vnc_draw_datalen == 0) {
112 return;
113 }
114 }
115
116 vnc_draw_dataptr = data;
117
118 /* vnc_draw_bitmapptr = bitmaptab[vnc_draw_y] +
119 (vnc_draw_x & 0x1f8);*/
120
121 for(; vnc_draw_datalen > 0; --vnc_draw_datalen) {
122 /* vnc_draw_pixel(vnc_draw_x, vnc_draw_y,
123 conv[*vnc_draw_dataptr]);*/
124
125 bitmapptr = bitmapptrtab[vnc_draw_y] + (vnc_draw_x & 0x1f8);
126
127 if(conv[*vnc_draw_dataptr]) {
128 o = oratab[vnc_draw_x & 7];
129 *bitmapptr = *bitmapptr | o;
130 } else {
131 a = andtab[vnc_draw_x & 7];
132 *bitmapptr = *bitmapptr & a;
133 }
134 ++vnc_draw_dataptr;
135 ++vnc_draw_x;
136 }
137}
138/*-----------------------------------------------------------------------------------*/
139void
140vnc_draw_init(void)
141{
142 unsigned int tmp;
143 unsigned int i;
144 unsigned short ptr;
145
146
147 /* Create color conversion table. */
148 for(i = 0; i < 256; ++i) {
149 if(((i & 0xc0) > 0xc0) ||
150 ((i & 0x38) > 0x18) ||
151 ((i & 0x07) > 0x03)) {
152 conv[i] = 0;
153 } else {
154 conv[i] = 1;
155 }
156 }
157
158 memset(vnc_draw_bitmap, 0, sizeof(vnc_draw_bitmap));
159
160 for(i = 0; i < VNC_CONF_VIEWPORT_HEIGHT; ++i) {
161 bitmapptrtab[i] = (u8_t *)((u8_t *)vnc_draw_bitmap +
162 ((i & 0xfff8)/8) * VNC_CONF_VIEWPORT_WIDTH +
163 (i & 7));
164 }
165
166 viewport_x = 0;
167 viewport_y = 0;
168
169 viewport_w = VNC_CONF_VIEWPORT_WIDTH;
170 viewport_h = VNC_CONF_VIEWPORT_HEIGHT;
171
172 return;
173}
174/*-----------------------------------------------------------------------------------*/
175u16_t
176vnc_draw_viewport_x(void)
177{
178 return viewport_x;
179}
180/*-----------------------------------------------------------------------------------*/
181u16_t
182vnc_draw_viewport_y(void)
183{
184 return viewport_y;
185}
186/*-----------------------------------------------------------------------------------*/
187u16_t
188vnc_draw_viewport_w(void)
189{
190 return viewport_w;
191}
192/*-----------------------------------------------------------------------------------*/
193u16_t
194vnc_draw_viewport_h(void)
195{
196 return viewport_h;
197}
198/*-----------------------------------------------------------------------------------*/