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