Depth1Image.st
author Claus Gittinger <cg@exept.de>
Tue, 21 May 2013 22:50:48 +0200
changeset 6066 62426e8110ae
parent 5482 d81219e58155
child 6303 fe26e0d67023
permissions -rw-r--r--
stx macros with 2 underlines
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     1
"
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
     3
	      All Rights Reserved
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     4
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     5
 This software is furnished under a license and may be used
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     6
 only in accordance with the terms of that license and with the
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     8
 be provided or otherwise made available to, or used by, any
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     9
 other person.  No title to or ownership of the software is
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    10
 hereby transferred.
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    11
"
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
    12
"{ Package: 'stx:libview' }"
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
    13
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    14
Image subclass:#Depth1Image
427
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    15
	instanceVariableNames:''
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    16
	classVariableNames:''
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    17
	poolDictionaries:''
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
    18
	category:'Graphics-Images'
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    19
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    20
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    21
!Depth1Image class methodsFor:'documentation'!
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    22
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    23
copyright
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    24
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    25
 COPYRIGHT (c) 1993 by Claus Gittinger
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
    26
	      All Rights Reserved
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    27
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    28
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    29
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    31
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    32
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    33
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    34
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    35
!
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    36
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    37
documentation
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    38
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    39
    this class represents bilevel (1 bit / pixel) images.
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
    40
    It mainly consists of methods which are already implemented in Image,
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
    41
    but reimplemented here for more performance. If you plan to do heavy
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
    42
    image processing on bilevel images, you may want to add more
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
    43
    specialized methods here.
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    44
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    45
    #blackIs0 / #whiteIs0 and #palette formats are supported here.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
    46
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    47
    [author:]
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    48
	Claus Gittinger
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    49
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    50
    [see also:]
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    51
	Depth2Image Depth4Image Depth8Image Depth16Image Depth24Image
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    52
	ImageReader
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    53
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    54
! !
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    55
89
ea2bf46eb669 *** empty log message ***
claus
parents: 82
diff changeset
    56
!Depth1Image class methodsFor:'queries'!
ea2bf46eb669 *** empty log message ***
claus
parents: 82
diff changeset
    57
ea2bf46eb669 *** empty log message ***
claus
parents: 82
diff changeset
    58
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 427
diff changeset
    59
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 427
diff changeset
    60
     this class - here we return 1"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 427
diff changeset
    61
89
ea2bf46eb669 *** empty log message ***
claus
parents: 82
diff changeset
    62
    ^ 1
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 427
diff changeset
    63
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 427
diff changeset
    64
    "Modified: 20.4.1996 / 23:40:06 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 82
diff changeset
    65
! !
ea2bf46eb669 *** empty log message ***
claus
parents: 82
diff changeset
    66
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 3000
diff changeset
    67
!Depth1Image methodsFor:'accessing-pixels'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    68
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
    69
