equal
deleted
inserted
replaced
35 " |
35 " |
36 ! |
36 ! |
37 |
37 |
38 version |
38 version |
39 " |
39 " |
40 $Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.3 1995-08-29 17:45:06 claus Exp $ |
40 $Header: /cvs/stx/stx/libview2/TargaReader.st,v 1.4 1995-10-25 10:16:21 cg Exp $ |
41 " |
41 " |
42 ! |
42 ! |
43 |
43 |
44 documentation |
44 documentation |
45 " |
45 " |
101 |
101 |
102 fromStream:aStream |
102 fromStream:aStream |
103 "read a targa-image from aFileName. return the receiver (with all |
103 "read a targa-image from aFileName. return the receiver (with all |
104 relevant instance variables set for the image) or nil on error" |
104 relevant instance variables set for the image) or nil on error" |
105 |
105 |
106 |depth flags| |
106 |depth flags nBytes ok| |
107 |
107 |
108 inStream := aStream. |
108 inStream := aStream. |
109 aStream binary. |
109 aStream binary. |
110 |
110 |
111 aStream skip:12. |
111 aStream skip:12. |
124 data := ByteArray new:(width * height * (depth / 8)). |
124 data := ByteArray new:(width * height * (depth / 8)). |
125 aStream nextBytes:(data size) into:data. |
125 aStream nextBytes:(data size) into:data. |
126 " |
126 " |
127 mhmh - order is blue-green-red |
127 mhmh - order is blue-green-red |
128 " |
128 " |
129 1 to:(data size - 2) by:3 do:[:i | |
129 nBytes := data size. |
130 |t| |
130 ok := false. |
131 t := data at:i. |
131 |
132 data at:i put:(data at:i+2). |
132 %{ /* OPTIONAL */ |
133 data at:i+2 put:t |
133 if (__isByteArray(_INST(data))) { |
|
134 int lastIndex = __intVal(nBytes) - 2; |
|
135 unsigned char *cp = __ByteArrayInstPtr(_INST(data))->ba_element; |
|
136 int i; |
|
137 unsigned char t; |
|
138 |
|
139 for (i=0; i<lastIndex; i+=3, cp+=3) { |
|
140 t = cp[0]; |
|
141 cp[0] = cp[2]; |
|
142 cp[2] = t; |
|
143 } |
|
144 ok = true; |
|
145 } |
|
146 %}. |
|
147 ok ifFalse:[ |
|
148 1 to:(data size - 2) by:3 do:[:i | |
|
149 |t| |
|
150 t := data at:i. |
|
151 data at:i put:(data at:i+2). |
|
152 data at:i+2 put:t |
|
153 ] |
134 ]. |
154 ]. |
135 |
155 |
136 photometric := #rgb. |
156 photometric := #rgb. |
137 samplesPerPixel := 3. |
157 samplesPerPixel := 3. |
138 bitsPerSample := #(8 8 8). |
158 bitsPerSample := #(8 8 8). |