Depth8Image.st
author Claus Gittinger <cg@exept.de>
Wed, 15 Oct 1997 13:23:11 +0200
changeset 1922 73114e8c9518
parent 1846 6080866bf196
child 1932 6afe07d9c88c
permissions -rw-r--r--
if display is running out of allocatable colors, use devices actual colors for dithering.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
claus
parents: 1
diff changeset
     1
"
claus
parents: 1
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
71
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
     3
	      All Rights Reserved
5
claus
parents: 1
diff changeset
     4
claus
parents: 1
diff changeset
     5
 This software is furnished under a license and may be used
claus
parents: 1
diff changeset
     6
 only in accordance with the terms of that license and with the
claus
parents: 1
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
claus
parents: 1
diff changeset
     8
 be provided or otherwise made available to, or used by, any
claus
parents: 1
diff changeset
     9
 other person.  No title to or ownership of the software is
claus
parents: 1
diff changeset
    10
 hereby transferred.
claus
parents: 1
diff changeset
    11
"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    12
1922
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
    13
'From Smalltalk/X, Version:3.2.1 on 15-oct-1997 at 2:31:42 pm'                  !
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
    14
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    15
Image subclass:#Depth8Image
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    16
	instanceVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    17
	classVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    18
	poolDictionaries:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    19
	category:'Graphics-Images'
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    20
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    21
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    22
!Depth8Image class methodsFor:'documentation'!
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    23
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    24
copyright
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    25
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    26
 COPYRIGHT (c) 1993 by Claus Gittinger
71
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
    27
	      All Rights Reserved
5
claus
parents: 1
diff changeset
    28
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    29
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    30
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    31
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    32
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    33
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    34
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    35
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    36
!
5
claus
parents: 1
diff changeset
    37
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    38
documentation
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    39
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    40
    this class represents 256-color (8 bit / pixel) images (palette, greyscale ...).
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    41
    It mainly consists of methods already implemented in Image,
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    42
    reimplemented here for more performance.
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    43
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    44
    [author:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    45
        Claus Gittinger
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    46
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    47
    [see also:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    48
        Depth1Image Depth2Image Depth4Image Depth16Image Depth24Image
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    49
        ImageReader
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    50
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    51
! !
5
claus
parents: 1
diff changeset
    52
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    53
!Depth8Image class methodsFor:'queries'!
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    54
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    55
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    56
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    57
     this class - here we return 8"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    58
304f026e10cd Initial revision
claus
parents:
diff changeset
    59
    ^ 8
304f026e10cd Initial revision
claus
parents:
diff changeset
    60
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    61
    "Modified: 20.4.1996 / 23:40:22 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 75
diff changeset
    62
! !
4ba554473294 *** empty log message ***
claus
parents: 75
diff changeset
    63
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    64
!Depth8Image methodsFor:'accessing - pixels'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    65
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    66
colorAtX:x y:y
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    67
    "retrieve a pixel at x/y; return a color.
304f026e10cd Initial revision
claus
parents:
diff changeset
    68
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
    69
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
    70
38
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
    71
    |value "{ Class: SmallInteger }"
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
    72
     index "{ Class: SmallInteger }"|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    73
304f026e10cd Initial revision
claus
parents:
diff changeset
    74
    index := (width * y) + 1 + x.
304f026e10cd Initial revision
claus
parents:
diff changeset
    75
    value := bytes at:index.
304f026e10cd Initial revision
claus
parents:
diff changeset
    76
304f026e10cd Initial revision
claus
parents:
diff changeset
    77
    photometric == #whiteIs0 ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    78
        ^ Color gray:100 - (100 / 255 * value)
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    79
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    80
    photometric == #blackIs0 ifTrue:[
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    81
        ^ Color gray:(100 / 255 * value)
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    82
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    83
    photometric ~~ #palette ifTrue:[
802
828038ff0e83 better multiplane dither
Claus Gittinger <cg@exept.de>
parents: 801
diff changeset
    84
        ^ self colorFromValue:value
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    85
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
    86
    index := value + 1.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    87
    ^ colorMap at:index
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
    88
802
828038ff0e83 better multiplane dither
Claus Gittinger <cg@exept.de>
parents: 801
diff changeset
    89
    "Modified: 8.6.1996 / 10:52:48 / cg"
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    90
    "Created: 24.4.1997 / 17:33:58 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    91
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    92
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    93
pixelAtX:x y:y
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    94
    "retrieve a pixel at x/y; return a pixelValue.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    95
     Pixels start at x=0 , y=0 for upper left pixel, end at
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    96
     x = width-1, y=height-1 for lower right pixel"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    97
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    98
    |index "{ Class: SmallInteger }"|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    99
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   100
%{  /* NOCONTEXT */
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   101
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   102
    OBJ b = _INST(bytes);
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   103
    OBJ w = _INST(width);
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   104
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   105
    if (__isByteArray(b) 
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   106
     && __bothSmallInteger(x, y) 
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   107
     && __isSmallInteger(w) ) {
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   108
        int _idx, _pix;
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   109
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   110
        _idx = (__intVal(w) * __intVal(y)) + __intVal(x);
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   111
        if ((unsigned)_idx < __byteArraySize(b)) {
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   112
            _pix = _ByteArrayInstPtr(b)->ba_element[_idx];
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   113
            RETURN( __MKSMALLINT(_pix) );
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   114
        }
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   115
    }
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   116
%}.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   117
    "/ should not be reached ...
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   118
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   119
    index := (width * y) + 1 + x.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   120
    ^ bytes at:index.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   121
!
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   122
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   123
pixelAtX:x y:y put:aPixelValue
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   124
    "set the pixel at x/y to aPixelValue.
304f026e10cd Initial revision
claus
parents:
diff changeset
   125
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
   126
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
   127
304f026e10cd Initial revision
claus
parents:
diff changeset
   128
    |index "{ Class: SmallInteger }"|
304f026e10cd Initial revision
claus
parents:
diff changeset
   129
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   130
%{  /* NOCONTEXT */
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   131
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   132
    OBJ b = _INST(bytes);
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   133
    OBJ w = _INST(width);
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   134
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   135
    if (__isByteArray(b) 
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   136
     && __bothSmallInteger(x, y) 
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   137
     && __bothSmallInteger(w, aPixelValue) ) {
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   138
        int _idx;
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   139
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   140
        _idx = (__intVal(w) * __intVal(y)) + __intVal(x);
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   141
        if ((unsigned)_idx < __byteArraySize(b)) {
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   142
            _ByteArrayInstPtr(b)->ba_element[_idx] = __intVal(aPixelValue);
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   143
            RETURN( self );
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   144
        }
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   145
    }
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   146
%}.
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   147
    "/ should not be reached ...
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   148
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   149
    index := (width * y) + 1 + x.
304f026e10cd Initial revision
claus
parents:
diff changeset
   150
    bytes at:index put:aPixelValue.
304f026e10cd Initial revision
claus
parents:
diff changeset
   151
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   152
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   153
rowAt:rowIndex into:aPixelBuffer startingAt:startIndex
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   154
    "fill aPixelBuffer with pixel values from a single row.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   155
     Notice: row indexing starts at 0."
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   156
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   157
    |srcIdx|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   158
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   159
    srcIdx := (rowIndex * width) + 1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   160
    aPixelBuffer replaceFrom:startIndex to:startIndex+width-1 with:bytes startingAt:srcIdx
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   161
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   162
    "Modified: 24.4.1997 / 15:47:22 / cg"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   163
!
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   164
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   165
rowAt:rowIndex putAll:pixelArray
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   166
    "replace a single rows bits from bits in the argument;
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   167
     Notice: row indexing starts at 0."
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   168
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   169
    |dstIdx|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   170
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   171
    dstIdx := (rowIndex*width) + 1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   172
    bytes replaceFrom:dstIdx to:dstIdx+width-1 with:pixelArray startingAt:1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   173
    ^ pixelArray
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   174
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   175
    "Modified: 24.4.1997 / 14:34:23 / cg"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   176
!
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   177
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   178
rowAt:rowIndex putAll:pixelArray startingAt:startIndex
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   179
    "store a single rows bits from bits in the pixelArray argument;
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   180
     Return the pixelArray.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   181
     Notice: row indexing starts at 0."
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   182
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   183
    |dstIdx|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   184
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   185
    dstIdx := (rowIndex * width) + 1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   186
    bytes replaceFrom:dstIdx to:dstIdx+width-1 with:pixelArray startingAt:startIndex.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   187
    ^ pixelArray
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   188
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   189
    "Created: 24.4.1997 / 15:49:42 / cg"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   190
! !
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   191
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   192
!Depth8Image methodsFor:'converting'!
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   193
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   194
fromImage:anImage
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   195
    "setup the receiver from another image.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   196
     The code here is tuned for depth 1, 2 and 4 source images;
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   197
     other conversions are done in the superclasses fallBack method."
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   198
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   199
    |srcBytesPerRow srcBuffer dstBuffer srcBytes srcIdx dstIdx 
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   200
     srcDepth map|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   201
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   202
    srcDepth := anImage depth.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   203
    (#(1 2 4) includes:srcDepth) ifFalse:[
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   204
        ^ super fromImage:anImage
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   205
    ].
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   206
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   207
    width := anImage width.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   208
    height := anImage height.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   209
    bytes := ByteArray uninitializedNew:(width * height).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   210
    bitsPerSample := self bitsPerSample.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   211
    samplesPerPixel := self samplesPerPixel.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   212
    self colormapFromImage:anImage.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   213
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   214
    colorMap isNil ifTrue:[
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   215
        "/ if source has no colorMap, more work is needed ...
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   216
        map := #(
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   217
                #[0 16rFF]
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   218
                #[0 16r55 16rAA 16rFF]
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   219
                nil
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   220
                #[16r00 16r11 16r22 16r33 16r44 16r55 16r66 16r77
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   221
                  16r88 16r99 16rAA 16rBB 16rCC 16rDD 16rEE 16rFF]
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   222
               ) at:srcDepth.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   223
    ].
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   224
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   225
    self mask:anImage mask.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   226
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   227
    "/ only expand & translate pixels
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   228
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   229
    srcBytes := anImage bits.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   230
    srcBytesPerRow := anImage bytesPerRow.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   231
    srcBuffer := ByteArray new:srcBytesPerRow.
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   232
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   233
    dstBuffer := ByteArray new:width.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   234
    srcIdx := 1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   235
    dstIdx := 1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   236
    1 to:height do:[:hi |
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   237
        srcBuffer replaceFrom:1 to:srcBytesPerRow with:srcBytes startingAt:srcIdx.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   238
        srcBuffer expandPixels:srcDepth width:width height:1 into:dstBuffer
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   239
                       mapping:map. 
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   240
        bytes replaceFrom:dstIdx to:dstIdx+width-1 with:dstBuffer startingAt:1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   241
        dstIdx := dstIdx + width.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   242
        srcIdx := srcIdx + srcBytesPerRow.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   243
    ]
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   244
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   245
    "
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   246
     |i1 i2 i4 i8 i16 i24|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   247
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   248
     i1 := Image fromFile:'bitmaps/SBrowser.xbm'.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   249
     i2 := Depth2Image fromImage:i1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   250
     i4 := Depth4Image fromImage:i1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   251
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   252
     i8 := Depth8Image fromImage:i1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   253
     i8 inspect.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   254
     i8 := Depth8Image fromImage:i2.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   255
     i8 inspect.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   256
     i8 := Depth8Image fromImage:i4.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   257
     i8 inspect.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   258
    "
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   259
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   260
    "Modified: 24.4.1997 / 14:01:14 / cg"
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   261
! !
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   262
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   263
!Depth8Image methodsFor:'converting palette images'!
304f026e10cd Initial revision
claus
parents:
diff changeset
   264