pixelAtX:x y:y
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    70
    "retrieve a pixelValue at x/y; return a number.
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    71
     The interpretation of the returned value depends on the photometric
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    72
     and the colormap. See also Image>>atX:y:)
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    73
     Pixels start at 0@0 for upper left pixel, end at
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    74
     (width-1)@(height-1) for lower right pixel"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    75
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
    76
    |index       "{Class: SmallInteger}"
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    77
     byte        "{Class: SmallInteger}"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    78
     mask        "{Class: SmallInteger}"|
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    79
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    80
%{  /* NOCONTEXT */
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    81
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    82
    OBJ b = __INST(bytes);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    83
    OBJ w = __INST(width);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    84
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
    85
    if (__bothSmallInteger(x, y) && __isSmallInteger(w)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    86
	if (__isByteArrayLike(b)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    87
	    int _w = __intVal(w);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    88
	    int _y = __intVal(y);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    89
	    int _x = __intVal(x);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    90
	    unsigned _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    91
	    int _idx;
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    92
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    93
	    _idx = ((_w + 7) >> 3) * _y + (_x >> 3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    94
	    if ((unsigned)_idx < __byteArraySize(b)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    95
		_byte = __ByteArrayInstPtr(b)->ba_element[_idx];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    96
		RETURN( (_byte & (0x80 >> (_x & 7))) ? __MKSMALLINT(1) : __MKSMALLINT(0) );
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    97
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
    98
	}
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    99
    }
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   100
%}.
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   101
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   102
    "/ the code below is only evaluated if the bytes-collection is
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   103
    "/ not a ByteArray, or the arguments are not integers
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   104
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   105
    index := (self bytesPerRow * y) + 1 + (x // 8).
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   106
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   107
    "left pixel is in high bit"
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   108
    byte := bytes at:index.
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   109
    mask := 1 bitShift:(7 - (x \\ 8)).
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   110
    (byte bitAnd:mask) == 0 ifTrue:[^ 0].
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   111
    ^ 1
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   112
!
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   113
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   114
pixelAtX:x y:y put:aPixelValue
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   115
    "set a pixels value at x/y to aPixelValue.
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   116
     Pixels start at x=0 , y=0 for upper left pixel, end at
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   117
     x = width-1, y=height-1 for lower right pixel"
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   118
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   119
    |index       "{Class: SmallInteger}"
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   120
     byte        "{Class: SmallInteger}"
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   121
     mask        "{Class: SmallInteger}"|
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   122
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   123
%{  /* NOCONTEXT */
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   124
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   125
    OBJ b = __INST(bytes);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   126
    OBJ w = __INST(width);
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   127
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   128
    if (__isByteArray(b) && __bothSmallInteger(x, y) && __isSmallInteger(w) ) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   129
	int _w = __intVal(w);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   130
	int _y = __intVal(y);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   131
	int _x = __intVal(x);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   132
	int _idx;
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   133
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   134
	_idx = ((_w + 7) >> 3) * _y + (_x >> 3);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   135
	if ((unsigned)_idx < __byteArraySize(b)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   136
	    if (aPixelValue == __MKSMALLINT(0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   137
		__ByteArrayInstPtr(b)->ba_element[_idx] &= ~(0x80 >> (_x & 7));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   138
	    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   139
		__ByteArrayInstPtr(b)->ba_element[_idx] |= (0x80 >> (_x & 7));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   140
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   141
	    RETURN( self );
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   142
	}
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   143
    }
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   144
%}.
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   145
    "fall back code for nonByteArray or nonInteger arguments"
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   146
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   147
    index := (self bytesPerRow * y) + 1 + (x // 8).
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   148
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   149
    "left pixel is in high bit"
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   150
    byte := bytes at:index.
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   151
    mask := #(16r80 16r40 16r20 16r10 16r08 16r04 16r02 16r01) at:((x \\ 8) + 1).
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   152
    aPixelValue == 0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   153
	byte := byte bitAnd:(mask bitInvert)
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   154
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   155
	byte := byte bitOr:mask
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   156
    ].
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   157
    bytes at:index put:byte
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   158
! !
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   159
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   160
!Depth1Image methodsFor:'converting'!
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   161
853
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   162
asFormOn:aDevice
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   163
    "convert a monochrome image to a device form"
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   164
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   165
    ^ self anyImageAsFormOn:aDevice
853
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   166
!
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   167
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   168
greyImageAsFormOn:aDevice
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   169
    "convert a greyscale image to a device form"
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   170
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   171
    ^ self anyImageAsFormOn:aDevice
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   172
!
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   173
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   174
greyImageAsMonoFormOn:aDevice
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   175
    "convert to a monochrome form - thats easy"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   176
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   177
    ^ self anyImageAsFormOn:aDevice
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   178
!
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   179
427
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
   180
paletteImageAsMonoFormOn:aDevice
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   181
    "convert a palette image to a b&w monochrome device form"
427
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
   182
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   183
    |f c0 c1|
427
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
   184
4773
65c6b8654054 Use Form class>>#width:height:fromArray:onDevice: instead of obsolete
Stefan Vogel <sv@exept.de>
parents: 4767
diff changeset
   185
    f := Form width:width height:height fromArray:self bits onDevice:aDevice.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   186
    c0 := self colorFromValue:0.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   187
    c1 := self colorFromValue:1.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   188
    c0 brightness > 0.5 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   189
	c0 := Color white
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   190
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   191
	c0 := Color black.
427
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
   192
    ].
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   193
    c1 brightness > 0.5 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   194
	c1 := Color white
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   195
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   196
	c1 := Color black.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   197
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   198
    f colorMap:(Array with:c0 with:c1).
427
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
   199
    ^ f
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
   200
1655
eec658000092 pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1635
diff changeset
   201
    "Modified: 24.4.1997 / 17:51:54 / cg"
427
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
   202
!
746424fba14f added palette-to-form conversion
Claus Gittinger <cg@exept.de>
parents: 337
diff changeset
   203
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   204
paletteImageAsTrueColorFormOn:aDevice
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   205
    "since all devices must support monochrome images, and
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   206
     a 2-entry colormap is implemented by ST/X's drawForm methods,
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   207
     we can do this on all color devices as a palette image."
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   208
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   209
    ^ self anyImageAsFormOn:aDevice
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   210
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   211
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   212
     |i|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   213
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   214
     i := Depth1Image
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   215
		width:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   216
		height:4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   217
		fromArray:#[ 2r00000000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   218
			     2r11110000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   219
			     2r01010000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   220
			     2r10100000 ].
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   221
     i photometric:#rgb.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   222
     i samplesPerPixel:3.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   223
     i bitsPerSample:#(1 0 0).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   224
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   225
     i := i magnifiedBy:30.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   226
     i inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   227
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   228
853
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   229
    "Modified: 14.6.1996 / 15:21:37 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   230
! !
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   231
89
ea2bf46eb669 *** empty log message ***
claus
parents: 82
diff changeset
   232
!Depth1Image methodsFor:'enumerating'!
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   233
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   234
colorsAtY:y from:xLow to:xHigh do:aBlock
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   235
    "perform aBlock for each pixel from x1 to x2 in row y.
304f026e10cd Initial revision
claus
parents:
diff changeset
   236
     The block is passed the color at each pixel.
304f026e10cd Initial revision
claus
parents:
diff changeset
   237
     This method allows slighly faster processing of an
304f026e10cd Initial revision
claus
parents:
diff changeset
   238
     image than using atX:y:, since some processing can be
304f026e10cd Initial revision
claus
parents:
diff changeset
   239
     avoided when going from pixel to pixel. However, for
304f026e10cd Initial revision
claus
parents:
diff changeset
   240
     real image processing, specialized methods should be written."
304f026e10cd Initial revision
claus
parents:
diff changeset
   241
304f026e10cd Initial revision
claus
parents:
diff changeset
   242
    |srcIndex "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   243
     byte     "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   244
     mask     "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   245
     x1       "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   246
     x2       "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   247
     color0 color1
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   248
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   249
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   250
    bytes := self bits.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   251
304f026e10cd Initial revision
claus
parents:
diff changeset
   252
    x1 := xLow.
304f026e10cd Initial revision
claus
parents:
diff changeset
   253
    x2 := xHigh.
304f026e10cd Initial revision
claus
parents:
diff changeset
   254
    srcIndex := (self bytesPerRow * y) + 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
   255
304f026e10cd Initial revision
claus
parents:
diff changeset
   256
    "left pixel is in high bit"
304f026e10cd Initial revision
claus
parents:
diff changeset
   257
2226
ceaba9778107 care for short colormap in #colorsAt...do:
tz
parents: 2211
diff changeset
   258
    color0 := self colorFromValue:0.
ceaba9778107 care for short colormap in #colorsAt...do:
tz
parents: 2211
diff changeset
   259
    color1 := self colorFromValue:1.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   260
304f026e10cd Initial revision
claus
parents:
diff changeset
   261
    srcIndex := srcIndex + (x1 // 8).
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   262
    mask := #[2r10000000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   263
	      2r01000000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   264
	      2r00100000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   265
	      2r00010000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   266
	      2r00001000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   267
	      2r00000100
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   268
	      2r00000010
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   269
	      2r00000001] at:((x1 \\ 8) + 1).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   270
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   271
    byte := bytes at:srcIndex.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   272
    x1 to:x2 do:[:x |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   273
	(byte bitAnd:mask) == 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   274
	    aBlock value:x value:color0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   275
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   276
	    aBlock value:x value:color1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   277
	].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   278
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   279
	mask := mask bitShift:-1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   280
	mask == 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   281
	    mask := 2r10000000.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   282
	    srcIndex := srcIndex + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   283
	    x < x2 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   284
		byte := bytes at:srcIndex.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   285
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   286
	]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   287
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   288
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   289
    "Created: 7.6.1996 / 19:12:26 / cg"
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 806
diff changeset
   290
    "Modified: 10.6.1996 / 10:33:06 / cg"
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   291
!
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   292
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   293
valuesAtY:y from:xLow to:xHigh do:aBlock
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   294
    "perform aBlock for each pixelValue from x1 to x2 in row y.
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   295
     The block is passed the color at each pixel.
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   296
     This method allows slighly faster processing of an
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   297
     image than using atX:y:, since some processing can be
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   298
     avoided when going from pixel to pixel. However, for
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   299
     real image processing, specialized methods should be written."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   300
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   301
    |srcIndex "{ Class: SmallInteger }"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   302
     byte     "{ Class: SmallInteger }"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   303
     mask     "{ Class: SmallInteger }"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   304
     x1       "{ Class: SmallInteger }"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   305
     x2       "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   306
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   307
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   308
    bytes := self bits.
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   309
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   310
    "this method needs more tuning, if used heavily
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   311
     (fetch 8 bits at once, unroll the loop over these 8 pixels)"
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   312
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   313
    x1 := xLow.
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   314
    x2 := xHigh.
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   315
    srcIndex := (self bytesPerRow * y) + 1.
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   316
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   317
    "left pixel is in high bit"
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   318
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   319
    srcIndex := srcIndex + (x1 // 8).
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   320
    mask := #[2r10000000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   321
	      2r01000000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   322
	      2r00100000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   323
	      2r00010000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   324
	      2r00001000
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   325
	      2r00000100
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   326
	      2r00000010
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   327
	      2r00000001] at:((x1 \\ 8) + 1).
193
Claus Gittinger <cg@exept.de>
parents: 118
diff changeset
   328
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   329
    byte := bytes at:srcIndex.
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   330
    x1 to:x2 do:[:x |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   331
	(byte bitAnd:mask) == 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   332
	    aBlock value:x value:0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   333
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   334
	    aBlock value:x value:1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   335
	].
193
Claus Gittinger <cg@exept.de>
parents: 118
diff changeset
   336
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   337
	mask := mask bitShift:-1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   338
	mask == 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   339
	    mask := 2r10000000.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   340
	    srcIndex := srcIndex + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   341
	    x < x2 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   342
		byte := bytes at:srcIndex.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   343
	    ]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   344
	]
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   345
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   346
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 611
diff changeset
   347
    "Created: 7.6.1996 / 19:09:38 / cg"
