2
* BitMapConversionLogicFromX11.c
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
10
/* sqUnixX11.c -- support for display via the X Window System.
12
* Copyright (C) 1996-2008 by Ian Piumarta and other authors/contributors
13
* listed elsewhere in this file.
14
* All rights reserved.
16
* This file is part of Unix Squeak.
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:
25
* The above copyright notice and this permission notice shall be included in
26
* all copies or substantial portions of the Software.
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
37
#include "BitMapConversionLogicFromX11.h"
42
void copyImage16To32(short *fromImageData, int *toImageData, int width, int height,
43
int affectedL, int affectedT, int affectedR, int affectedB)
45
long scanLine16, firstWord16, lastWord16;
46
long scanLine32, firstWord32;
48
register unsigned int col;
51
fprintf(stderr, "copyImg16to32 %p -> %p (%d %d) %d %d %d %d\n",
52
fromImageData, toImageData, width, height,
53
affectedT, affectedL, affectedB, affectedR);
56
#define map16To32(w) (col= (w), \
57
(((col >> 10) & 0x1f) << 3) | \
58
(((col >> 5) & 0x1f) << 11) | \
61
scanLine16= bytesPerLine(width, 16);
62
firstWord16= scanLine16*affectedT + bytesPerLineRD(affectedL, 16);
63
lastWord16= scanLine16*affectedT + bytesPerLine(affectedR, 16);
64
scanLine32= bytesPerLine(width, 32);
67
for (line= affectedT; line < affectedB; line++)
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);
74
# if defined(WORDS_BIGENDIAN)
75
to[0]= map16To32(from[0]);
76
to[1]= map16To32(from[1]);
78
to[0]= map16To32(from[1]);
79
to[1]= map16To32(from[0]);
84
firstWord16+= scanLine16;
85
lastWord16+= scanLine16;
86
firstWord32+= scanLine32;
91
void copyImage8To32(int *fromImageData, int *toImageData, int width, int height,
92
int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
94
long scanLine8, firstWord8, lastWord8;
95
long scanLine32, firstWord32;
98
scanLine8= bytesPerLine(width, 8);
99
firstWord8= scanLine8*affectedT + bytesPerLineRD(affectedL, 8);
100
lastWord8= scanLine8*affectedT + bytesPerLine(affectedR, 8);
101
scanLine32= bytesPerLine(width, 32);
104
for (line= affectedT; line < affectedB; line++)
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);
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]];
117
to[0]= stColors[from[3]];
118
to[1]= stColors[from[2]];
119
to[2]= stColors[from[1]];
120
to[3]= stColors[from[0]];
125
firstWord8+= scanLine8;
126
lastWord8+= scanLine8;
127
firstWord32+= scanLine32;
131
void copyImage4To32(int *fromImageData, int *toImageData, int width, int height,
132
int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
134
int scanLine4, firstWord4, firstShift4;
135
long scanLine32, firstWord32, lastWord32;
138
scanLine4= bytesPerLine(width, 4);
139
firstWord4= scanLine4*affectedT + bytesPerLineRD(affectedL, 4);
140
firstShift4= 28 - ((affectedL & 7) * 4);
142
scanLine32= bytesPerLine(width, 32);
144
lastWord32= bytesPerLineRD(affectedR, 32);
146
for (line= affectedT; line < affectedB; line++)
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;
154
*to= stColors[(*from >> shift) & 15];
163
firstWord4+= scanLine4;
164
firstWord32+= scanLine32;
165
lastWord32+= scanLine32;
169
void copyImage2To32(int *fromImageData, int *toImageData, int width, int height,
170
int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
172
long scanLine2, firstWord2, firstShift2;
173
long scanLine32, firstWord32, lastWord32;
176
scanLine2= bytesPerLine(width, 2);
177
firstWord2= scanLine2*affectedT + bytesPerLineRD(affectedL, 2);
178
firstShift2= 30 - ((affectedL & 15) * 2);
180
scanLine32= bytesPerLine(width, 32);
182
lastWord32= bytesPerLineRD(affectedR, 32);
184
for (line= affectedT; line < affectedB; line++)
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;
192
*to= stColors[(*from >> shift) & 3];
201
firstWord2+= scanLine2;
202
firstWord32+= scanLine32;
203
lastWord32+= scanLine32;
207
void copyImage1To32(int *fromImageData, int *toImageData, int width, int height,
208
int affectedL, int affectedT, int affectedR, int affectedB, unsigned int * stColors)
210
long scanLine1, firstWord1, firstShift1;
211
long scanLine32, firstWord32, lastWord32;
214
scanLine1= bytesPerLine(width, 1);
215
firstWord1= scanLine1*affectedT + bytesPerLineRD(affectedL, 1);
216
firstShift1= 31 - (affectedL & 31);
218
scanLine32= bytesPerLine(width, 32);
220
lastWord32= bytesPerLine(affectedR, 32);
222
for (line= affectedT; line < affectedB; line++)
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;
230
*to= stColors[(*from >> shift) & 1];
239
firstWord1+= scanLine1;
240
firstWord32+= scanLine32;
241
lastWord32+= scanLine32;