~drgeo-developers/drgeo/trunk

« back to all changes in this revision

Viewing changes to VMs/iPad/source/iOS/vm/OSX/BitMapConversionLogicFromX11.c

  • Committer: Hilaire Fernandes
  • Date: 2012-01-27 21:15:40 UTC
  • Revision ID: hilaire.fernandes@gmail.com-20120127211540-912spf97bhpx6mve
Initial additions

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  BitMapConversionLogicFromX11.c
 
3
 *  SqueakPureObjc
 
4
 *
 
5
 *  Created by John M McIntosh on 09-12-08.
 
6
 *  Copyright 2009 Corporate Smalltalk Consulting Ltd. All rights reserved.
 
7
 *      This code is comes from the sqUnixX11.c logic to convert Squeak Forms to 32bit image data
 
8
 *
 
9
 */
 
10
/* sqUnixX11.c -- support for display via the X Window System.
 
11
 * 
 
12
 *   Copyright (C) 1996-2008 by Ian Piumarta and other authors/contributors
 
13
 *                              listed elsewhere in this file.
 
14
 *   All rights reserved.
 
15
 *   
 
16
 *   This file is part of Unix Squeak.
 
17
 * 
 
18
 *   Permission is hereby granted, free of charge, to any person obtaining a copy
 
19
 *   of this software and associated documentation files (the "Software"), to deal
 
20
 *   in the Software without restriction, including without limitation the rights
 
21
 *   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
22
 *   copies of the Software, and to permit persons to whom the Software is
 
23
 *   furnished to do so, subject to the following conditions:
 
24
 * 
 
25
 *   The above copyright notice and this permission notice shall be included in
 
26
 *   all copies or substantial portions of the Software.
 
27
 * 
 
28
 *   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
29
 *   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
30
 *   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
31
 *   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
32
 *   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
33
 *   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
34
 *   SOFTWARE.
 
35
 */
 
36
 
 
37
#include "BitMapConversionLogicFromX11.h"
 
38
 
 
39
//#define DEBUG
 
40
#include <stdio.h>
 
41
 
 
42
void copyImage16To32(short *fromImageData, int *toImageData, int width, int height,
 
43
                                         int affectedL, int affectedT, int affectedR, int affectedB)
 
44
{
 
45
        long scanLine16, firstWord16, lastWord16;
 
46
        long scanLine32, firstWord32;
 
47
        int line;
 
48
        register unsigned int col;
 
49
 
 
50
#if defined(DEBUG)
 
51
        fprintf(stderr, "copyImg16to32 %p -> %p (%d %d) %d %d %d %d\n",
 
52
                        fromImageData, toImageData, width, height,
 
53
                        affectedT, affectedL, affectedB, affectedR);
 
54
#endif
 
55
        
 
56
#define map16To32(w) (col= (w), \
 
57
(((col >> 10) & 0x1f) << 3) | \
 
58
(((col >> 5)  & 0x1f) << 11) | \
 
59
((col & 0x1f) << 19))
 
60
        
 
61
        scanLine16= bytesPerLine(width, 16);
 
62
        firstWord16= scanLine16*affectedT + bytesPerLineRD(affectedL, 16);
 
63
        lastWord16= scanLine16*affectedT + bytesPerLine(affectedR, 16);
 
64
        scanLine32= bytesPerLine(width, 32);
 
65
        firstWord32= 0;
 
66
        
 
67
        for (line= affectedT; line < affectedB; line++)
 
68
    {
 
69
                register unsigned short *from= (unsigned short *)((long)fromImageData+firstWord16);
 
70
                register unsigned short *limit= (unsigned short *)((long)fromImageData+lastWord16);
 
71
                register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
 
72
                while (from < limit)
 
73
                {
 
74
#        if defined(WORDS_BIGENDIAN)
 
75
                        to[0]= map16To32(from[0]);
 
76
                        to[1]= map16To32(from[1]);
 
77
#        else
 
78
                        to[0]= map16To32(from[1]);
 
79
                        to[1]= map16To32(from[0]);
 
80
#        endif
 
81
                        from+= 2;
 
82
                        to+= 2;
 
83
                }
 
84
                firstWord16+= scanLine16;
 
85
                lastWord16+= scanLine16;
 
86
                firstWord32+= scanLine32;
 
87
    }
 
88
#undef map16To32
 
89
}
 