806
8d8a58e12c08 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 805
diff changeset
   348
    "Modified: 8.6.1996 / 13:36:37 / cg"
82
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   349
! !
98a70bce6d51 *** empty log message ***
claus
parents: 81
diff changeset
   350
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   351
!Depth1Image methodsFor:'magnification'!
304f026e10cd Initial revision
claus
parents:
diff changeset
   352
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   353
hardMagnifiedBy:scalePoint
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   354
    "return a new image magnified by scalePoint, aPoint.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   355
     This is the general magnification method, handling non-integral values.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   356
     It is slower than the integral magnification method."
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   357
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   358
    |mX
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   359
     mY
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   360
     newWidth  "{ Class: SmallInteger }"
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   361
     newHeight "{ Class: SmallInteger }"
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   362
     newImage newBits bitsPerPixel newBytesPerRow
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   363
     newMask
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   364
     bytes|
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   365
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   366
    bytes := self bits.
2988
e90b0ada0843 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
   367
    bytes isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   368
	self error:'cannot magnify image without bits'.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   369
	^ self
2988
e90b0ada0843 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
   370
    ].
e90b0ada0843 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2269
diff changeset
   371
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   372
    mX := scalePoint x.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   373
    mY := scalePoint y.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   374
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   375
    newWidth := (width * mX) truncated.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   376
    newHeight := (height * mY) truncated.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   377
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   378
    bitsPerPixel := self depth.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   379
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   380
    newBits := ByteArray new:(newBytesPerRow * newHeight).
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   381
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   382
    mask notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   383
	newMask := (mask magnifiedBy:scalePoint)
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   384
    ].
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   385
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   386
    newImage := self species new.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   387
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   388
    newImage
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   389
	width:newWidth
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   390
	height:newHeight
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   391
	photometric:photometric
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   392
	samplesPerPixel:samplesPerPixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   393
	bitsPerSample:bitsPerSample
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   394
	colorMap:colorMap copy
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   395
	bits:newBits
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   396
	mask:newMask.
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   397
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   398
    "walk over destination image fetching pixels from source image"
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   399
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   400
    mX := mX asFloat.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   401
    mY := mY asFloat.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   402
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   403
%{
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   404
{
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   405
    OBJ b1 = bytes;
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   406
    int _w1 = __intVal(__INST(width));
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   407
    int _y1, _y2;
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   408
    OBJ b2 = newBits;
2044
9ea84b4ba249 more single-underline macros
Claus Gittinger <cg@exept.de>
parents: 2042
diff changeset
   409
    int _w2 = __intVal(newWidth);
9ea84b4ba249 more single-underline macros
Claus Gittinger <cg@exept.de>
parents: 2042
diff changeset
   410
    int _h2 = __intVal(newHeight);
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   411
    int _x2, _x1;
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   412
    int _idx2;
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   413
    unsigned _byte;
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   414
    double _mY = __floatVal(mY);
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   415
    double _mX = __floatVal(mX);
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   416
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   417
    for (_y2 = 0; _y2 < _h2; _y2++) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   418
	_y1 = (int)( (double)_y2 / _mY);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   419
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   420
	for (_x2 = 0; _x2 < _w2; _x2++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   421
	    _x1 = (int)( (double)_x2 / _mX);
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   422
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   423
	    _byte = __ByteArrayInstPtr(b1)->ba_element[(_w1 + 7) / 8 * _y1 + (_x1 / 8)];
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   424
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   425
	    if ((_byte & (0x80 >> (_x1 % 8)))) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   426
		_idx2 = (_w2 + 7) / 8 * _y2 + (_x2 / 8);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   427
		__ByteArrayInstPtr(b2)->ba_element[_idx2] |= (0x80 >> (_x2 % 8));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   428
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   429
	}
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   430
    }
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   431
}
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   432
%}.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   433
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   434
"/    w := newWidth - 1.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   435
"/    h := newHeight - 1.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   436
"/
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   437
"/    0 to:h do:[:row |
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   438
"/        dstRow := row.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   439
"/        srcRow := (row // mY).
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   440
"/        0 to:w do:[:col |
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   441
"/
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   442
"/            dstCol := col.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   443
"/            srcCol := col // mX.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   444
"/            value := self valueAtX:(col // mX) y:srcRow.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   445
"/            newImage atX:col y:row putValue:value.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   446
"/        ]
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   447
"/    ].
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   448
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   449
    ^ newImage
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   450
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   451
    "((Image fromFile:'bitmaps/claus.gif') magnifiedBy:0.5@0.5)"
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   452
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   453
    "Created: 18.6.1996 / 16:04:26 / cg"
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   454
!
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 862
diff changeset
   455
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   456
magnifyRowFrom:srcBytes offset:srcStart
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   457
	  into:dstBytes offset:dstStart factor:mX
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   458
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   459
    "magnify a single pixel row - can only magnify by integer factors.
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   460
     This method has been specially tuned for magnification by 2 and 4."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   461