853
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   265
asGray8FormOn:aDevice
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   266
    "return an 8-bit greyForm from the 8-bit receiver image.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   267
     Redefined, since only a translation has to be done here."
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   268
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   269
    |greyBits map
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   270
     mapSize "{ Class: SmallInteger }"|
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   271
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   272
    greyBits := ByteArray uninitializedNew:(width * height).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   273
304f026e10cd Initial revision
claus
parents:
diff changeset
   274
    map := ByteArray uninitializedNew:256.
304f026e10cd Initial revision
claus
parents:
diff changeset
   275
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   276
    1 to:256 do:[:i |
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   277
        map at:i put:((self colorFromValue:(i-1)) brightness * 255) rounded
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   278
    ].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   279
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   280
"/    mapSize := colorMap size.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   281
"/
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   282
"/    1 to:mapSize do:[:i |
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   283
"/        map at:i put:((colorMap at:i) brightness * 255) rounded
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   284
"/    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   285
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   286
    bytes expandPixels:8         "xlate only"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   287
                width:width 
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   288
               height:height
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   289
                 into:greyBits
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   290
              mapping:map.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   291
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   292
    ^ self makeDeviceGrayPixmapOn:aDevice depth:8 fromArray:greyBits
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   293
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   294
    "Modified: 10.6.1996 / 20:10:14 / cg"
853
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   295
    "Created: 14.6.1996 / 15:23:09 / cg"
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   296
!
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   297
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   298
asGrayFormOn:aDevice
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   299
    "get a gray device form.
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   300
     Redefined, since we can do it with simple translate, 
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   301
     if the depth matches my depth."
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   302
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   303
    (aDevice visualType == #StaticGray) ifTrue:[
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   304
        (aDevice depth == 8) ifTrue:[
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   305
            ^ self asGray8FormOn:aDevice
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   306
        ].
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   307
    ].
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   308
    ^ super asGrayFormOn:aDevice
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   309
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   310
    "Created: 10.6.1996 / 18:51:19 / cg"
93598e697248 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 839
diff changeset
   311
    "Modified: 10.6.1996 / 18:54:36 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   312
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   313
304f026e10cd Initial revision
claus
parents:
diff changeset
   314
paletteImageAsPseudoFormOn:aDevice
304f026e10cd Initial revision
claus
parents:
diff changeset
   315
    "return a pseudoForm from the palette picture. The main work is
304f026e10cd Initial revision
claus
parents:
diff changeset
   316
     in color reduction, when not all colors can be aquired."
304f026e10cd Initial revision
claus
parents:
diff changeset
   317
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   318
    |pseudoBits f gcRound has8BitImage deviceDepth
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   319
     imgMap newImage pixelRow dColors
154
claus
parents: 151
diff changeset
   320
     usedColors usageCounts maxIndex map
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   321
     fit scale lastOK error 
154
claus
parents: 151
diff changeset
   322
     div 
claus
parents: 151
diff changeset
   323
     bitsPerRGB "{Class: SmallInteger }"
claus
parents: 151
diff changeset
   324
     shift      "{Class: SmallInteger }"
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   325
     m          "{Class: SmallInteger }" 
1220
d22a0f15273a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1179
diff changeset
   326
     cube nR nG nB ditherColors|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   327
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   328
    (cube := aDevice fixColors) notNil ifTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   329
        nR := aDevice numFixRed.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   330
        nG := aDevice numFixGreen.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   331
        nB := aDevice numFixBlue.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   332
880
8b2c06ed438d added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
   333
        DitherAlgorithm == #floydSteinberg ifTrue:[
8b2c06ed438d added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
   334
            f := self
8b2c06ed438d added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
   335
                   asFloydSteinbergDitheredDepth8FormOn:aDevice 
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   336
                   colors:cube 
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   337
                   nRed:nR
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   338
                   nGreen:nG
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   339
                   nBlue:nB.
880
8b2c06ed438d added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
   340
        ] ifFalse:[
8b2c06ed438d added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
   341
            f := self
8b2c06ed438d added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
   342
                   asNearestPaintDepth8FormOn:aDevice 
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   343
                   colors:cube 
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   344
                   nRed:nR
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   345
                   nGreen:nG
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 933
diff changeset
   346
                   nBlue:nB.
880
8b2c06ed438d added #nearestPaint for fixColor images
Claus Gittinger <cg@exept.de>
parents: 875
diff changeset
   347
        ].
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   348
        f notNil ifTrue:[^ f].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   349
    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   350
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   351
    "find used colors"