90
 
 
91
void copyImage8To32(int *fromImageData, int *toImageData, int width, int height,
 
92
                                        int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
 
93
{
 
94
        long scanLine8, firstWord8, lastWord8;
 
95
        long scanLine32, firstWord32;
 
96
        int line;
 
97
        
 
98
        scanLine8= bytesPerLine(width, 8);
 
99
        firstWord8= scanLine8*affectedT + bytesPerLineRD(affectedL, 8);
 
100
        lastWord8= scanLine8*affectedT + bytesPerLine(affectedR, 8);
 
101
        scanLine32= bytesPerLine(width, 32);
 
102
        firstWord32= 0;
 
103
        
 
104
        for (line= affectedT; line < affectedB; line++)
 
105
    {
 
106
                register unsigned char *from= (unsigned char *)((long)fromImageData+firstWord8);
 
107
                register unsigned char *limit= (unsigned char *)((long)fromImageData+lastWord8);
 
108
                register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
 
109
                while (from < limit)
 
110
                {
 
111
#        if defined(WORDS_BIGENDIAN)
 
112
                        to[0]= stColors[from[0]];
 
113
                        to[1]= stColors[from[1]];
 
114
                        to[2]= stColors[from[2]];
 
115
                        to[3]= stColors[from[3]];
 
116
#        else
 
117
                        to[0]= stColors[from[3]];
 
118
                        to[1]= stColors[from[2]];
 
119
                        to[2]= stColors[from[1]];
 
120
                        to[3]= stColors[from[0]];
 
121
#        endif
 
122
                        from+= 4;
 
123
                        to+= 4;
 
124
                }
 
125
                firstWord8+= scanLine8;
 
126
                lastWord8+= scanLine8;
 
127
                firstWord32+= scanLine32;
 
128
    }
 
129
}
 
130
 
 
131
void copyImage4To32(int *fromImageData, int *toImageData, int width, int height,
 
132
                                        int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
 
133
{
 
134
        int scanLine4, firstWord4, firstShift4;
 
135
        long scanLine32, firstWord32, lastWord32;
 
136
        long line;
 
137
        
 
138
        scanLine4= bytesPerLine(width, 4);
 
139
        firstWord4= scanLine4*affectedT + bytesPerLineRD(affectedL, 4);
 
140
        firstShift4= 28 - ((affectedL & 7) * 4);
 
141
        
 
142
        scanLine32= bytesPerLine(width, 32);
 
143
        firstWord32= 0;
 
144
        lastWord32= bytesPerLineRD(affectedR, 32);
 
145
        
 
146
        for (line= affectedT; line < affectedB; line++)
 
147
    {
 
148
                register unsigned int *from= (unsigned int *)((long)fromImageData+firstWord4);
 
149
                register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
 
150
                register unsigned int *limit= (unsigned int *)((long)toImageData+lastWord32);
 
151
                register int shift= firstShift4;
 
152
                while (to < limit)
 
153
                {
 
154
                        *to= stColors[(*from >> shift) & 15];
 
155
                        to++;
 
156
                        shift-= 4;
 
157
                        if (shift < 0)
 
158
                        {
 
159
                                shift= 28;
 
160
                                from++;
 
161
                        }
 
162
                }
 
163
                firstWord4+= scanLine4;
 
164
                firstWord32+= scanLine32;
 
165
                lastWord32+= scanLine32;
 
166
    }
 
167
}
 
168
 
 
169
void copyImage2To32(int *fromImageData, int *toImageData, int width, int height,
 
170
                                        int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
 
171
{
 
172
        long scanLine2, firstWord2, firstShift2;
 
173
        long scanLine32, firstWord32, lastWord32;
 
174
        int line;
 
175
        
 
176
        scanLine2= bytesPerLine(width, 2);
 
177
        firstWord2= scanLine2*affectedT + bytesPerLineRD(affectedL, 2);
 
178
        firstShift2= 30 - ((affectedL & 15) * 2);
 
179
        
 
180
        scanLine32= bytesPerLine(width, 32);
 
181
        firstWord32= 0;
 
182
        lastWord32= bytesPerLineRD(affectedR, 32);
 
183
        
 
184
        for (line= affectedT; line < affectedB; line++)
 
185
    {
 
186
                register unsigned int *from= (unsigned int *)((long)fromImageData+firstWord2);
 
187
                register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
 
188
                register unsigned int *limit= (unsigned int *)((long)toImageData+lastWord32);
 
189
                register int shift= firstShift2;
 
190
                while (to < limit)
 
191
                {
 
192
                        *to= stColors[(*from >> shift) & 3];
 
193
                        to++;
 
194
                        shift-= 2;
 
195
                        if (shift < 0)
 
196
                        {
 
197
                                shift= 30;
 
198
                                from++;
 
199
                        }
 
200
                }
 
201
                firstWord2+= scanLine2;
 
202
                firstWord32+= scanLine32;
 
203
                lastWord32+= scanLine32;
 
204
    }
 
205
}
 
206
 
 
207
void copyImage1To32(int *fromImageData, int *toImageData, int width, int height,
 
208
                                        int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
 
209
{
 
210
        long scanLine1, firstWord1, firstShift1;
 
211
        long scanLine32, firstWord32, lastWord32;
 
212
        int line;
 
213
        
 
214
        scanLine1= bytesPerLine(width, 1);
 
215
        firstWord1= scanLine1*affectedT + bytesPerLineRD(affectedL, 1);
 
216
        firstShift1= 31 - (affectedL & 31);
 
217
        
 
218
        scanLine32= bytesPerLine(width, 32);
 
219
        firstWord32= 0;
 
220
        lastWord32= bytesPerLine(affectedR, 32);
 
221
        
 
222
        for (line= affectedT; line < affectedB; line++)
 
223
    {
 
224
                register unsigned int *from= (unsigned int *)((long)fromImageData+firstWord1);
 
225
                register unsigned int *to= (unsigned int *)((long)toImageData+firstWord32);
 
226
                register unsigned int *limit= (unsigned int *)((long)toImageData+lastWord32);
 
227
                register int shift= firstShift1;
 
228
                while (to < limit)
 
229
                {
 
230
                        *to= stColors[(*from >> shift) & 1];
 
231
                        to++;
 
232
                        shift--;
 
233
                        if (shift < 0)
 
234
                        {
 
235
                                shift= 31;
 
236
                                from++;
 
237
                        }
 
238
                }
 
239
                firstWord1+= scanLine1;
 
240
                firstWord32+= scanLine32;
 
241
                lastWord32+= scanLine32;
 
242
    }
 
243
}