304f026e10cd Initial revision
claus
parents:
diff changeset
   462
%{
304f026e10cd Initial revision
claus
parents:
diff changeset
   463
    unsigned char *srcP, *dstP;
304f026e10cd Initial revision
claus
parents:
diff changeset
   464
    int _mag;
304f026e10cd Initial revision
claus
parents:
diff changeset
   465
    REGISTER int i;
304f026e10cd Initial revision
claus
parents:
diff changeset
   466
    REGISTER unsigned char _byte;
304f026e10cd Initial revision
claus
parents:
diff changeset
   467
    int _pixels, bpr;
304f026e10cd Initial revision
claus
parents:
diff changeset
   468
    REGISTER int outcnt, bits, bit, mask, incnt;
304f026e10cd Initial revision
claus
parents:
diff changeset
   469
    int shift;
304f026e10cd Initial revision
claus
parents:
diff changeset
   470
    unsigned char byte1, byte2, byte3, byte4;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   471
    OBJ w = __INST(width);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   472
304f026e10cd Initial revision
claus
parents:
diff changeset
   473
    /* helper for monochrome magnification by 2 */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   474
    static unsigned char mag1[16] = {0x00, 0x03, 0x0c, 0x0f, 0x30, 0x33, 0x3c, 0x3f,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   475
				     0xc0, 0xc3, 0xcc, 0xcf, 0xf0, 0xf3, 0xfc, 0xff};
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   476
97
dd6116883ac0 *** empty log message ***
claus
parents: 89
diff changeset
   477
    if (__bothSmallInteger(srcStart, dstStart)
dd6116883ac0 *** empty log message ***
claus
parents: 89
diff changeset
   478
     && __bothSmallInteger(w, mX)
5482
d81219e58155 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 4773
diff changeset
   479
     && __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   480
	_mag = __intVal(mX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   481
	srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   482
	dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   483
	_pixels = __intVal(w);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   484
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   485
	switch (_mag) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   486
	    case 1:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   487
		break;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   488
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   489
	    case 2:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   490
		/* tuned for this common case */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   491
		while (_pixels > 4) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   492
		    _byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   493
		    *dstP++ = mag1[ _byte >> 4 ];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   494
		    *dstP++ = mag1[ _byte & 0x0F ];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   495
		    _pixels -= 8;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   496
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   497
		while (_pixels > 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   498
		    _byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   499
		    *dstP++ = mag1[ _byte >> 4 ];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   500
		    _pixels -= 8;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   501
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   502
		break;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   503
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   504
	    case 4:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   505
		/* tuned for this common case */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   506
		while (_pixels > 6) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   507
		    _byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   508
		    byte1 = mag1[_byte >> 4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   509
		    byte2 = mag1[byte1 & 0xF];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   510
		    byte1 = mag1[byte1 >> 4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   511
		    byte3 = mag1[ _byte & 0x0F ];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   512
		    byte4 = mag1[byte3 & 0xF];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   513
		    byte3 = mag1[byte3 >> 4];
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3599
diff changeset
   514
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   515
		    *dstP++ = byte1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   516
		    *dstP++ = byte2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   517
		    *dstP++ = byte3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   518
		    *dstP++ = byte4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   519
		    _pixels -= 8;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   520
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   521
		while (_pixels > 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   522
		    _byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   523
		    byte1 = mag1[_byte >> 4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   524
		    byte2 = mag1[byte1 & 0xF];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   525
		    byte1 = mag1[byte1 >> 4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   526
		    byte3 = mag1[_byte & 0x0F ];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   527
		    byte4 = mag1[byte3 & 0xF];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   528
		    byte3 = mag1[byte3 >> 4];
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   529
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   530
		    *dstP++ = byte1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   531
		    if (_pixels > 2) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   532
			*dstP++ = byte2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   533
			if (_pixels > 4) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   534
			    *dstP++ = byte3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   535
			    if (_pixels > 6) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   536
				*dstP++ = byte4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   537
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   538
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   539
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   540
		    _pixels -= 8;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   541
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   542
		break;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   543
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   544
	    default:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   545
		bits = 0, incnt = 0, outcnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   546
		mask = 0x80;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   547
		_byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   548
		while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   549
		    if (_byte & mask)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   550
			bit = 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   551
		    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   552
			bit = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   553
		    incnt++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   554
		    if (incnt == 8) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   555
			incnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   556
			mask = 0x80;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   557
			_byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   558
		    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   559
			mask >>= 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   560
		    }
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   561
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   562
		    for (i=_mag; i>0; i--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   563
			bits = (bits << 1) | bit;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   564
			outcnt++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   565
			if (outcnt == 8) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   566
			    *dstP++ = bits;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   567
			    bits = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   568
			    outcnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   569
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   570
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   571
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   572
		if (outcnt) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   573
		    *dstP = bits << (8-outcnt);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   574
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   575
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   576
	}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   577
	RETURN (self);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   578
    }
81
4ba554473294 *** empty log message ***
claus
parents: 54
diff changeset
   579
%}.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   580
    super
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   581
	magnifyRowFrom:srcBytes offset:srcStart
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   582
	into:dstBytes offset:dstStart factor:mX
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   583
! !
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   584
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   585
!Depth1Image methodsFor:'private'!
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   586
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   587
anyImageAsFormOn:aDevice
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   588
    "convert a monochrome image to a device form"
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   589
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   590
    |f color0 color1|
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   591
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   592
    ((aDevice == device) and:[deviceForm notNil]) ifTrue:[^ deviceForm].
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   593
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   594
    color0 := (self colorFromValue:0) exactOn:aDevice.
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   595
    color1 := (self colorFromValue:1) exactOn:aDevice.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   596
    (color0 notNil and:[(color0 isOnDevice:aDevice)
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   597
     and:[color1 notNil and:[color1 isOnDevice:aDevice]]]) ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   598
	"could not allocate colors, do it the hard way ..."
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   599
	^ self paletteImageAsFormOn:aDevice.
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   600
    ].
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   601
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   602
    "all colors are available, this is easy now"
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   603
4767
61d7b2ee4939 ...:on: -> ...:onDevice:
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
   604
    f := Form width:width height:height fromArray:self bits onDevice:aDevice.
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   605
    f notNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   606
	f colorMap:(Array with:color0 with:color1).
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   607
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   608
	"/ remember deviceForm
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   609
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   610
	(device isNil or:[deviceForm isNil]) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   611
	    device := aDevice.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   612
	    deviceForm := f.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   613
	    maskedPixelsAre0 := nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   614
	]
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   615
    ].
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   616
    ^ f
4767
61d7b2ee4939 ...:on: -> ...:onDevice:
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
   617
61d7b2ee4939 ...:on: -> ...:onDevice:
Claus Gittinger <cg@exept.de>
parents: 4419
diff changeset
   618
    "Modified: / 29-05-2007 / 19:32:09 / cg"
3599
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   619
! !
bb5474dfa1c8 Depth1Image didn't work with unavailable colors.
Stefan Vogel <sv@exept.de>
parents: 3569
diff changeset
   620
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   621
!Depth1Image methodsFor:'queries'!
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   622
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   623
bitsPerPixel
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   624
    "return the number of bits per pixel"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   625
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   626
    ^ 1
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   627
!
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   628
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   629
bitsPerRow
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   630
    "return the number of bits in one scanline of the image"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   631
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3867
diff changeset
   632
    ^ width
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   633
!
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   634
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   635
bytesPerRow
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   636
    "return the number of bytes in one scanline of the image"
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   637
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   638
    |nbytes|
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   639
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   640
    nbytes := width // 8.
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   641
    ((width \\ 8) ~~ 0) ifTrue:[
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   642
	^ nbytes + 1
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   643
    ].
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   644
    ^ nbytes
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   645
!
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   646
3869
cd40d1912c03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
   647
colorFromValue:pixelValue
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   648
    "given a pixel value, return the corresponding color.
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   649
     Pixel values start with 0."
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   650
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   651
    photometric == #blackIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   652
	(pixelValue == 0) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   653
	    ^ Color black
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   654
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   655
	^ Color white
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   656
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   657
    photometric == #whiteIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   658
	(pixelValue == 0) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   659
	    ^ Color white
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   660
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   661
	^ Color black
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   662
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   663
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   664
	pixelValue < colorMap size ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   665
	    ^ colorMap at:(pixelValue+1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   666
	]
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   667
    ].
3869
cd40d1912c03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
   668
    ^ super colorFromValue:pixelValue.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   669
!
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   670
4117
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   671
rgbFromValue:pixelValue
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   672
    "given a pixel value, return the corresponding 24bit rgbValue (rrggbb, red is MSB).
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   673
     Pixel values start with 0."
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   674
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   675
    photometric == #blackIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   676
	(pixelValue == 0) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   677
	    ^ 0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   678
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   679
	^ 16rFFFFFF
4117
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   680
    ].
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   681
    photometric == #whiteIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   682
	(pixelValue == 0) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   683
	    ^ 16rFFFFFF
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   684
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   685
	^ 0
4117
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   686
    ].
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   687
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   688
	pixelValue < colorMap size ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   689
	    ^ (colorMap at:(pixelValue+1)) rgbValue
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   690
	]
