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