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