4117
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   691
    ].
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   692
    ^ super rgbFromValue:pixelValue.
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   693
!
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   694
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   695
usedColors
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   696
    "return a collection of colors used in the receiver.
2201
7272763312a0 comments
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   697
     For depth1 images, we return the colorMap here, assuming all
7272763312a0 comments
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   698
     pixels are used ...
7272763312a0 comments
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   699
     ... which is not really true - it could be all-white or all-black"
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   700
3867
2a620c958987 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   701
    (photometric == #whiteIs0 or:[photometric == #blackIs0]) ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   702
	^ Array
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   703
	    with:(Color black)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   704
	    with:(Color white).
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   705
    ].
3867
2a620c958987 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   706
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   707
	^ colorMap
3867
2a620c958987 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   708
    ].
2a620c958987 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
   709
    ^ super usedColors
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   710
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   711
    "
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   712
     (Image fromFile:'bitmaps/garfield.gif') usedColors
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   713
     (Image fromFile:'bitmaps/SBrowser.xbm') usedColors
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   714
    "
2201
7272763312a0 comments
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   715
7272763312a0 comments
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   716
    "Modified: / 28.7.1998 / 22:21:29 / cg"
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   717
!
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   718
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   719
usedValues
4419
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   720
    "return a collection of color values used in the receiver."
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   721
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   722
    |bits first|
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   723
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   724
    bits := self bits.
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   725
    bits isEmptyOrNil ifTrue:[^ #() ].
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   726
4419
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   727
    first := bits at:1.
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   728
    ((first == 0) or:[(first == 2r11111111)]) ifFalse:[ ^ #(0 1) ].
2201
7272763312a0 comments
Claus Gittinger <cg@exept.de>
parents: 2179
diff changeset
   729
4419
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   730
    bits do:[:eachByte |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   731
	(first bitXor:eachByte) ~~ 0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   732
	    ^ #(0 1)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   733
	].
4419
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   734
    ].
a7b3e60e4f0a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4117
diff changeset
   735
    ^ first == 0 ifTrue:[ #(0) ] ifFalse:[ #(1) ].
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   736
!
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   737
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   738
valueFromColor:aColor
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   739
    "given a color, return the corresponding pixel value.
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   740
     Non-representable colors return nil."
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   741
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   742
    |clr0 clr1|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   743
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   744
    photometric == #whiteIs0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   745
	clr0 := Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   746
	clr1 := Color black.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   747
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   748
	photometric == #blackIs0 ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   749
	    clr0 := Color black.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   750
	    clr1 := Color white.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   751
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   752
	    photometric ~~ #palette ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   753
		^ super valueFromColor:aColor
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   754
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   755
	    clr0 := colorMap at:1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   756
	    clr1 := colorMap at:2 ifAbsent:nil.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   757
	]
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   758
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   759
    aColor = clr0 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   760
	^ 0.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   761
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   762
    aColor = clr1 ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   763
	^ 1
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   764
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   765
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   766
    "
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   767
     the color is not in the images colormap
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   768
    "
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   769
    ^ nil
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   770
! !
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   771
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   772
!Depth1Image class methodsFor:'documentation'!
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   773
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   774
version
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   775
    ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.58 2013-05-21 20:50:48 cg Exp $'
5482
d81219e58155 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 4773
diff changeset
   776
!
d81219e58155 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 4773
diff changeset
   777
d81219e58155 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 4773
diff changeset
   778
version_CVS
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 5482
diff changeset
   779
    ^ '$Header: /cvs/stx/stx/libview/Depth1Image.st,v 1.58 2013-05-21 20:50:48 cg Exp $'
279
2751e757e228 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   780
! !