author | Claus Gittinger <cg@exept.de> |
Fri, 27 Jun 1997 18:47:27 +0200 | |
changeset 630 | 48657c687a8b |
parent 556 | a2d03470af59 |
child 647 | 6f26c76aa0c9 |
permissions | -rw-r--r-- |
37 | 1 |
" |
2 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
13 |
ImageReader subclass:#TargaReader |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
14 |
instanceVariableNames:'orientation' |
210 | 15 |
classVariableNames:'' |
16 |
poolDictionaries:'' |
|
259 | 17 |
category:'Graphics-Images-Support' |
37 | 18 |
! |
19 |
||
20 |
!TargaReader class methodsFor:'documentation'! |
|
21 |
||
22 |
copyright |
|
23 |
" |
|
24 |
COPYRIGHT (c) 1994 by Claus Gittinger |
|
25 |
All Rights Reserved |
|
26 |
||
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
36 |
documentation |
|
37 |
" |
|
38 |
this class provides methods for loading targa-file (tga) images. |
|
556 | 39 |
|
37 | 40 |
Limitations: |
556 | 41 |
not fully tested (I only had a few targa files to check things) |
42 |
only supports 8,24 and 32 bits/pixel formats; alpha channel is ignored |
|
210 | 43 |
Image saving not supported |
37 | 44 |
|
45 |
I had two tga files to test this code with - it may not work with |
|
556 | 46 |
other targa files (it certainly does not work with 1/16 bit images). |
299 | 47 |
|
37 | 48 |
Suggestions: adapt & use the pbmplus library here. |
210 | 49 |
|
50 |
[See also:] |
|
234 | 51 |
Image Form Icon |
210 | 52 |
BlitImageReader FaceReader GIFReader JPEGReader PBMReader PCXReader |
53 |
ST80FormReader SunRasterReader TIFFReader WindowsIconReader |
|
54 |
XBMReader XPMReader XWDReader |
|
37 | 55 |
" |
56 |
! ! |
|
57 |
||
58 |
!TargaReader class methodsFor:'initialization'! |
|
59 |
||
60 |
initialize |
|
210 | 61 |
"tell Image-class, that a new fileReader is present |
398 | 62 |
for the '.tga' extension." |
210 | 63 |
|
630 | 64 |
Image addReader:self suffix:'tga' mimeType:'image/x-targa'. |
37 | 65 |
|
630 | 66 |
"Modified: 27.6.1997 / 18:39:43 / cg" |
37 | 67 |
! ! |
68 |
||
69 |
!TargaReader class methodsFor:'testing'! |
|
70 |
||
71 |
isValidImageFile:aFileName |
|
72 |
"return true, if aFileName contains a targa-file image" |
|
73 |
||
43 | 74 |
|aStream w h depth flags| |
37 | 75 |
|
43 | 76 |
aStream := self streamReadingFile:aFileName. |
77 |
aStream isNil ifTrue:[^ false]. |
|
78 |
aStream binary. |
|
79 |
aStream skip:12. "/ skip 12 bytes |
|
37 | 80 |
|
43 | 81 |
w := aStream nextShortMSB:false. |
82 |
h := aStream nextShortMSB:false. |
|
37 | 83 |
|
43 | 84 |
depth := aStream next. |
85 |
flags := aStream next. |
|
37 | 86 |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
87 |
(#(8 "16" 24 32) includes:depth) ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
88 |
aStream close. ^ false |
37 | 89 |
]. |
90 |
||
43 | 91 |
aStream close. |
37 | 92 |
^ true |
93 |
||
94 |
" |
|
95 |
TargaReader isValidImageFile:'bitmaps/test.tga' |
|
96 |
TargaReader isValidImageFile:'bitmaps/garfield.gif' |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
97 |
" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
98 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
99 |
"Modified: 21.4.1997 / 20:46:52 / cg" |
37 | 100 |
! ! |
101 |
||
102 |
!TargaReader methodsFor:'reading from file'! |
|
103 |
||
43 | 104 |
fromStream:aStream |
37 | 105 |
"read a targa-image from aFileName. return the receiver (with all |
106 |
relevant instance variables set for the image) or nil on error" |
|
107 |
||
299 | 108 |
|depth flags nBytes ok lenID hasColorMap imageType |
109 |
cmapOffset cmapLength cmapEntrySize xOrg yOrg |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
110 |
t bytesPerPixel bytesPerRow rowIdx startIdx endIdx rle |
299 | 111 |
dSize "{ Class: SmallInteger }" | |
37 | 112 |
|
43 | 113 |
inStream := aStream. |
114 |
aStream binary. |
|
115 |
||
299 | 116 |
lenID := aStream next. |
117 |
hasColorMap := aStream next. |
|
118 |
imageType := aStream next. |
|
119 |
cmapOffset := aStream nextShortMSB:false. |
|
120 |
cmapLength := aStream nextShortMSB:false. |
|
121 |
cmapEntrySize := aStream next. |
|
122 |
xOrg := aStream nextShortMSB:false. |
|
123 |
yOrg := aStream nextShortMSB:false. |
|
124 |
||
43 | 125 |
width := aStream nextShortMSB:false. |
126 |
height := aStream nextShortMSB:false. |
|
127 |
depth := aStream next. |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
128 |
(#(8 "16" 24 32) includes:depth) ifFalse:[ |
551 | 129 |
'TargaReader [warning]: unsupported depth: ' errorPrint. depth errorPrintCR. |
299 | 130 |
^ nil |
37 | 131 |
]. |
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
132 |
depth == 32 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
133 |
'TargaReader [info]: alpha channel ignored' infoPrintCR. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
134 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
135 |
'TargaReader [info]: depth: ' infoPrint. depth infoPrintCR. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
136 |
]. |
551 | 137 |
|
138 |
"/ MapRGB == 1 |
|
139 |
"/ RawRGB == 2 |
|
140 |
"/ RawMono == 3 |
|
141 |
"/ MapEnCode == 9 |
|
142 |
"/ RawEnCode == 10 |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
143 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
144 |
(#(1 2 9 10) includes:imageType) ifFalse:[ |
551 | 145 |
'TargaReader [warning]: unsupported imageType: ' errorPrint. imageType errorPrintCR. |
146 |
]. |
|
147 |
'TargaReader [info]: imageType: ' infoPrint. imageType infoPrintCR. |
|
299 | 148 |
|
149 |
"/ flags: |
|
150 |
"/ 0000 xxxx attribute-bits-per-pixel |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
151 |
"/ 0000 0001 greysc |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
152 |
"/ 0000 0010 colour |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
153 |
"/ 0000 0011 mapped |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
154 |
"/ 0000 0100 rleEncoded |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
155 |
"/ 0000 1000 interlaced |
299 | 156 |
"/ 00xx 0000 origin (0 -> lower-left / 1 -> l-r / 2 -> u-l / 3 -> u-r) |
157 |
"/ xx00 0000 interleave (0 -> none / 1 -> odd/even / 2 ->4-fould / 3 reserved) |
|
158 |
"/ |
|
43 | 159 |
flags := aStream next. |
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
160 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
161 |
(flags bitAnd:2r11000000) ~~ 0 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
162 |
'TargaReader [warning]: unsupported interlace: ' errorPrint. flags errorPrintCR. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
163 |
^ nil |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
164 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
165 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
166 |
rle := flags bitTest:2r000001000. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
167 |
flags := flags bitAnd:2r111110111. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
168 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
169 |
(flags bitAnd:2r00001111) ~~ 0 ifTrue:[ |
551 | 170 |
'TargaReader [warning]: unsupported flags: ' errorPrint. flags errorPrintCR. |
171 |
^ nil |
|
172 |
]. |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
173 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
174 |
(flags bitAnd:2r00110000) == 16r20 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
175 |
orientation := #topLeft |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
176 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
177 |
(flags bitAnd:2r00110000) == 16r30 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
178 |
orientation := #topRight |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
179 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
180 |
(flags bitAnd:2r00110000) == 16r10 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
181 |
orientation := #bottomRight |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
182 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
183 |
(flags bitAnd:2r00110000) == 0 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
184 |
orientation := #bottomLeft |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
185 |
] |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
186 |
] |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
187 |
] |
299 | 188 |
]. |
189 |
||
190 |
lenID ~~ 0 ifTrue:[ |
|
191 |
aStream skip:lenID |
|
37 | 192 |
]. |
193 |
||
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
194 |
hasColorMap ~~ 0 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
195 |
"/ read the colorMap |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
196 |
colorMap := Array new:cmapLength. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
197 |
1 to:cmapLength do:[:index | |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
198 |
|r g b| |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
199 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
200 |
b := aStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
201 |
g := aStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
202 |
r := aStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
203 |
colorMap at:index put:(Color redByte:r greenByte:g blueByte:b). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
204 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
205 |
'TargaReader [info]: has colorMap' infoPrintCR. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
206 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
207 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
208 |
depth == 32 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
209 |
imageType == 2 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
210 |
"/ rle ifTrue:[self halt]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
211 |
self read32. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
212 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
213 |
"/ rle ifFalse:[self halt]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
214 |
self read32RLE. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
215 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
216 |
bytesPerRow := width*3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
217 |
bytesPerPixel := 3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
218 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
219 |
depth == 24 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
220 |
imageType == 2 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
221 |
"/ rle ifTrue:[self halt]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
222 |
self read24. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
223 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
224 |
"/ rle ifFalse:[self halt]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
225 |
self read24RLE. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
226 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
227 |
bytesPerRow := width*3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
228 |
bytesPerPixel := 3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
229 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
230 |
depth == 8 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
231 |
imageType == 1 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
232 |
"/ rle ifTrue:[self halt]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
233 |
self read8. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
234 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
235 |
"/ rle ifFalse:[self halt]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
236 |
self read8RLE |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
237 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
238 |
bytesPerRow := width. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
239 |
bytesPerPixel := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
240 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
241 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
242 |
orientation == #topLeft ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
243 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
244 |
orientation == #topRight ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
245 |
"/ flip horizontal |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
246 |
rowIdx := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
247 |
1 to:height do:[:row | |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
248 |
startIdx := rowIdx. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
249 |
endIdx := rowIdx + bytesPerRow - bytesPerPixel. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
250 |
1 to:width//2 do:[:x | |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
251 |
0 to:bytesPerPixel-1 do:[:c | |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
252 |
t := data at:startIdx+c. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
253 |
data at:startIdx+c put:(data at:endIdx+c). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
254 |
data at:endIdx+c put:t. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
255 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
256 |
startIdx := startIdx + bytesPerPixel. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
257 |
endIdx := endIdx - bytesPerPixel. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
258 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
259 |
rowIdx := rowIdx + width. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
260 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
261 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
262 |
orientation == #bottomLeft ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
263 |
"/ flip vertical |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
264 |
startIdx := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
265 |
endIdx := 1 + ((height - 1) * bytesPerRow). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
266 |
t := ByteArray new:bytesPerRow. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
267 |
1 to:height//2 do:[:row | |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
268 |
t replaceFrom:1 to:bytesPerRow with:data startingAt:startIdx. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
269 |
data replaceFrom:startIdx to:startIdx+bytesPerRow-1 with:data startingAt:endIdx. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
270 |
data replaceFrom:endIdx to:endIdx+bytesPerRow-1 with:t startingAt:1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
271 |
startIdx := startIdx + bytesPerRow. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
272 |
endIdx := endIdx - bytesPerRow |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
273 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
274 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
275 |
'TargaReader [warning]: unsupported orientation: ' errorPrint. orientation errorPrintCR. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
276 |
] |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
277 |
] |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
278 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
279 |
^ self |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
280 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
281 |
" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
282 |
TargaReader fromFile:'bitmaps/test.tga' |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
283 |
" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
284 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
285 |
"Modified: 21.4.1997 / 21:03:36 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
286 |
! |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
287 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
288 |
read24 |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
289 |
"read a 24 bit/pixel targa-image" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
290 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
291 |
|nBytes ok dSize t| |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
292 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
293 |
data := ByteArray new:(width * height * 3). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
294 |
inStream nextBytes:(dSize := data size) into:data. |
299 | 295 |
|
37 | 296 |
" |
299 | 297 |
mhmh - pixel-byte order is blue-green-red |
298 |
swap blue & red bytes |
|
37 | 299 |
" |
107 | 300 |
nBytes := data size. |
301 |
ok := false. |
|
302 |
||
303 |
%{ /* OPTIONAL */ |
|
304 |
if (__isByteArray(_INST(data))) { |
|
299 | 305 |
int __lastIndex = __intVal(nBytes) - 2; |
306 |
unsigned char *__cp = __ByteArrayInstPtr(_INST(data))->ba_element; |
|
307 |
int __i; |
|
308 |
unsigned char __t; |
|
107 | 309 |
|
299 | 310 |
for (__i=0; __i<__lastIndex; __i+=3, __cp+=3) { |
311 |
__t = __cp[0]; |
|
312 |
__cp[0] = __cp[2]; |
|
313 |
__cp[2] = __t; |
|
314 |
} |
|
315 |
ok = true; |
|
107 | 316 |
} |
317 |
%}. |
|
318 |
ok ifFalse:[ |
|
299 | 319 |
1 to:(dSize - 2) by:3 do:[:i | |
320 |
t := data at:i. |
|
321 |
data at:i put:(data at:i+2). |
|
322 |
data at:i+2 put:t |
|
323 |
] |
|
37 | 324 |
]. |
325 |
||
326 |
photometric := #rgb. |
|
327 |
samplesPerPixel := 3. |
|
328 |
bitsPerSample := #(8 8 8). |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
329 |
! |
37 | 330 |
|
555
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
331 |
read24RLE |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
332 |
"read an 8 bit/pixel rle encoded targa-image" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
333 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
334 |
|total count dstIndex code n r g b| |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
335 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
336 |
data := ByteArray new:((total := width * height * 3)). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
337 |
count := 0. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
338 |
dstIndex := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
339 |
[count < total] whileTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
340 |
code := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
341 |
n := (code bitAnd:16r7F) + 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
342 |
(code bitAnd:16r80) ~~ 0 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
343 |
b := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
344 |
g := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
345 |
r := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
346 |
n timesRepeat:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
347 |
data at:dstIndex put:r. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
348 |
data at:dstIndex+1 put:g. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
349 |
data at:dstIndex+2 put:b. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
350 |
dstIndex := dstIndex + 3 |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
351 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
352 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
353 |
n timesRepeat:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
354 |
b := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
355 |
g := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
356 |
r := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
357 |
data at:dstIndex put:r. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
358 |
data at:dstIndex+1 put:g. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
359 |
data at:dstIndex+2 put:b. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
360 |
dstIndex := dstIndex + 3 |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
361 |
] |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
362 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
363 |
count := count + (n * 3). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
364 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
365 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
366 |
photometric := #rgb. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
367 |
samplesPerPixel := 3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
368 |
bitsPerSample := #(8 8 8). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
369 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
370 |
"Modified: 21.4.1997 / 20:21:12 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
371 |
"Created: 21.4.1997 / 20:43:23 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
372 |
! |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
373 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
374 |
read32 |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
375 |
"read a 32 bit/pixel targa-image; skip alpha channel (for now)" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
376 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
377 |
|total dstIndex a r g b| |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
378 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
379 |
data := ByteArray new:((total := width * height * 3)). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
380 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
381 |
dstIndex := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
382 |
[total > 0] whileTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
383 |
inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
384 |
a := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
385 |
b := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
386 |
g := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
387 |
r := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
388 |
data at:dstIndex put:r. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
389 |
data at:dstIndex+1 put:g. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
390 |
data at:dstIndex+2 put:b. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
391 |
dstIndex := dstIndex + 3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
392 |
total := total - 3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
393 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
394 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
395 |
photometric := #rgb. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
396 |
samplesPerPixel := 3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
397 |
bitsPerSample := #(8 8 8). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
398 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
399 |
"Modified: 21.4.1997 / 20:21:12 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
400 |
"Created: 21.4.1997 / 20:45:35 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
401 |
! |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
402 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
403 |
read32RLE |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
404 |
"read a 32 bit/pixel rle encoded targa-image; skip alpha channel (for now)" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
405 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
406 |
|total count dstIndex code n a r g b| |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
407 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
408 |
data := ByteArray new:((total := width * height * 3)). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
409 |
count := 0. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
410 |
dstIndex := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
411 |
[count < total] whileTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
412 |
code := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
413 |
n := (code bitAnd:16r7F) + 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
414 |
(code bitAnd:16r80) ~~ 0 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
415 |
a := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
416 |
b := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
417 |
g := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
418 |
r := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
419 |
n timesRepeat:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
420 |
data at:dstIndex put:r. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
421 |
data at:dstIndex+1 put:g. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
422 |
data at:dstIndex+2 put:b. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
423 |
dstIndex := dstIndex + 3 |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
424 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
425 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
426 |
n timesRepeat:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
427 |
a := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
428 |
b := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
429 |
g := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
430 |
r := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
431 |
data at:dstIndex put:r. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
432 |
data at:dstIndex+1 put:g. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
433 |
data at:dstIndex+2 put:b. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
434 |
dstIndex := dstIndex + 3 |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
435 |
] |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
436 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
437 |
count := count + (n * 3). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
438 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
439 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
440 |
photometric := #rgb. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
441 |
samplesPerPixel := 3. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
442 |
bitsPerSample := #(8 8 8). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
443 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
444 |
"Created: 21.4.1997 / 20:43:54 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
445 |
"Modified: 21.4.1997 / 20:45:49 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
446 |
! |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
447 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
448 |
read8 |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
449 |
"read an 8 bit/pixel targa-image" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
450 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
451 |
data := ByteArray new:(width * height). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
452 |
inStream nextBytes:(data size) into:data. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
453 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
454 |
colorMap isNil ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
455 |
photometric := #blackIs0. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
456 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
457 |
photometric := #palette. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
458 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
459 |
samplesPerPixel := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
460 |
bitsPerSample := #(8). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
461 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
462 |
"Created: 21.4.1997 / 20:12:35 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
463 |
"Modified: 21.4.1997 / 20:39:02 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
464 |
! |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
465 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
466 |
read8RLE |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
467 |
"read an 8 bit/pixel rle encoded targa-image" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
468 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
469 |
|total count dstIndex code n byte| |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
470 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
471 |
data := ByteArray new:((total := width * height)). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
472 |
count := 0. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
473 |
dstIndex := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
474 |
[count < total] whileTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
475 |
code := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
476 |
n := (code bitAnd:16r7F) + 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
477 |
(code bitAnd:16r80) ~~ 0 ifTrue:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
478 |
byte := inStream nextByte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
479 |
data from:dstIndex to:dstIndex+n-1 put:byte. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
480 |
] ifFalse:[ |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
481 |
inStream nextBytes:n into:data startingAt:dstIndex. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
482 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
483 |
count := count + n. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
484 |
dstIndex := dstIndex + n. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
485 |
]. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
486 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
487 |
photometric := #palette. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
488 |
samplesPerPixel := 1. |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
489 |
bitsPerSample := #(8). |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
490 |
|
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
491 |
"Created: 21.4.1997 / 20:19:46 / cg" |
f51ec2cc4482
support RLE, 8 and 32 bit images
Claus Gittinger <cg@exept.de>
parents:
551
diff
changeset
|
492 |
"Modified: 21.4.1997 / 20:21:12 / cg" |
37 | 493 |
! ! |
494 |
||
210 | 495 |
!TargaReader class methodsFor:'documentation'! |
496 |
||
497 |
version |
|
630 | 498 |
^ '$Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.14 1997-06-27 16:47:23 cg Exp $' |
210 | 499 |
! ! |
37 | 500 |
TargaReader initialize! |