author | Claus Gittinger <cg@exept.de> |
Wed, 22 Jan 2020 16:46:53 +0100 | |
changeset 8974 | f00c923a5748 |
parent 8757 | 5410e9509f3c |
permissions | -rw-r--r-- |
8757 | 1 |
"{ Encoding: utf8 }" |
2 |
||
193 | 3 |
" |
4 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
5 |
All Rights Reserved |
|
6 |
||
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
3263 | 14 |
"{ Package: 'stx:libview' }" |
15 |
||
7190 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
193 | 18 |
Image subclass:#Depth16Image |
579 | 19 |
instanceVariableNames:'' |
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'Graphics-Images' |
|
193 | 23 |
! |
24 |
||
25 |
!Depth16Image class methodsFor:'documentation'! |
|
26 |
||
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
30 |
All Rights Reserved |
|
31 |
||
32 |
This software is furnished under a license and may be used |
|
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
43 |
this class represents 16 bit images. |
|
44 |
Only the minimum protocol is implemented here; much more is |
|
45 |
needed for higher performance operations on depth16 images. |
|
46 |
(however, 16bit images are seldom used, so falling back into the |
|
47 |
slow general methods from Image should not hurt too much ..) |
|
611 | 48 |
|
49 |
[author:] |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
50 |
Claus Gittinger |
611 | 51 |
|
52 |
[see also:] |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
53 |
Depth1Image Depth2Image Depth4Image Depth8Image Depth24Image |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
54 |
ImageReader |
193 | 55 |
" |
56 |
! ! |
|
57 |
||
58 |
!Depth16Image class methodsFor:'queries'! |
|
59 |
||
4759 | 60 |
defaultPhotometric |
61 |
"return the default photometric pixel interpretation" |
|
62 |
||
63 |
^ #rgb |
|
64 |
||
65 |
"Created: / 27-05-2007 / 14:04:11 / cg" |
|
66 |
! |
|
67 |
||
193 | 68 |
imageDepth |
579 | 69 |
"return the depth of images represented by instances of |
70 |
this class - here we return 16" |
|
71 |
||
193 | 72 |
^ 16 |
579 | 73 |
|
74 |
"Modified: 20.4.1996 / 23:40:01 / cg" |
|
193 | 75 |
! ! |
76 |
||
3263 | 77 |
!Depth16Image methodsFor:'accessing-pixels'! |
281 | 78 |
|
1659
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
79 |
pixelAtX:x y:y |
8324 | 80 |
"retrieve a pixel at x/y; return a pixelValue (0..16rFFFF). |
7520 | 81 |
The interpretation of the returned value depends on the photometric |
82 |
and the colormap. See also Image>>atX:y:) |
|
281 | 83 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
84 |
x = width-1, y=height-1 for lower right pixel" |
|
85 |
||
86 |
|lineIndex "{ Class: SmallInteger }"| |
|
87 |
||
6306 | 88 |
pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y]. |
89 |
||
281 | 90 |
lineIndex := (width * 2 * y) + 1. |
91 |
||
7209
c4cb8c02e820
call the renamed basic methods for short access:
Claus Gittinger <cg@exept.de>
parents:
7190
diff
changeset
|
92 |
^ bytes unsignedInt16At:(lineIndex + (x * 2)) MSB:true. |
1659
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
93 |
|
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
94 |
"Created: 24.4.1997 / 16:06:19 / cg" |
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
95 |
! |
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
96 |
|
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
97 |
pixelAtX:x y:y put:aPixelValue |
8324 | 98 |
"set the pixel at x/y to aPixelValue (0..16rFFFF). |
7520 | 99 |
The interpretation of the pixelValue depends on the photometric |
100 |
and the colormap. (see also: Image>>atX:y:put:) |
|
1659
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
101 |
Pixels start at x=0 , y=0 for upper left pixel, end at |
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
102 |
x = width-1, y=height-1 for lower right pixel" |
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
103 |
|
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
104 |
|lineIndex "{ Class: SmallInteger }"| |
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
105 |
|
8198 | 106 |
bytes isNil ifTrue:[ self createPixelStore ]. |
107 |
||
1659
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
108 |
lineIndex := (width * 2 * y) + 1. |
7209
c4cb8c02e820
call the renamed basic methods for short access:
Claus Gittinger <cg@exept.de>
parents:
7190
diff
changeset
|
109 |
bytes unsignedInt16At:(lineIndex + (x * 2)) put:aPixelValue MSB:true |
1659
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
110 |
|
a38cf5be1aa8
pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents:
813
diff
changeset
|
111 |
"Created: 24.4.1997 / 17:06:21 / cg" |
2180 | 112 |
! |
113 |
||
3872 | 114 |
rowAt:y putAll:pixelArray startingAt:startIndex |
2180 | 115 |
"store a single rows bits from bits in the pixelArray argument; |
8324 | 116 |
The interpretation of the pixel values depends on the photometric. |
3872 | 117 |
Notice: row coordinate starts at 0." |
2180 | 118 |
|
119 |
|dstIdx "{ Class: SmallInteger }" |
|
7190 | 120 |
srcIdx "{ Class: SmallInteger }" |
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
121 |
pixel |
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
122 |
bytes| |
2180 | 123 |
|
3866
c01473a90934
eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents:
3263
diff
changeset
|
124 |
bytes := self bits. |
3872 | 125 |
dstIdx := (width * 2 * y) + 1. |
7190 | 126 |
srcIdx := startIndex. |
2180 | 127 |
1 to:width do:[:col | |
7190 | 128 |
pixel := pixelArray at:srcIdx. |
129 |
"/ msbFirst |
|
8757 | 130 |
"/ bytes unsignedInt16At:dstIdx put:pixel MSB:true. |
7190 | 131 |
bytes at:dstIdx put:((pixel bitShift:-8) bitAnd:16rFF). |
132 |
bytes at:dstIdx+1 put:(pixel bitAnd:16rFF). |
|
133 |
dstIdx := dstIdx + 2. |
|
134 |
srcIdx := srcIdx + 1. |
|
2180 | 135 |
]. |
136 |
||
137 |
"Created: 24.4.1997 / 15:50:27 / cg" |
|
281 | 138 |
! ! |
139 |
||
4759 | 140 |
!Depth16Image methodsFor:'initialization'! |
141 |
||
142 |
initialize |
|
143 |
super initialize. |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
144 |
samplesPerPixel := 3. |
7815 | 145 |
bitsPerSample := #[5 5 5]. |
4759 | 146 |
|
147 |
"Created: / 27-05-2007 / 14:09:46 / cg" |
|
7815 | 148 |
"Modified: / 30-01-2017 / 18:24:16 / stefan" |
4759 | 149 |
! ! |
150 |
||
5128
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
151 |
!Depth16Image methodsFor:'magnification'! |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
152 |
|
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
153 |
magnifyRowFrom:srcBytes offset:srcStart |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
154 |
into:dstBytes offset:dstStart factor:mX |
5128
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
155 |
|
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
156 |
"magnify a single pixel row - can only magnify by integer factors" |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
157 |
|
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
158 |
%{ |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
159 |
unsigned char *srcP, *dstP; |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
160 |
int _mag; |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
161 |
REGISTER int i; |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
162 |
REGISTER unsigned char byte1, byte2; |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
163 |
int _pixels; |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
164 |
OBJ w = __INST(width); |
5128
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
165 |
|
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
166 |
if (__bothSmallInteger(srcStart, dstStart) |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
167 |
&& __bothSmallInteger(w, mX) |
5477
8badcb37a2c0
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5128
diff
changeset
|
168 |
&& __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) { |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
169 |
_mag = __intVal(mX); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
170 |
srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
171 |
dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
172 |
_pixels = __intVal(w); |
5128
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
173 |
|
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
174 |
while (_pixels--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
175 |
byte1 = *srcP; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
176 |
byte2 = *(srcP+1); |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
177 |
srcP += 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
178 |
for (i=_mag; i>0; i--) { |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
179 |
*dstP = byte1; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
180 |
*(dstP+1) = byte2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
181 |
dstP += 2; |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
182 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
183 |
} |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
184 |
RETURN (self); |
5128
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
185 |
} |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
186 |
%}. |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
187 |
super |
6066
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
188 |
magnifyRowFrom:srcBytes offset:srcStart |
62426e8110ae
stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents:
5477
diff
changeset
|
189 |
into:dstBytes offset:dstStart factor:mX |
5128
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
190 |
! ! |
6092105361d1
+magnifyRowFrom:offset:into:offset:factor:
Claus Gittinger <cg@exept.de>
parents:
4759
diff
changeset
|
191 |
|
193 | 192 |
!Depth16Image methodsFor:'queries'! |
193 |
||
194 |
bitsPerPixel |
|
195 |
"return the number of bits per pixel" |
|
196 |
||
197 |
^ 16 |
|
198 |
! |
|
199 |
||
200 |
bitsPerRow |
|
201 |
"return the number of bits in one scanline of the image" |
|
202 |
||
3868 | 203 |
^ width * 16 |
193 | 204 |
! |
205 |
||
206 |
bytesPerRow |
|
207 |
"return the number of bytes in one scanline of the image" |
|
208 |
||
209 |
^ width * 2. |
|
8727 | 210 |
! |
211 |
||
212 |
valueFromRGB:rgb |
|
8757 | 213 |
"given a color as rgb-value, with 8 bits per component and r in high 8 bits, |
8727 | 214 |
return the corresponding pixel value. |
215 |
The red component is in the high 8 bits. |
|
216 |
Non-representable colors return nil." |
|
217 |
||
218 |
|pixel redBits greenBits blueBits r g b a| |
|
219 |
||
220 |
b := rgb bitAnd:16rFF. |
|
221 |
g := (rgb bitShift:-8) bitAnd:16rFF. |
|
222 |
r := (rgb bitShift:-16) bitAnd:16rFF. |
|
223 |
a := 255. |
|
224 |
||
225 |
photometric == #rgb ifTrue:[ |
|
226 |
samplesPerPixel >= 3 ifTrue:[ |
|
227 |
"/ rrrrrrrrggggggggbbbbbbbb -> rrrrrgggggbbbbb |
|
228 |
"/ r,g,b r in hi bits, b in low bits |
|
229 |
redBits := bitsPerSample at:1. |
|
230 |
greenBits := bitsPerSample at:2. |
|
231 |
blueBits := bitsPerSample at:3. |
|
232 |
r := r bitShift:(redBits-8). |
|
233 |
g := g bitShift:(greenBits-8). |
|
234 |
b := b bitShift:(blueBits-8). |
|
235 |
pixel := (((r bitShift:greenBits) + g) bitShift:blueBits) + b. |
|
236 |
^ pixel |
|
237 |
] |
|
238 |
]. |
|
239 |
^ super valueFromRGB:rgb |
|
240 |
||
241 |
"Created: / 12-07-2019 / 14:48:31 / Stefan Reise" |
|
193 | 242 |
! ! |
243 |
||
281 | 244 |
!Depth16Image class methodsFor:'documentation'! |
193 | 245 |
|
281 | 246 |
version |
7190 | 247 |
^ '$Header$' |
5477
8badcb37a2c0
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5128
diff
changeset
|
248 |
! |
8badcb37a2c0
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5128
diff
changeset
|
249 |
|
8badcb37a2c0
__isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents:
5128
diff
changeset
|
250 |
version_CVS |
7190 | 251 |
^ '$Header$' |
193 | 252 |
! ! |
6306 | 253 |