304f026e10cd Initial revision
claus
parents:
diff changeset
   352
154
claus
parents: 151
diff changeset
   353
    usedColors := bytes usedValues.    "gets us an array filled with used values"
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   354
                                       "(could use bytes asBag)"
154
claus
parents: 151
diff changeset
   355
    maxIndex := usedColors max + 1.
claus
parents: 151
diff changeset
   356
180
claus
parents: 158
diff changeset
   357
    usedColors size > 20 ifTrue:[
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
   358
        ('Depth8Image [info]: allocating ' , usedColors size printString , ' colors ...') infoPrintCR.
180
claus
parents: 158
diff changeset
   359
    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   360
304f026e10cd Initial revision
claus
parents:
diff changeset
   361
    "sort by usage"
304f026e10cd Initial revision
claus
parents:
diff changeset
   362
    usageCounts := bytes usageCounts.
304f026e10cd Initial revision
claus
parents:
diff changeset
   363
    usageCounts := usedColors asArray collect:[:clr | usageCounts at:(clr + 1)].
304f026e10cd Initial revision
claus
parents:
diff changeset
   364
    usageCounts sort:[:a :b | a > b] with:usedColors.
304f026e10cd Initial revision
claus
parents:
diff changeset
   365
304f026e10cd Initial revision
claus
parents:
diff changeset
   366
    "allocate the colors (in order of usage count)"
304f026e10cd Initial revision
claus
parents:
diff changeset
   367
154
claus
parents: 151
diff changeset
   368
    imgMap := Array new:maxIndex.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   369
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   370
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   371
     first, try to get the exact colors ...
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   372
    "
154
claus
parents: 151
diff changeset
   373
    bitsPerRGB := aDevice bitsPerRGB.
claus
parents: 151
diff changeset
   374
    shift := (8 - bitsPerRGB) negated.
claus
parents: 151
diff changeset
   375
    m := (1 bitShift:bitsPerRGB) - 1.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   376
    div := m asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
   377
304f026e10cd Initial revision
claus
parents:
diff changeset
   378
    fit := true.
304f026e10cd Initial revision
claus
parents:
diff changeset
   379
    scale := 100.0 / div.       "to scale 0..255 into 0.0 .. 100.0"
304f026e10cd Initial revision
claus
parents:
diff changeset
   380
    lastOK := 0.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   381
    gcRound := 0.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   382
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   383
    usedColors do:[:aColorIndex |
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   384
        |devColor color
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   385
         r        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   386
         g        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   387
         b        "{Class: SmallInteger }"
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   388
         mapIndex "{Class: SmallInteger }"|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   389
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   390
        fit ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   391
            mapIndex := aColorIndex + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   392
            color := colorMap at:mapIndex.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   393
            (color colorId notNil 
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
   394
            and:[color graphicsDevice == aDevice]) ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   395
                "wow - an immediate hit"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   396
                devColor := color
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   397
            ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   398
                devColor := color exactOn:aDevice.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   399
                devColor isNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   400
                    "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   401
                     could not allocate color - on the first round, do a GC to flush 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   402
                     unused colors - this may help if some colors where locked by 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   403
                     already free images.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   404
                    "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   405
                    gcRound == 0 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   406
                        ObjectMemory scavenge; finalize.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   407
                        devColor := color exactOn:aDevice.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   408
                        gcRound := 1
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   409
                    ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   410
                    devColor isNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   411
                        gcRound == 1 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   412
                            CollectGarbageWhenRunningOutOfColors ifTrue:[
1177
e89408c15bb5 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   413
                                'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR.
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   414
                                ObjectMemory incrementalGC; finalize.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   415
                                devColor := color exactOn:aDevice.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   416
                            ].    
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   417
                            gcRound := 2
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   418
                        ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   419
                    ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   420
                ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   421
            ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   422
            (devColor notNil and:[devColor colorId notNil]) ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   423
                imgMap at:mapIndex put:devColor.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   424
                lastOK := lastOK + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   425
            ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   426
                fit := false
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   427
            ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   428
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   429
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   430
304f026e10cd Initial revision
claus
parents:
diff changeset
   431
    fit ifFalse:[
1628
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   432
        ('Depth8Image [info]: got %1 exact colors (out of %2)' bindWith:lastOK with:usedColors size) infoPrintCR.
157
claus
parents: 156
diff changeset
   433
1628
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   434
        DitherAlgorithm == #floydSteinberg ifTrue:[
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   435
            dColors := colorMap asArray collect:[:clr | clr isNil ifTrue:[clr]
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   436
                                                          ifFalse:[clr nearestOn:aDevice]].
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   437
            dColors := dColors select:[:clr | clr notNil].
1846
6080866bf196 care to not use invalid colors for dithering
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   438
            dColors := dColors collect:[:clr | clr exactOn:aDevice].
6080866bf196 care to not use invalid colors for dithering
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   439
            dColors := dColors select:[:clr | clr notNil].
1628
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   440
            dColors := dColors asSet.
1922
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   441
            dColors addAll:((aDevice colorMap collect:[:c|c onDevice:aDevice])
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   442
                            select:[:c | c colorId notNil]).
1628
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   443
            ditherColors := aDevice availableDitherColors.
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   444
            ditherColors notNil ifTrue:[
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   445
                dColors addAll:ditherColors.
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   446
            ].
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   447
            dColors := dColors asArray.
1922
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   448
            dColors size > 256 ifTrue:[
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   449
                dColors := dColors copyTo:256
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   450
            ].
1628
204f3a5afc2a dont forget to flip mask.
Claus Gittinger <cg@exept.de>
parents: 1609
diff changeset
   451
            ^ self asFloydSteinbergDitheredPseudoFormUsing:dColors on:aDevice
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   452
        ].
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   453
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   454
        "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   455
         again, this time allow wrong colors (loop while increasing allowed error)
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   456
        "
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   457
        error := 1.
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   458
        [fit] whileFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   459
            fit := true.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   460
            usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   461
                |devColor color
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   462
                 r        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   463
                 g        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   464
                 b        "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   465
                 mapIndex "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   466
                 rMask    "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   467
                 gMask    "{Class: SmallInteger }"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   468
                 bMask    "{Class: SmallInteger }"|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   469
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   470
                fit ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   471
                    gMask := bMask := rMask := m.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   472
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   473
                    mapIndex := aColorIndex + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   474
                    color := colorMap at:mapIndex.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   475
                    r := (color red * 255 / 100.0) rounded.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   476
                    g := (color green * 255 / 100.0) rounded.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   477
                    b := (color blue * 255 / 100.0) rounded.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   478
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   479
                    color := Color red:((r bitShift:shift) bitAnd:rMask) * scale
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   480
                                 green:((g bitShift:shift) bitAnd:gMask) * scale
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   481
                                  blue:((b bitShift:shift) bitAnd:bMask) * scale.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   482
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   483
                    (color colorId notNil 
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
   484
                    and:[color graphicsDevice == aDevice]) ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   485
                        "wow - an immediate hit"
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   486
                        devColor := color.
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   487
                    ] ifFalse:[
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   488
                        devColor := color nearestOn:aDevice.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   489
                        (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   490
                            devColor := nil
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   491
                        ].
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   492
                        devColor isNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   493
                            "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   494
                             no free color - on the first round, do a GC to flush unused
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   495
                             colors - this may help if some colors where locked by already
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   496
                             free images.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   497
                            "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   498
                            gcRound == 0 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   499
                                ObjectMemory scavenge; finalize.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   500
                                devColor := color nearestOn:aDevice.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   501
                                (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   502
                                    devColor := nil
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   503
                                ].
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   504
                                gcRound := 1
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   505
                            ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   506
                            devColor isNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   507
                                gcRound == 1 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   508
                                    CollectGarbageWhenRunningOutOfColors ifTrue:[
1177
e89408c15bb5 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   509
                                        'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR.
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   510
                                        ObjectMemory incrementalGC; finalize.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   511
                                        devColor := color nearestOn:aDevice.
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   512
                                        (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   513
                                            devColor := nil
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   514
                                        ].
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   515
                                    ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   516
                                    gcRound := 2
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   517
                                ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   518
                            ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   519
                        ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   520
                    ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   521
                    (devColor notNil and:[devColor colorId notNil]) ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   522
                        imgMap at:mapIndex put:devColor.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   523
                        lastOK := lastOK + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   524
                    ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   525
                        fit := false
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   526
                    ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   527
                ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   528
            ].
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   529
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   530
            fit ifTrue:[
1177
e89408c15bb5 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   531
                ('Depth8Image [info]: remaining colors with error <= %1' bindWith:error) infoPrintCR.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   532
            ].
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   533
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   534
            error := error * 2.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   535
            error > 100 ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   536
                "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   537
                 break out, if the error becomes too big.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   538
                "
1179
e0ef3e3c28d0 *PrintNL eliminated
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   539
                'Depth8Image [info]: hard color allocation problem - revert to b&w for remaining colors' infoPrintCR.
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   540
                "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   541
                 map to b&w as a last fallback.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   542
                 (should really do a dither here)
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   543
                "
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   544
                usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   545
                    |color
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   546
                     mapIndex "{ Class: SmallInteger }"|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   547
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   548
                    mapIndex := aColorIndex + 1.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   549
                    color := colorMap at:mapIndex.
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   550
                    color brightness > 0.4 ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   551
                        color := Color white.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   552
                    ] ifFalse:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   553
                        color := Color black.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   554
                    ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   555
                    imgMap at:mapIndex put:(color on:aDevice).
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   556
                ].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   557
                fit := true.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   558
            ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   559
        ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   560
