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