859
34268959162d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 855
diff changeset
   561
        error > 10 ifTrue:[
1179
e0ef3e3c28d0 *PrintNL eliminated
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   562
            'Depth8Image [info]: not enough colors for a reasonable image' infoPrintCR
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   563
        ] ifFalse:[
1179
e0ef3e3c28d0 *PrintNL eliminated
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   564
            'Depth8Image [info]: not enough colors for exact picture' infoPrintCR.
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   565
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   566
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   567
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   568
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   569
     create translation map (from image colors to allocated colorIds)
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   570
    "
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   571
    map := ByteArray new:256.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   572
    1 to:imgMap size do:[:i |
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   573
        |clr|
154
claus
parents: 151
diff changeset
   574
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   575
        (clr := imgMap at:i) notNil ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   576
            map at:i put:clr colorId
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   577
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   578
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   579
154
claus
parents: 151
diff changeset
   580
    "
claus
parents: 151
diff changeset
   581
     does the device support 8-bit images ?
claus
parents: 151
diff changeset
   582
    "
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   583
    deviceDepth := aDevice depth.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   584
    deviceDepth == 8 ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   585
        has8BitImage := true.
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   586
    ] ifFalse:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   587
        has8BitImage := false.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   588
        aDevice supportedImageFormats do:[:fmt |
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   589
            (fmt at:#bitsPerPixel) == 8 ifTrue:[
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   590
                has8BitImage := true.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   591
            ]
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   592
        ]
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   593
    ].
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   594
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   595
    "
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   596
     finally, create a form on the device and copy (& translate)
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   597
     the pixel values
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
   598
    "
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   599
    has8BitImage ifTrue:[
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   600
        pseudoBits := ByteArray uninitializedNew:(width * height).
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   601
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   602
        bytes expandPixels:8         "xlate only"
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   603
                    width:width 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   604
                   height:height
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   605
                     into:pseudoBits
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   606
                  mapping:map.
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   607
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   608
        map := nil.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   609
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   610
        f := Form width:width height:height depth:deviceDepth on:aDevice.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   611
        f isNil ifTrue:[^ nil].
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   612
        f colorMap:imgMap. 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   613
        f initGC.
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   614
        aDevice drawBits:pseudoBits bitsPerPixel:8 depth:deviceDepth  
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   615
                   width:width height:height
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   616
                       x:0 y:0
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   617
                    into:(f id) x:0 y:0 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   618
                   width:width height:height with:(f gcId).
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   619
        ^ f
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   620
    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   621
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   622
    "
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   623
     slow fall back: convert into appropriate depth image,
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   624
     by looping over each pixel individually
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   625
    "
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   626
    newImage := (Image implementorForDepth:deviceDepth) new.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   627
    newImage width:width.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   628
    newImage height:height.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   629
    newImage bits:(ByteArray uninitializedNew:(height * newImage bytesPerRow)).
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   630
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   631
    0 to:height-1 do:[:row |
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   632
        pixelRow := self rowAt:row.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   633
        pixelRow
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   634
            expandPixels:8         "xlate only"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   635
            width:width 
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   636
            height:1
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   637
            into:pixelRow
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   638
            mapping:map.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   639
        newImage rowAt:row putAll:pixelRow
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   640
    ].
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   641
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   642
    f := Form width:width height:height depth:deviceDepth on:aDevice.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   643
    f isNil ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
   644
    f colorMap:imgMap. 
304f026e10cd Initial revision
claus
parents:
diff changeset
   645
    f initGC.
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   646
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   647
    aDevice drawBits:(newImage bits) depth:deviceDepth width:width height:height
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   648
                   x:0 y:0
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   649
                into:(f id) x:0 y:0 
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   650
               width:width height:height with:(f gcId).
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
   651
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   652
    ^ f
855
9b5aa569679f support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 853
diff changeset
   653
1922
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
   654
    "Modified: 15.10.1997 / 01:48:20 / cg"
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   655
!
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   656
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   657
paletteImageAsTrueColorFormOn:aDevice
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   658
    "return a true-color device-form for the palette-image receiver.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   659
     Supports true color devices with depths: 8, 16, 24 and 32"
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   660
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   661
    |depth 
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   662
     nColors "{ Class: SmallInteger }"
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   663
     colorValues 
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   664
     scaleRed scaleGreen scaleBlue redShift greenShift blueShift
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   665
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel 
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   666
     n|
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   667
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   668
    depth := aDevice depth.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   669
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   670
    "/ gather r/g/b values for all colors in the map ...
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   671
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   672
    nColors := colorMap size.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   673
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   674
    "/ precompute scales to map from 0..100 into devices range
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   675
    "/ (this may be different for the individual components)
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   676
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   677
    scaleRed := ((1 bitShift:aDevice bitsRed) - 1) / 100.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   678
    scaleGreen := ((1 bitShift:aDevice bitsGreen) - 1) / 100.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   679
    scaleBlue := ((1 bitShift:aDevice bitsBlue) - 1) / 100.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   680
    redShift := aDevice shiftRed.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   681
    greenShift := aDevice shiftGreen.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   682
    blueShift := aDevice shiftBlue.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   683
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   684
    colorValues := Array uninitializedNew:nColors.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   685
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   686
    1 to:nColors do:[:index |
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   687
        |clr rv gv bv v "{ Class: SmallInteger }" |
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   688
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   689
        clr := colorMap at:index.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   690
        clr notNil ifTrue:[
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   691
            rv := (clr red * scaleRed) rounded.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   692
            gv := (clr green * scaleGreen) rounded.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   693
            bv := (clr blue * scaleBlue) rounded.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   694
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   695
            v := rv bitShift:redShift.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   696
            v := v bitOr:(gv bitShift:greenShift).
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   697
            v := v bitOr:(bv bitShift:blueShift).
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   698
            colorValues at:index put:v.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   699
"/ clr print. ' ' print.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   700
"/ rv print. ' ' print. gv print. ' ' print. bv print. ' ' print.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   701
"/ ' -> ' print. v printNL.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   702
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   703
        ]
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   704
    ].
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   705
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   706
    bestFormat := self bestSupportedImageFormatFor:aDevice.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   707
    usedDeviceDepth := bestFormat at:#depth.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   708
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   709
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   710
    "/ for now, only support some depths
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   711
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   712
    usedDeviceBitsPerPixel == 16 ifTrue:[
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   713
        "/ 16 bits/pixel
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   714
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   715
        imageBits := ByteArray uninitializedNew:(width * height * 2).
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   716
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   717
        "/ now, walk over the image and replace
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   718
        "/ colorMap indices by color values in the bits array
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   719
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   720
%{  
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   721
        if (__bothSmallInteger(_INST(height), _INST(width))
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   722
         && __isArray(colorValues)
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   723
         && __isByteArray(_INST(bytes))
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   724
         && __isByteArray(imageBits)) {
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   725
            int x, y, w, h, nPix;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   726
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   727
            unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
   728
            unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   729
            OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   730
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   731
            w = __intVal(_INST(width));
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   732
            h = __intVal(_INST(height));
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   733
            nPix = w * h;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   734
            while (nPix > 0) {
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   735
                unsigned idx, v;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   736
                OBJ clr;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   737
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   738
                idx = *srcPtr;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   739
                clr = ap[idx];
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   740
                v = __intVal(clr);
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   741
#ifdef MSBFIRST
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   742
                ((short *)dstPtr)[0] = v;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   743
#else
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   744
                dstPtr[0] = (v>>8) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   745
                dstPtr[1] = (v) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   746
#endif
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   747
                dstPtr += 2;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   748
                srcPtr += 1;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   749
                nPix--;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   750
            }
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   751
        }
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   752
%}.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   753
    ] ifFalse:[
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   754
        usedDeviceBitsPerPixel == 32 ifTrue:[
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   755
            "/ 32 bits/pixel
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   756
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   757
            imageBits := ByteArray uninitializedNew:(width * height * 4).
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   758
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   759
            "/ now, walk over the image and replace
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   760
            "/ colorMap indices by color values in the bits array
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   761
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   762
%{       
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   763
            if (__bothSmallInteger(_INST(height), _INST(width))
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   764
             && __isArray(colorValues)
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   765
             && __isByteArray(_INST(bytes))
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   766
             && __isByteArray(imageBits)) {
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   767
                int x, y, w, h, nPix;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   768
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   769
                unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
   770
                unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   771
                OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   772
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   773
                w = __intVal(_INST(width));
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   774
                h = __intVal(_INST(height));
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   775
                nPix = w * h;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   776
                while (nPix > 0) {
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   777
                    unsigned idx, v;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   778
                    OBJ clr;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   779
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   780
                    idx = *srcPtr;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   781
                    clr = ap[idx];
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   782
                    v = __intVal(clr);
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   783
#ifdef MSBFIRST
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   784
                    ((long *)dstPtr)[0] = v;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   785
#else
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   786
                    dstPtr[0] = (v>>24) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   787
                    dstPtr[1] = (v>>16) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   788
                    dstPtr[2] = (v>>8) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   789
                    dstPtr[3] = (v) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   790
#endif
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   791
                    dstPtr += 4;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   792
                    srcPtr += 1;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   793
                    nPix--;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   794
                }
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   795
            }
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   796
%}.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   797
        ] ifFalse:[
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   798
            usedDeviceBitsPerPixel == 8 ifTrue:[
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   799
                "/ 8 bits/pixel
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   800
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   801
                imageBits := ByteArray uninitializedNew:(width * height).
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   802
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   803
                "/ now, walk over the image and replace
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   804
                "/ colorMap indices by color values in the bits array
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   805
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   806
%{       
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   807
                if (__bothSmallInteger(_INST(height), _INST(width))
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   808
                 && __isArray(colorValues)
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   809
                 && __isByteArray(_INST(bytes))
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   810
                 && __isByteArray(imageBits)) {
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   811
                    int x, y, w, h, nPix;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   812
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   813
                    unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
   814
                    unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   815
                    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   816
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   817
                    w = __intVal(_INST(width));
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   818
                    h = __intVal(_INST(height));
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   819
                    nPix = w * h;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   820
                    while (nPix > 0) {
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   821
                        unsigned idx, v;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   822
                        OBJ clr;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   823
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   824
                        idx = *srcPtr;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   825
                        clr = ap[idx];
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   826
                        v = __intVal(clr);
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   827
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   828
                        dstPtr[0] = v;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   829
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   830
                        dstPtr += 1;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   831
                        srcPtr += 1;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   832
                        nPix--;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   833
                    }
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   834
                }
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   835
%}.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   836
            ] ifFalse:[
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   837
                usedDeviceBitsPerPixel == 24 ifTrue:[
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   838
                    "/ 24 bits/pixel
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   839
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   840
                    imageBits := ByteArray uninitializedNew:(width * height * 3).
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   841
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   842
                    "/ now, walk over the image and replace
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   843
                    "/ colorMap indices by color values in the bits array
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   844
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   845
%{       
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   846
                    if (__bothSmallInteger(_INST(height), _INST(width))
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   847
                     && __isArray(colorValues)
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   848
                     && __isByteArray(_INST(bytes))
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   849
                     && __isByteArray(imageBits)) {
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   850
                        int x, y, w, h, nPix;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   851
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   852
                        unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
   853
                        unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   854
                        OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   855
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   856
                        w = __intVal(_INST(width));
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   857
                        h = __intVal(_INST(height));
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   858
                        nPix = w * h;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   859
                        while (nPix > 0) {
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   860
                            unsigned idx, v;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   861
                            OBJ clr;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   862
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   863
                            idx = *srcPtr;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   864
                            clr = ap[idx];
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   865
                            v = __intVal(clr);
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   866
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   867
                            dstPtr[0] = (v>>16) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   868
                            dstPtr[1] = (v>>8) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   869
                            dstPtr[2] = (v) & 0xFF;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   870
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   871
                            dstPtr += 3;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   872
                            srcPtr += 1;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   873
                            nPix--;
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   874
                        }
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   875
                    }
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   876
%}.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   877
                ]
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   878
            ]
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   879
        ]
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   880
    ].
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   881
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   882
    imageBits isNil ifTrue:[            
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   883
        'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   884
        ^ self asMonochromeFormOn:aDevice
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   885
    ].
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   886
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   887
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   888
    form isNil ifTrue:[^ nil].
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   889
    form initGC.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   890
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   891
    form 
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   892
        copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth 
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   893
               width:width height:height 
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   894
                   x:0 y:0 toX:0 y:0. 
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   895
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   896
    ^ form
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   897
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   898
    "Created: 20.10.1995 / 22:05:10 / cg"
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   899
    "Modified: 21.10.1995 / 19:30:26 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   900
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
   901
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   902
!Depth8Image methodsFor:'dither helpers'!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   903
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1658
diff changeset
   904
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   905
    "return the bitmap for a dithered depth-bitmap from the image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   906
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   907
     Redefined to make use of knowing that pixels are 8-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   908
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   909
    |dH nDither   
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   910
     greyLevels greyMap1 greyMap2
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   911
     bytesPerRow  "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   912
     bytesPerOutRow  "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   913
     pixelsPerByte   "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   914
     outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   915
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   916
     h               "{Class: SmallInteger }" |
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   917
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   918
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   919
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   920
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   921
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   922
    h := height.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   923
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   924
    greyLevels := 1 bitShift:depth.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   925
    pixelsPerByte := 8 / depth.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   926
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   927
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   928
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   929
    bytesPerOutRow := (w * depth + 7) // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   930
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   931
    (outBits isNil or:[bytes isNil]) ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   932
        ^ nil
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   933
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   934
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   935
    greyMap1 := self greyMapForRange:(greyLevels-1).                    "/ the pixels
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   936
    greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   937
                                            0
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   938
                                        ] ifFalse:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   939
                                            b truncated
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   940
                                        ]
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   941
                                  ]) asByteArray.      
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   942
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   943
    greyMap2 := self greyMapForRange:(greyLevels-1).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   944
    greyMap2 := (greyMap2 collect:[:el | 
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   945
                                        el isNil ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   946
                                            0
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   947
                                        ] ifFalse:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   948
                                            ((el - el truncated)  "/ the error (0..1)
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   949
                                            * nDither) rounded
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   950
                                        ]]) asByteArray.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   951
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   952
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   953
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   954
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   955
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   956
    int __dT, __dO;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   957
    int __depth = __intVal(depth);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   958
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   959
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   960
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   961
    int __grey, __pixel;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   962
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   963
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   964
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   965
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   966
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   967
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   968
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   969
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   970
    int __bytesPerOutRow = __intVal(bytesPerOutRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   971
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
   972
    unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   973
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   974
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   975
    unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   976
    unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   977
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   978
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   979
    for (__y=0; __y<__h; __y++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   980
        __nextDst = __dstIdx + __bytesPerOutRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   981
        __nextSrc = __srcIdx + __bytesPerRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   982
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   983
        __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   984
        __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   985
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   986
        __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   987
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   988
        for (__x=0; __x<__w; __x++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   989
            __grey = __bytes[__srcIdx++];            /* 0..255 */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   990
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   991
            __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   992
            __dO    = __greyMap2[__grey];            /* 0.. nDither-1) */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   993
            __dT = __ditherMatrix[__dY + __oX];
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   994
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   995
            if (__dO > __dT)                         /* dither says: next pixel */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   996
                __pixel++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   997
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   998
            __oX++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
   999
            if (__oX == __dW) __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1000
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1001
            __byte = (__byte << __depth) | __pixel;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1002
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1003
            __bitCnt = __bitCnt - __depth;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1004
            if (__bitCnt == 0) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1005
                __outBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1006
                __dstIdx++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1007
                __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1008
                __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1009
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1010
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1011
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1012
        if (__bitCnt != 8) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1013
            __byte = __byte << __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1014
            __outBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1015
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1016
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1017
        __oY++; __dY += __dW;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1018
        if (__oY == __dH) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1019
            __oY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1020
            __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1021
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1022
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1023
        __srcIdx = __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1024
        __dstIdx = __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1025
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1026
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1027
    ^ outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1028
!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1029
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1030
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1031
    "return the dithered monochrome bits for the receiver image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1032
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1033
     Redefined to make use of knowing that pixels are 8-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1034
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1035
    |f dH nDither   
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1036
     greyMap monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1037
     bytesPerMonoRow "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1038
     bytesPerRow     "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1039
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1040
     h               "{Class: SmallInteger }"|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1041
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1042
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1043
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1044
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1045
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1046
    h := height.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1047
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1048
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1049
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1050
    bytesPerMonoRow := w + 7 // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1051
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1052
    (monoBits isNil or:[bytes isNil]) ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1053
        ^ nil
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1054
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1055
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1056
    greyMap := self greyByteMapForRange:nDither.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1057
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1058
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1059
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1060
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1061
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1062
    int __dT;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1063
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1064
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1065
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1066
    int __grey;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1067
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1068
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1069
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1070
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1071
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1072
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1073
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1074
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1075
    int __bytesPerMonoRow = __intVal(bytesPerMonoRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1076
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1077
    unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1078
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1079
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1080
    unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1081
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1082
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1083
    for (__y=0; __y<__h; __y++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1084
        __nextDst = __dstIdx + __bytesPerMonoRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1085
        __nextSrc = __srcIdx + __bytesPerRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1086
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1087
        __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1088
        __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1089
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1090
        __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1091
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1092
        for (__x=__w; __x>0; __x--) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1093
            __grey = __bytes[__srcIdx];   /* 0..255 */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1094
            __srcIdx++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1095
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1096
            __grey = __greyMap[__grey];
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1097
            __dT = __ditherMatrix[__dY + __oX];
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1098
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1099
            __oX++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1100
            if (__oX == __dW) __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1101
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1102
            __byte = __byte << 1;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1103
            if (__grey > __dT) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1104
                __byte = __byte | 1;           /* white */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1105
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1106
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1107
            __bitCnt--;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1108
            if (__bitCnt == 0) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1109
                __monoBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1110
                __dstIdx++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1111
                __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1112
                __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1113
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1114
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1115
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1116
        if (__bitCnt != 8) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1117
            __byte = __byte << __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1118
            __monoBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1119
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1120
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1121
        __oY++; __dY += __dW;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1122
        if (__oY == __dH) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1123
            __oY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1124
            __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1125
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1126
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1127
        __srcIdx = __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1128
        __dstIdx = __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1129
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1130
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1131
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1132
    ^ monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1133
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1134
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1135
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1136
1609
42e9d60aaca9 comments
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
  1137
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1138
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1139
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1140
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1141
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1142
1609
42e9d60aaca9 comments
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
  1143
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1144
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1145
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1146
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1147
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1148
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1149
     i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1150
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1151
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1152
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1153
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1154
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1155
     i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1156
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1157
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1158
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1159
    "Created: 7.6.1996 / 10:48:06 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1160
    "Modified: 7.6.1996 / 11:08:50 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1161
! !
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1162
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1163
!Depth8Image methodsFor:'enumerating'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1164
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1165
colorsAtY:y from:xLow to:xHigh do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1166
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1167
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1168
     This method allows slighly faster processing of an
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1169
     image than using atX:y:, since some processing can be
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1170
     avoided when going from pixel to pixel. However, for
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1171
     real image processing, specialized methods should be written."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1172
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1173
    |srcIndex "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1174
     value    "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1175
     x1       "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1176
     x2       "{ Class: SmallInteger }"
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1177
     color colorArray|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1178
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1179
    x1 := xLow.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1180
    x2 := xHigh.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1181
    srcIndex := (width * y) + 1 + x1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1182
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1183
    colorArray := Array new:256.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1184
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1185
    x1 to:x2 do:[:x |
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1186
        value := bytes at:srcIndex.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1187
        srcIndex := srcIndex + 1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1188
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1189
        color := colorArray at:value+1.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1190
        color isNil ifTrue:[
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1191
            color := self colorFromValue:value.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1192
            colorArray at:value+1 put:color
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1193
        ].
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1194
        aBlock value:x value:color
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1195
    ]
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1196
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1197
    "Created: 7.6.1996 / 19:12:35 / cg"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1198
    "Modified: 11.7.1996 / 20:22:32 / cg"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1199
!
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1200
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1201
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1202
    "perform aBlock for each pixel in the rectangle
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1203
     yStart..yEnd / xStart..xEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1204
     The block is passed the color at each pixel.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1205
     This method allows slighly faster processing of an
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1206
     image than using individual atX:y: accesses, 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1207
     both since some processing can be avoided when going from pixel to pixel,
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1208
     and since the color composition is done outside of the pixel loop. 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1209
     However, for real high performance image processing, specialized methods 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1210
     should be written which know how to deal with specific photometric interpretations."
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1211
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1212
    |srcIndex    "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1213
     srcNext     "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1214
     bytesPerRow "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1215
     value    "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1216
     x1       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1217
     x2       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1218
     y1       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1219
     y2       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1220
     colorArray|
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1221
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1222
    x1 := xStart.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1223
    x2 := xEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1224
    y1 := yStart.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1225
    y2 := yEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1226
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1227
    srcIndex := (width * y1) + x1 + 1 .
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1228
    bytesPerRow := self bytesPerRow.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1229
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1230
    colorArray := self realColorMap.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1231
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1232
    y1 to:y2 do:[:y |
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1233
        srcNext := srcIndex + bytesPerRow.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1234
        x1 to:x2 do:[:x |
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1235
            value := bytes at:srcIndex.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1236
            srcIndex := srcIndex + 1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1237
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1238
            aBlock value:x value:y value:(colorArray at:value+1)
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1239
        ].
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1240
        srcIndex := srcNext.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1241
    ].
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1242
    ^ self
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  1243
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1244
    "Created: 7.6.1996 / 19:12:35 / cg"
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1245
    "Modified: 11.7.1996 / 20:20:55 / cg"
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1246
!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1247
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1248
valuesAtY:y from:xLow to:xHigh do:aBlock
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1249
    "perform aBlock for each pixelValue from x1 to x2 in row y.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1250
     The block is passed the pixelValue at each pixel.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1251
     This method allows slighly faster processing of an
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1252
     image than using valueAtX:y:, since some processing can be
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1253
     avoided when going from pixel to pixel. However, for
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1254
     real image processing, specialized methods should be written."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1255
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1256
    |srcIndex   "{ Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1257
     pixelValue "{ Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1258
     x1         "{ Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1259
     x2         "{ Class: SmallInteger }"|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1260
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1261
    x1 := xLow.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1262
    x2 := xHigh.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1263
    srcIndex := (width * y) + 1 + x1.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1264
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1265
    x1 to:x2 do:[:x |
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1266
        pixelValue := bytes at:srcIndex.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1267
        srcIndex := srcIndex + 1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1268
        aBlock value:x value:pixelValue 
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1269
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1270
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1271
    "Created: 7.6.1996 / 19:09:47 / cg"
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1272
!
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1273
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1274
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1275
    "perform aBlock for each pixel in the rectangle
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1276
     yStart..yEnd / xStart..xEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1277
     The block is passed the pixelValue at each pixel.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1278
     This method allows slighly faster processing of an
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1279
     image than using individual valueAtX:y: accesses, 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1280
     since some processing can be avoided when going from pixel to pixel.. 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1281
     However, for real high performance image processing, specialized methods 
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1282
     should be written which know how to deal with specific photometric interpretations."
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1283
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1284
    |srcIndex    "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1285
     srcNext     "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1286
     bytesPerRow "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1287
     value    "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1288
     x1       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1289
     x2       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1290
     y1       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1291
     y2       "{ Class: SmallInteger }"|
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1292
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1293
    x1 := xStart.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1294
    x2 := xEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1295
    y1 := yStart.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1296
    y2 := yEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1297
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1298
    srcIndex := (width * y1) + x1 + 1 .
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1299
    bytesPerRow := self bytesPerRow.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1300
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1301
    y1 to:y2 do:[:y |
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1302
        srcNext := srcIndex + bytesPerRow.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1303
        x1 to:x2 do:[:x |
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1304
            value := bytes at:srcIndex.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1305
            srcIndex := srcIndex + 1.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1306
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1307
            aBlock value:x value:y value:value
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1308
        ].
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1309
        srcIndex := srcNext.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1310
    ].
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1311
    ^ self
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1312
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1313
    "Modified: 11.7.1996 / 20:06:47 / cg"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1314
    "Created: 11.7.1996 / 20:08:11 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1315
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
  1316
12
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
  1317
!Depth8Image methodsFor:'image manipulations'!
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
  1318
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1319
hardMagnifiedBy:scalePoint
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1320
    "return a new image magnified by scalePoint, aPoint.
12
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
  1321
     This is the general magnification method, handling non-integral values"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1322
304f026e10cd Initial revision
claus
parents:
diff changeset
  1323
    |mX mY
304f026e10cd Initial revision
claus
parents:
diff changeset
  1324
     newWidth  "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  1325
     newHeight "{ Class: SmallInteger }"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1326
     w         "{ Class: SmallInteger }"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1327
     h         "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  1328
     newImage newBytes
304f026e10cd Initial revision
claus
parents:
diff changeset
  1329
     value     "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  1330
     srcRowIdx "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  1331
     srcIndex  "{ Class: SmallInteger }"
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1332
     dstIndex  "{ Class: SmallInteger }"
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1333
     newMask|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1334
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1335
    mX := scalePoint x.
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1336
    mY := scalePoint y.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1337
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
  1338
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
304f026e10cd Initial revision
claus
parents:
diff changeset
  1339
304f026e10cd Initial revision
claus
parents:
diff changeset
  1340
    newWidth := (width * mX) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
  1341
    newHeight := (height * mY) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
  1342
304f026e10cd Initial revision
claus
parents:
diff changeset
  1343
    newBytes := ByteArray uninitializedNew:(newWidth * newHeight).
304f026e10cd Initial revision
claus
parents:
diff changeset
  1344
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1345
    mask notNil ifTrue:[
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1346
        newMask := (mask magnifiedBy:scalePoint)
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1347
    ].
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1348
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1349
    newImage := self species new.
887
a455ac21b8ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
  1350
    newImage 
a455ac21b8ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
  1351
        width:newWidth 
a455ac21b8ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
  1352
        height:newHeight 
a455ac21b8ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
  1353
        photometric:photometric 
a455ac21b8ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
  1354
        samplesPerPixel:samplesPerPixel 
a455ac21b8ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
  1355
        bitsPerSample:#(8) 
a455ac21b8ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
  1356
        colorMap:colorMap copy
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1357
        bits:newBytes
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  1358
        mask:newMask.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1359
304f026e10cd Initial revision
claus
parents:
diff changeset
  1360
    "walk over destination image fetching pixels from source image"
304f026e10cd Initial revision
claus
parents:
diff changeset
  1361
304f026e10cd Initial revision
claus
parents:
diff changeset
  1362
    mY := mY asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
  1363
    mX := mX asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
  1364
%{
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1365
    unsigned char *__dstP = _ByteArrayInstPtr(newBytes)->ba_element;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1366
    unsigned char *__srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1367
    unsigned char *__srcRowP;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1368
    int __width = __intVal(_INST(width));
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1369
    int __w = __intVal(newWidth) - 1;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1370
    int __h = __intVal(newHeight) - 1;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1371
    int __row, __col;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1372
    double __mX = _floatVal(mX);
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1373
    double __mY = _floatVal(mY);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1374
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1375
    for (__row = 0; __row <= __h; __row++) {
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1376
        __srcRowP = __srcP + (__width * (int)((double)__row / __mY));
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1377
        for (__col = 0; __col <= __w; __col++) {
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1378
            *__dstP++ = __srcRowP[(int)((double)__col / __mX)];
887
a455ac21b8ca checkin from browser
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
  1379
        }
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1380
    }
304f026e10cd Initial revision
claus
parents:
diff changeset
  1381
%}
304f026e10cd Initial revision
claus
parents:
diff changeset
  1382
.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1383
"/   the above C-code is equivalent to:
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1384
"/
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1385
"/    dstIndex := 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1386
"/    w := newWidth - 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1387
"/    h := newHeight - 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1388
"/    0 to:h do:[:row |
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1389
"/        srcRowIdx := (width * (row // mY)) + 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1390
"/        0 to:w do:[:col |
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1391
"/            srcIndex := srcRowIdx + (col // mX).
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1392
"/            value := bytes at:srcIndex.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1393
"/            newBytes at:dstIndex put:value.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1394
"/            dstIndex := dstIndex + 1
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1395
"/        ]
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1396
"/    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  1397
"/
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1398
304f026e10cd Initial revision
claus
parents:
diff changeset
  1399
    ^ newImage
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1400
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1401
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1402
magnifyRowFrom:srcBytes offset:srcStart  
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1403
	  into:dstBytes offset:dstStart factor:mX
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1404
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1405
    "magnify a single pixel row - can only magnify by integer factors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1406
     Specially tuned for factors 2,3 and 4."
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1407
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1408
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1409
    REGISTER unsigned char *srcP, *dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1410
    REGISTER unsigned char _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1411
    int _mag;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1412
    REGISTER int i;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1413
    int _pixels;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1414
    OBJ w = _INST(width);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1415
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1416
    if (__bothSmallInteger(srcStart, dstStart)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1417
     && __bothSmallInteger(w, mX)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1418
     && __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1419
	_mag = _intVal(mX);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1420
	srcP = _ByteArrayInstPtr(srcBytes)->ba_element - 1 + _intVal(srcStart);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1421
	dstP = _ByteArrayInstPtr(dstBytes)->ba_element - 1 + _intVal(dstStart);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1422
	_pixels = _intVal(w);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1423
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1424
	switch (_mag) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1425
	    case 1:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1426
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1427
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1428
	    case 2:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1429
		/* special code for common case */
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1430
		while (_pixels--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1431
		    _byte = *srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1432
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1433
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1434
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1435
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1436
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1437
	    case 3:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1438
		/* special code for common case */
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1439
		while (_pixels--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1440
		    _byte = *srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1441
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1442
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1443
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1444
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1445
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1446
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1447
	    case 4:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1448
		/* special code for common case */
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1449
		while (_pixels--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1450
		    _byte = *srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1451
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1452
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1453
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1454
		    *dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1455
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1456
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1457
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1458
	    default:
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1459
		while (_pixels--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1460
		    _byte = *srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1461
		    for (i=_mag; i>0; i--)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1462
			*dstP++ = _byte;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1463
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1464
		break;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1465
	}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1466
	RETURN (self);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1467
    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1468
%}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1469
.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1470
    self primitiveFailed
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1471
! !
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1472
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1473
!Depth8Image methodsFor:'private'!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1474
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1475
dither1PlaneUsingMap:map on:aDevice
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1476
    "a helper for dithering palette and greyscale images"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1477
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1478
    |f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1479
     patterns formBytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1480
     pixel0bytes pixel1bytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1481
     clr ditherPattern
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1482
     nColors       "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1483
     w             "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1484
     h             "{Class: SmallInteger }"|
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1485
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1486
    nColors := map size.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1487
    w := width.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1488
    h := height.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1489
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1490
    formBytes := ByteArray uninitializedNew:(w + 7 // 8) * h.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1491
    patterns := Array new:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1492
    pixel0bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1493
    pixel1bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1494
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1495
    "
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1496
     extract dither patterns and values to use for 1/0 bits
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1497
     in those from the dithercolors
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1498
    "
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1499
    1 to:nColors do:[:i |
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1500
	clr := (map at:i) on:aDevice.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1501
	ditherPattern := clr ditherForm.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1502
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1503
	ditherPattern isNil ifTrue:[
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1504
	    patterns at:i put:#[2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1505
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1506
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1507
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1508
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1509
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1510
				2r11111111
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1511
				2r11111111].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1512
	    pixel0bytes at:i put:clr colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1513
	    pixel1bytes at:i put:clr colorId
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1514
	] ifFalse:[
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1515
	    patterns at:i put:(ditherPattern bits).
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1516
	    pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1517
	    pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1518
	].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1519
    ].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1520
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1521
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1522
    unsigned char *_srcP, *_dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1523
    OBJ _patternBytes;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1524
    unsigned char __mask = 0x80;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1525
    unsigned char _outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1526
    unsigned char _last, _v, _patternBits, _p0, _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1527
    int _h, _w;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1528
    int _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1529
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1530
    _srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1531
    _dstP = _ByteArrayInstPtr(formBytes)->ba_element;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1532
    for (_h = _intVal(h); _h; _h--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1533
	_last = -1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1534
	for (_w = _intVal(w); _w; _w--) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1535
	    _v = *_srcP++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1536
	    if (_v != _last) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1537
		_patternBytes = _ArrayInstPtr(patterns)->a_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1538
		if (__isByteArray(_patternBytes)) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1539
		    _patternBits = _ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1540
		} else if (__isArray(_patternBytes)) {
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1541
		    _patternBits = _intVal(_ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1542
		}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1543
		_p0 = _ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1544
		_p1 = _ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1545
		_last = _v;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1546
	    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1547
	    _outBits <<= 1;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1548
	    if (_patternBits & __mask)
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1549
		_outBits |= _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1550
	    else
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1551
		_outBits |= _p0;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1552
	    __mask >>= 1;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1553
	    if (__mask == 0) {
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1554
		__mask = 0x80;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1555
		*_dstP++ = _outBits;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1556
		_outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1557
	    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1558
	}
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1559
	if (__mask != 0x80) {
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1560
	    while (__mask != 0) {
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1561
		_outBits <<= 1;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1562
		__mask >>= 1;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1563
	    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1564
	    *_dstP++ = _outBits;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1565
	    __mask = 0x80;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1566
	    _outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1567
	}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1568
	_patternOffset++;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1569
	if (_patternOffset == 8)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1570
	    _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1571
    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1572
%}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1573
.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1574
    f := Form width:w height:h fromArray:formBytes.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1575
    ^ f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1576
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1577
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1578
dither2PlaneUsingMap:map on:aDevice
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1579
    "a helper for dithering palette and greyscale images"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1580
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1581
    |f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1582
     patterns formBytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1583
     pixel0bytes pixel1bytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1584
     clr ditherPattern
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1585
     nColors       "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1586
     w             "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1587
     h             "{Class: SmallInteger }"|
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1588
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1589
    nColors := map size.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1590
    w := width.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1591
    h := height.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1592
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1593
    formBytes := ByteArray uninitializedNew:(w * 2 + 7 // 8) * h.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1594
    patterns := Array new:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1595
    pixel0bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1596
    pixel1bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1597
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1598
    "extract dither patterns and values to use for 1/0 bits
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1599
     in those from the dithercolors"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1600
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1601
    1 to:nColors do:[:i |
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1602
        clr := (map at:i) on:aDevice.
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1603
        ditherPattern := clr ditherForm.
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1604
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1605
        ditherPattern isNil ifTrue:[
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1606
            patterns at:i put:#[2r11111111
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1607
                                2r11111111
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1608
                                2r11111111
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1609
                                2r11111111
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1610
                                2r11111111
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1611
                                2r11111111
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1612
                                2r11111111
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1613
                                2r11111111].
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1614
            pixel0bytes at:i put:clr colorId.
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1615
            pixel1bytes at:i put:clr colorId
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1616
        ] ifFalse:[
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1617
            patterns at:i put:(ditherPattern bits).
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1618
            pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1619
            pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1620
        ].
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1621
    ].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1622
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1623
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1624
    unsigned char *_srcP, *_dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1625
    OBJ _patternBytes;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1626
    unsigned char __mask = 0x80;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1627
    unsigned char _outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1628
    unsigned char _last, _v, _patternBits, _p0, _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1629
    int _h, _w;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1630
    int _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1631
    int _outCount;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1632
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1633
    _srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1634
    _dstP = _ByteArrayInstPtr(formBytes)->ba_element;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1635
    for (_h = _intVal(h); _h; _h--) {
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1636
        _last = -1;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1637
        _outCount = 0;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1638
        for (_w = _intVal(w); _w; _w--) {
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1639
            _v = *_srcP++;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1640
            if (_v != _last) {
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1641
                _patternBytes = _ArrayInstPtr(patterns)->a_element[_v];
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1642
                if (__isByteArray(_patternBytes)) {
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1643
                    _patternBits = _ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1644
                } else if (__isArray(_patternBytes)) {
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1645
                    _patternBits = _intVal(_ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1646
                }
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1647
                _p0 = _ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1648
                _p1 = _ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1649
                _last = _v;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1650
            }
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1651
            _outBits <<= 2;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1652
            if (_patternBits & __mask)
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1653
                _outBits |= _p1;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1654
            else
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1655
                _outBits |= _p0;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1656
            __mask >>= 1;
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1657
            _outCount++;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1658
            if (_outCount == 4) {
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1659
                *_dstP++ = _outBits;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1660
                _outCount = 0;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1661
                if (__mask == 0) {
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1662
                    __mask = 0x80;
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1663
                }
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1664
            }
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1665
        }
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1666
        if (_outCount) {
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1667
            do {
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1668
                _outBits <<= 2;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1669
            } while (++_outCount != 4);
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1670
            *_dstP++ = _outBits;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1671
        }
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  1672
        __mask = 0x80;
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1673
        _outBits = 0;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1674
        _patternOffset++;
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1675
        if (_patternOffset == 8)
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1676
            _patternOffset = 0;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1677
    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1678
%}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1679
.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1680
    f := Form width:w height:h depth:2.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1681
    f initGC.
927
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1682
    f graphicsDevice 
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1683
        drawBits:formBytes depth:2 width:w height:h x:0 y:0
c4bc2a7ff733 use #graphicsDevice instead of #device.
Claus Gittinger <cg@exept.de>
parents: 887
diff changeset
  1684
        into:f id x:0 y:0 width:w height:h with:f gcId.
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1685
    ^ f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1686
! !
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1687
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1688
!Depth8Image methodsFor:'queries'!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1689
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1690
bitsPerPixel
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1691
    "return the number of bits per pixel"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1692
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1693
    ^ 8
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1694
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1695
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1696
bitsPerRow
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1697
    "return the number of bits in one scanline of the image"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1698
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1699
    ^  width * 8
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1700
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1701
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1702
bytesPerRow
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1703
    "return the number of bytes in one scanline of the image"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1704
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1705
    ^ width
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1706
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1707
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1708
usedValues
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1709
    "return a collection of color values used in the receiver."
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1710
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1711
    ^ bytes usedValues
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1712
! !
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1713
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
  1714
!Depth8Image class methodsFor:'documentation'!
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1715
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1716
version
1922
73114e8c9518 if display is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1846
diff changeset
  1717
    ^ '$Header: /cvs/stx/stx/libview/Depth8Image.st,v 1.75 1997-10-15 11:23:11 cg Exp $'
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1718
! !