Depth8Image.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Sat, 26 Nov 2016 21:09:32 +0000
branchjv
changeset 7719 c2f802dd340a
parent 7597 5abdbcd771e5
child 7754 2aac86a2c288
permissions -rw-r--r--
XFT: Forbid XFT rendering on bitmaps (depth-1 pixmaps) In theory it could work if XFT would just turn gray into either black or white. But XFT doesn't do it and simply draw nothing without failing in any way. To prevent this silent failures, forbid drawing XFT onto bitmaps (depth-1 pixmaps). After all, the while point of XFT is to use anti-aliased fonts.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7597
5abdbcd771e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7533
diff changeset
     1
"{ Encoding: utf8 }"
5abdbcd771e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7533
diff changeset
     2
5
claus
parents: 1
diff changeset
     3
"
claus
parents: 1
diff changeset
     4
 COPYRIGHT (c) 1993 by Claus Gittinger
71
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
     5
	      All Rights Reserved
5
claus
parents: 1
diff changeset
     6
claus
parents: 1
diff changeset
     7
 This software is furnished under a license and may be used
claus
parents: 1
diff changeset
     8
 only in accordance with the terms of that license and with the
claus
parents: 1
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
claus
parents: 1
diff changeset
    10
 be provided or otherwise made available to, or used by, any
claus
parents: 1
diff changeset
    11
 other person.  No title to or ownership of the software is
claus
parents: 1
diff changeset
    12
 hereby transferred.
claus
parents: 1
diff changeset
    13
"
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    14
"{ Package: 'stx:libview' }"
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    15
6837
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
    16
"{ NameSpace: Smalltalk }"
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
    17
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    18
Image subclass:#Depth8Image
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    19
	instanceVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    20
	classVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    21
	poolDictionaries:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    22
	category:'Graphics-Images'
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    23
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    24
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    25
!Depth8Image class methodsFor:'documentation'!
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    26
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    27
copyright
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    28
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    29
 COPYRIGHT (c) 1993 by Claus Gittinger
71
6a42b2b115f8 *** empty log message ***
claus
parents: 66
diff changeset
    30
	      All Rights Reserved
5
claus
parents: 1
diff changeset
    31
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    32
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    33
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    35
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    36
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    37
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    38
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    39
!
5
claus
parents: 1
diff changeset
    40
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    41
documentation
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    42
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    43
    this class represents 256-color (8 bit / pixel) images (palette, greyscale ...).
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    44
    It mainly consists of methods already implemented in Image,
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    45
    reimplemented here for more performance.
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    46
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    47
    [author:]
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
    48
	Claus Gittinger
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    49
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    50
    [see also:]
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
    51
	Depth1Image Depth2Image Depth4Image Depth16Image Depth24Image
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
    52
	ImageReader
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    53
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    54
! !
5
claus
parents: 1
diff changeset
    55
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
    56
!Depth8Image class methodsFor:'queries'!
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    57
4889
91227e415992 photometric
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
    58
defaultPhotometric
6310
612c17181395 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6299
diff changeset
    59
    "return the default photometric pixel interpretation.
612c17181395 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6299
diff changeset
    60
     This may be a somewhat old leftover from times, when tiff was the first image file type to be read.
612c17181395 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6299
diff changeset
    61
     Much better would be to always have some (possibly fake and virtual) colormap around, and ask that one.
612c17181395 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6299
diff changeset
    62
     However, in the meantime, many other classes depend on that, so that it should be kept as an API 
612c17181395 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6299
diff changeset
    63
     - even when the internal representation will be replaced by something better in the future."
612c17181395 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6299
diff changeset
    64
4889
91227e415992 photometric
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
    65
    ^ #palette
91227e415992 photometric
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
    66
!
91227e415992 photometric
Claus Gittinger <cg@exept.de>
parents: 4783
diff changeset
    67
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
    68
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    69
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    70
     this class - here we return 8"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    71
304f026e10cd Initial revision
claus
parents:
diff changeset
    72
    ^ 8
304f026e10cd Initial revision
claus
parents:
diff changeset
    73
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    74
    "Modified: 20.4.1996 / 23:40:22 / cg"
81
4ba554473294 *** empty log message ***
claus
parents: 75
diff changeset
    75
! !
4ba554473294 *** empty log message ***
claus
parents: 75
diff changeset
    76
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 2864
diff changeset
    77
!Depth8Image methodsFor:'accessing-pixels'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    78
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    79
pixelAtX:x y:y
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    80
    "retrieve a pixel at x/y; return a pixelValue.
7518
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
    81
     The interpretation of the returned value depends on the photometric
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
    82
     and the colormap. See also Image>>atX:y:)
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    83
     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
    84
     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
    85
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    86
    |index "{ Class: SmallInteger }"|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    87
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    88
%{  /* NOCONTEXT */
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    89
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
    90
    OBJ b = __INST(bytes);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
    91
    OBJ w = __INST(width);
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    92
5472
5508a0ac6319 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5453
diff changeset
    93
    if (__isByteArrayLike(b)
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
    94
     && __bothSmallInteger(x, y)
7276
3af688594d98 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 6837
diff changeset
    95
     && __isSmallInteger(w)
3af688594d98 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 6837
diff changeset
    96
     && (__INST(pixelFunction)==nil) ) {
6299
83fea4366ebd pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    97
        int _idx, _pix;
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
    98
6299
83fea4366ebd pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
    99
        _idx = (__intVal(w) * __intVal(y)) + __intVal(x);
83fea4366ebd pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   100
        if ((unsigned)_idx < __byteArraySize(b)) {
83fea4366ebd pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   101
            _pix = __ByteArrayInstPtr(b)->ba_element[_idx];
83fea4366ebd pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   102
            RETURN( __MKSMALLINT(_pix) );
83fea4366ebd pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   103
        }
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   104
    }
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   105
%}.
6299
83fea4366ebd pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   106
    pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y].
83fea4366ebd pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   107
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   108
    "/ the code below is only evaluated if the bytes-collection is
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   109
    "/ not a ByteArray, or the arguments are not integers
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   110
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   111
    index := (width * y) + 1 + x.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   112
    ^ bytes at:index.
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
pixelAtX:x y:y put:aPixelValue
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   116
    "set the pixel at x/y to aPixelValue.
7518
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
   117
     The interpretation of the pixelValue depends on the photometric
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
   118
     and the colormap. (see also: Image>>atX:y:put:)
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   119
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
   120
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
   121
304f026e10cd Initial revision
claus
parents:
diff changeset
   122
    |index "{ Class: SmallInteger }"|
304f026e10cd Initial revision
claus
parents:
diff changeset
   123
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   124
%{  /* NOCONTEXT */
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   125
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
   126
    OBJ b = __INST(bytes);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
   127
    OBJ w = __INST(width);
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   128
5472
5508a0ac6319 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5453
diff changeset
   129
    if (__isByteArrayLike(b)
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   130
     && __bothSmallInteger(x, y)
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   131
     && __bothSmallInteger(w, aPixelValue) ) {
7518
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
   132
        int _idx;
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   133
7518
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
   134
        _idx = (__intVal(w) * __intVal(y)) + __intVal(x);
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
   135
        if ((unsigned)_idx < __byteArraySize(b)) {
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
   136
            __ByteArrayInstPtr(b)->ba_element[_idx] = __intVal(aPixelValue);
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
   137
            RETURN( self );
de8364635170 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7496
diff changeset
   138
        }
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   139
    }
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   140
%}.
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
   141
    "fall back code for nonByteArray or nonInteger arguments"
1634
72ee64fad9fe tuned #valueAtX:y: and #atX:y:putValue:
Claus Gittinger <cg@exept.de>
parents: 1628
diff changeset
   142
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   143
    index := (width * y) + 1 + x.
304f026e10cd Initial revision
claus
parents:
diff changeset
   144
    bytes at:index put:aPixelValue.
304f026e10cd Initial revision
claus
parents:
diff changeset
   145
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   146
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   147
rowAt:y into:aPixelBuffer startingAt:startIndex
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   148
    "fill aPixelBuffer with pixel values from a single row.
7524
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   149
     Notice: row/column coordinates start at 0."
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   150
5851
ce6442599a43 changed: #rowAt:into:startingAt:
Claus Gittinger <cg@exept.de>
parents: 5472
diff changeset
   151
    |srcIdx endIndex n|
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   152
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   153
    bytes notNil ifTrue:[
7524
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   154
        srcIdx := (y * width) + 1.
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   155
        n := width.
5851
ce6442599a43 changed: #rowAt:into:startingAt:
Claus Gittinger <cg@exept.de>
parents: 5472
diff changeset
   156
7524
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   157
        endIndex := srcIdx+width-1.
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   158
        endIndex > bytes size ifTrue:[
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   159
            self assert:(bytes size >= endIndex).
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   160
            endIndex := bytes size.
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   161
            n := endIndex - srcIdx + 1.
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   162
        ].
5851
ce6442599a43 changed: #rowAt:into:startingAt:
Claus Gittinger <cg@exept.de>
parents: 5472
diff changeset
   163
7524
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   164
        aPixelBuffer replaceFrom:startIndex to:startIndex+n-1 with:bytes startingAt:srcIdx.
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   165
        ^ self.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   166
    ].
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   167
    ^ super rowAt:y into:aPixelBuffer startingAt:startIndex
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   168
5851
ce6442599a43 changed: #rowAt:into:startingAt:
Claus Gittinger <cg@exept.de>
parents: 5472
diff changeset
   169
    "Modified: / 16-02-2012 / 15:58:01 / cg"
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   170
!
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   171
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   172
rowAt:y putAll:pixelArray startingAt:startIndex
7524
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   173
    "store a single row's bits from bits in the pixelArray argument;
780f829a2e1f #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7518
diff changeset
   174
     Notice: row/column coordinates start at 0."
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   175
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   176
    |dstIdx|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   177
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3869
diff changeset
   178
    dstIdx := (y * width) + 1.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   179
    self bits replaceFrom:dstIdx to:dstIdx+width-1 with:pixelArray startingAt:startIndex.
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   180
    ^ pixelArray
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   181
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   182
    "Created: 24.4.1997 / 15:49:42 / cg"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   183
! !
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
   184
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   185
!Depth8Image methodsFor:'converting'!
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1634
diff changeset
   186
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   187
fromImage:anImage
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   188
    "setup the receiver from another image.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   189
     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
   190
     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
   191
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   192
    |srcBytesPerRow "{ Class: SmallInteger }"
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   193
     srcIdx "{ Class: SmallInteger }"
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   194
     dstIdx "{ Class: SmallInteger }"
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   195
     w      "{ Class: SmallInteger }"
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   196
     h      "{ Class: SmallInteger }"
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   197
     srcBuffer dstBuffer srcBytes
3900
2ee04532b466 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   198
     srcDepth map bytes|
2202
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:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   202
	^ super fromImage:anImage
2202
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
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   205
    width := w := anImage width.
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   206
    height := h := anImage height.
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   207
    bytes := ByteArray uninitializedNew:(w * h).
2202
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:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   213
	"/ if source has no colorMap, more work is needed ...
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   214
	map := #(
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   215
		#[0 16rFF]
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   216
		#[0 16r55 16rAA 16rFF]
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   217
		nil
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   218
		#[16r00 16r11 16r22 16r33 16r44 16r55 16r66 16r77
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   219
		  16r88 16r99 16rAA 16rBB 16rCC 16rDD 16rEE 16rFF]
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   220
	       ) at:srcDepth.
2202
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
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   231
    dstBuffer := ByteArray new:w.
2202
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.
3900
2ee04532b466 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   234
    bytes := self bits.
2ee04532b466 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   235
    bytes isNil ifTrue:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   236
	self bits:(bytes := ByteArray new:(self bytesPerRow * self height)).
3900
2ee04532b466 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3897
diff changeset
   237
    ].
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   238
    1 to:h do:[:hi |
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   239
	srcBuffer replaceFrom:1 to:srcBytesPerRow with:srcBytes startingAt:srcIdx.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   240
	srcBuffer expandPixels:srcDepth width:w height:1 into:dstBuffer mapping:map.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   241
	bytes replaceFrom:dstIdx to:dstIdx+w-1 with:dstBuffer startingAt:1.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   242
	dstIdx := dstIdx + w.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   243
	srcIdx := srcIdx + srcBytesPerRow.
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   244
    ]
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
    "
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   247
     |i1 i2 i4 i8 i16 i24|
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   248
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   249
     i1 := Image fromFile:'bitmaps/SBrowser.xbm'.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   250
     i2 := Depth2Image fromImage:i1.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   251
     i4 := Depth4Image fromImage:i1.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   252
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   253
     i8 := Depth8Image fromImage:i1.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   254
     i8 inspect.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   255
     i8 := Depth8Image fromImage:i2.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   256
     i8 inspect.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   257
     i8 := Depth8Image fromImage:i4.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   258
     i8 inspect.
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
    "Modified: 24.4.1997 / 14:01:14 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   262
! !
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   263
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   264
!Depth8Image methodsFor:'converting images'!
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   265
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   266
anyImageAsPseudoFormOn:aDevice
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   267
    "return a pseudoForm from the palette picture.
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   268
     The main work is in color reduction, when not all colors can be acquired.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   269
     This method works for any photometric."
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   270
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   271
    |bytes pseudoBits f gcRound has8BitImage deviceDepth
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   272
     imgMap newImage pixelRow dColors
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   273
     usedColors usageCounts maxIndex map
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   274
     fit scale lastOK error
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   275
     div
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   276
     bitsPerRGB "{Class: SmallInteger }"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   277
     shift      "{Class: SmallInteger }"
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   278
     m          "{Class: SmallInteger }"
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   279
     mapSize    "{Class: SmallInteger }"
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   280
     cube nR nG nB ditherColors clr|
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   281
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   282
    (cube := aDevice fixColors) notNil ifTrue:[
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   283
        nR := aDevice numFixRed.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   284
        nG := aDevice numFixGreen.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   285
        nB := aDevice numFixBlue.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   286
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   287
        DitherAlgorithm == #floydSteinberg ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   288
            f := self
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   289
                   asFloydSteinbergDitheredDepth8FormOn:aDevice
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   290
                   colors:cube
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   291
                   nRed:nR
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   292
                   nGreen:nG
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   293
                   nBlue:nB.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   294
        ] ifFalse:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   295
            f := self
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   296
                   asNearestPaintDepth8FormOn:aDevice
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   297
                   colors:cube
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   298
                   nRed:nR
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   299
                   nGreen:nG
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   300
                   nBlue:nB.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   301
        ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   302
        f notNil ifTrue:[^ f].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   303
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   304
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   305
    "find used colors"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   306
    bytes := self bits.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   307
    usedColors := bytes usedValues.    "gets us an array filled with used values"
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   308
                                       "(could use bytes asBag)"
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   309
    maxIndex := usedColors max + 1.
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
    usedColors size > 20 ifTrue:[
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   312
        ('Depth8Image [info]: allocating ' , usedColors size printString , ' colors ...') infoPrintCR.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   313
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   314
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   315
    "sort by usage"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   316
    usageCounts := bytes usageCounts.
6039
6883ca47d798 Don't do collect:[] as:Array and select:[] as:Array
Stefan Vogel <sv@exept.de>
parents: 6036
diff changeset
   317
    usageCounts := (usedColors collect:[:clr | usageCounts at:(clr + 1)]) asArray.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   318
    usageCounts sort:[:a :b | a > b] with:usedColors.
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
    "allocate the colors (in order of usage count)"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   321
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   322
    imgMap := Array new:maxIndex.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   323
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   324
    "
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   325
     first, try to get the exact colors ...
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   326
    "
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   327
    bitsPerRGB := aDevice bitsPerRGB.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   328
    shift := (8 - bitsPerRGB) negated.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   329
    m := (1 bitShift:bitsPerRGB) - 1.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   330
    div := m asFloat.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   331
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   332
    fit := true.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   333
    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
   334
    lastOK := 0.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   335
    gcRound := 0.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   336
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   337
    usedColors do:[:aColorIndex |
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   338
        |devColor color
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   339
         r        "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   340
         g        "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   341
         b        "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   342
         mapIndex "{Class: SmallInteger }"|
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   343
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   344
        fit ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   345
            mapIndex := aColorIndex + 1.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   346
            "/ color := colorMap at:mapIndex.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   347
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   348
            color := self colorFromValue:aColorIndex.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   349
            (color isOnDevice:aDevice) ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   350
                "wow - an immediate hit"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   351
                devColor := color
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   352
            ] ifFalse:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   353
                devColor := color exactOn:aDevice.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   354
                devColor isNil ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   355
                    "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   356
                     could not allocate color - on the first round, do a GC to flush
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   357
                     unused colors - this may help if some colors where locked by
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   358
                     already free images.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   359
                    "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   360
                    gcRound == 0 ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   361
                        ObjectMemory scavenge; finalize.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   362
                        devColor := color exactOn:aDevice.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   363
                        gcRound := 1
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   364
                    ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   365
                    devColor isNil ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   366
                        gcRound == 1 ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   367
                            CollectGarbageWhenRunningOutOfColors ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   368
                                'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   369
                                ObjectMemory incrementalGC; finalize.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   370
                                devColor := color exactOn:aDevice.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   371
                            ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   372
                            gcRound := 2
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   373
                        ]
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   374
                    ]
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   375
                ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   376
            ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   377
            (devColor notNil and:[devColor colorId notNil]) ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   378
                imgMap at:mapIndex put:devColor.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   379
                lastOK := lastOK + 1.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   380
            ] ifFalse:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   381
                fit := false
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   382
            ]
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   383
        ]
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   384
    ].
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
    fit ifFalse:[
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   387
        ('Depth8Image [info]: got %1 exact colors (out of %2)' bindWith:lastOK with:usedColors size) infoPrintCR.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   388
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   389
        DitherAlgorithm == #floydSteinberg ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   390
            dColors := imgMap collect:[:clr | clr isNil ifTrue:[clr]
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   391
                                                        ifFalse:[clr nearestOn:aDevice]].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   392
            dColors := dColors select:[:clr | clr notNil] thenCollect:[:clr | clr exactOn:aDevice].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   393
            dColors := dColors asSet.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   394
            dColors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice] thenSelect:[:c | c colorId notNil]).
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   395
            ditherColors := aDevice availableDitherColors.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   396
            ditherColors notNil ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   397
                dColors addAll:ditherColors.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   398
            ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   399
            dColors := dColors asArray.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   400
            dColors size > 256 ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   401
                dColors := dColors copyTo:256
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   402
            ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   403
            ^ self asFloydSteinbergDitheredPseudoFormUsing:dColors on:aDevice
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   404
        ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   405
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   406
        "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   407
         again, this time allow wrong colors (loop while increasing allowed error)
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   408
        "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   409
        error := 1.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   410
        [fit] whileFalse:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   411
            fit := true.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   412
            usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   413
                |devColor color
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   414
                 r        "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   415
                 g        "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   416
                 b        "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   417
                 mapIndex "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   418
                 rMask    "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   419
                 gMask    "{Class: SmallInteger }"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   420
                 bMask    "{Class: SmallInteger }"|
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   421
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   422
                fit ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   423
                    gMask := bMask := rMask := m.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   424
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   425
                    mapIndex := aColorIndex + 1.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   426
                    "/ color := colorMap at:mapIndex.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   427
                    color := self colorFromValue:aColorIndex.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   428
                    r := (color red * 255 / 100.0) rounded.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   429
                    g := (color green * 255 / 100.0) rounded.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   430
                    b := (color blue * 255 / 100.0) rounded.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   431
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   432
                    color := Color red:((r bitShift:shift) bitAnd:rMask) * scale
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   433
                                 green:((g bitShift:shift) bitAnd:gMask) * scale
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   434
                                  blue:((b bitShift:shift) bitAnd:bMask) * scale.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   435
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   436
                    (color isOnDevice:aDevice) ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   437
                        "wow - an immediate hit"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   438
                        devColor := color.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   439
                    ] ifFalse:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   440
                        devColor := color nearestOn:aDevice.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   441
                        (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   442
                            devColor := nil
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   443
                        ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   444
                        devColor isNil ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   445
                            "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   446
                             no free color - on the first round, do a GC to flush unused
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   447
                             colors - this may help if some colors where locked by already
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   448
                             free images.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   449
                            "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   450
                            gcRound == 0 ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   451
                                ObjectMemory scavenge; finalize.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   452
                                devColor := color nearestOn:aDevice.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   453
                                (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   454
                                    devColor := nil
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   455
                                ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   456
                                gcRound := 1
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   457
                            ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   458
                            devColor isNil ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   459
                                gcRound == 1 ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   460
                                    CollectGarbageWhenRunningOutOfColors ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   461
                                        'Depth8Image [info]: force GC for possible color reclamation.' infoPrintCR.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   462
                                        ObjectMemory incrementalGC; finalize.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   463
                                        devColor := color nearestOn:aDevice.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   464
                                        (devColor notNil and:[(devColor deltaFrom:color) > error]) ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   465
                                            devColor := nil
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   466
                                        ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   467
                                    ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   468
                                    gcRound := 2
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   469
                                ]
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   470
                            ]
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   471
                        ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   472
                    ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   473
                    (devColor notNil and:[devColor colorId notNil]) ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   474
                        imgMap at:mapIndex put:devColor.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   475
                        lastOK := lastOK + 1.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   476
                    ] ifFalse:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   477
                        fit := false
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   478
                    ]
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   479
                ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   480
            ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   481
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   482
            fit ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   483
                ('Depth8Image [info]: remaining colors with error <= %1' bindWith:error) infoPrintCR.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   484
            ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   485
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   486
            error := error * 2.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   487
            error > 100 ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   488
                "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   489
                 break out, if the error becomes too big.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   490
                "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   491
                'Depth8Image [info]: hard color allocation problem - revert to b&w for remaining colors' infoPrintCR.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   492
                "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   493
                 map to b&w as a last fallback.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   494
                 (should really do a dither here)
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   495
                "
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   496
                usedColors from:(lastOK+1) to:(usedColors size) do:[:aColorIndex |
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   497
                    |color
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   498
                     mapIndex "{ Class: SmallInteger }"|
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   499
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   500
                    mapIndex := aColorIndex + 1.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   501
                    "/ color := colorMap at:mapIndex.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   502
                    color := self colorFromValue:aColorIndex.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   503
                    color brightness > 0.4 ifTrue:[
7424
79d2310a0c43 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7407
diff changeset
   504
                        color := aDevice whiteColor.
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   505
                    ] ifFalse:[
7424
79d2310a0c43 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7407
diff changeset
   506
                        color := aDevice blackColor.
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   507
                    ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   508
                    imgMap at:mapIndex put:(color onDevice:aDevice).
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   509
                ].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   510
                fit := true.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   511
            ]
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   512
        ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   513
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   514
        error > 10 ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   515
            'Depth8Image [info]: not enough colors for a reasonable image' infoPrintCR
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   516
        ] ifFalse:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   517
            'Depth8Image [info]: not enough colors for exact picture' infoPrintCR.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   518
        ]
1932
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
     create translation map (from image colors to allocated colorIds)
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   523
    "
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   524
    mapSize := imgMap size.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   525
    map := ByteArray new:256.
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
   526
    1 to:mapSize do:[:i |
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   527
        (clr := imgMap at:i) notNil ifTrue:[
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   528
            map at:i put:clr colorId
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   529
        ]
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   530
    ].
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
     does the device support 8-bit images ?
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
    deviceDepth := aDevice depth.
2529
637a5979a3d0 use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2401
diff changeset
   536
    has8BitImage := (deviceDepth == 8)
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   537
                    or:[ (aDevice supportedImageFormatForDepth:8) notNil ].
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   538
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   539
    "
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   540
     finally, create a form on the device and copy (& translate)
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   541
     the pixel values
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   542
    "
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   543
    has8BitImage ifTrue:[
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   544
        pseudoBits := ByteArray uninitializedNew:(width * height).
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   545
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   546
        bytes
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   547
            expandPixels:8         "xlate only"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   548
            width:width height:height
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   549
            into:pseudoBits
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   550
            mapping:map.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   551
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   552
        map := nil.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   553
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   554
        f := Form imageForm width:width height:height depth:deviceDepth onDevice:aDevice.
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   555
        f isNil ifTrue:[^ nil].
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   556
        f colorMap:imgMap.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   557
        f initGC.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   558
        aDevice
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   559
            drawBits:pseudoBits
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   560
            bitsPerPixel:8
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   561
            depth:deviceDepth
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   562
            padding:8
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   563
            width:width height:height
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   564
            x:0 y:0
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   565
            into:(f id) x:0 y:0
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   566
            width:width height:height
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   567
            with:(f gcId).
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   568
        ^ f
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   569
    ].
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   570
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   571
    "
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   572
     slow fall back: convert into appropriate depth image,
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   573
     by looping over each pixel individually
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   574
    "
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   575
    newImage := (Image implementorForDepth:deviceDepth) new.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   576
    newImage width:width.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   577
    newImage height:height.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   578
    newImage bits:(ByteArray uninitializedNew:(height * newImage bytesPerRow)).
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
    0 to:height-1 do:[:row |
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   581
        pixelRow := self rowAt:row.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   582
        pixelRow
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   583
            expandPixels:8         "xlate only"
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   584
            width:width
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   585
            height:1
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   586
            into:pixelRow
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   587
            mapping:map.
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   588
        newImage rowAt:row putAll:pixelRow
1932
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
4783
717a41ef31e4 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4764
diff changeset
   591
    f := Form width:width height:height depth:deviceDepth onDevice:aDevice.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   592
    f isNil ifTrue:[^ nil].
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   593
    f colorMap:imgMap.
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   594
    f initGC.
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   595
1998
606d0a877d4e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1997
diff changeset
   596
    aDevice
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   597
        drawBits:(newImage bits)
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   598
        depth:deviceDepth
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   599
        padding:8
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   600
        width:width height:height
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   601
        x:0 y:0
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   602
        into:(f id) x:0 y:0
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   603
        width:width height:height
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
   604
        with:(f gcId).
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   605
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   606
    ^ f
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   607
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   608
    "Modified: 15.10.1997 / 01:48:20 / cg"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   609
    "Created: 19.10.1997 / 04:57:05 / cg"
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   610
!
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1922
diff changeset
   611
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   612
anyImageAsTrueColorFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   613
    "return a true-color device-form for the receiver.
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   614
     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
   615
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   616
    |depth
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   617
     colorValues
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   618
     form imageBits bestFormat usedDeviceDepth usedDeviceBitsPerPixel
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   619
     usedDevicePadding usedDeviceBytesPerRow padd|
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   620
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   621
    depth := aDevice depth.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   622
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   623
    "/ 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
   624
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   625
    colorValues := self rgbColormapFor:aDevice.
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   626
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   627
    bestFormat := self bestSupportedImageFormatFor:aDevice.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   628
    usedDeviceDepth := bestFormat at:#depth.
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
   629
    usedDeviceDepth == 1 ifTrue:[
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   630
        ^ self asMonochromeFormOn:aDevice
2864
dd151bfdff9d care for deep devices which do not support deep bitmaps
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
   631
    ].
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   632
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
1994
2f12026904e3 oops - care for image padding
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
   633
    usedDevicePadding := bestFormat at:#padding.
2f12026904e3 oops - care for image padding
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
   634
2006
a80384aa337f oops - padding stuff was wrong (16-bit display)
tz
parents: 1998
diff changeset
   635
    usedDeviceBytesPerRow := self class bytesPerRowForWidth:width depth:usedDeviceBitsPerPixel padding:usedDevicePadding.
a80384aa337f oops - padding stuff was wrong (16-bit display)
tz
parents: 1998
diff changeset
   636
    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
   637
    imageBits := ByteArray uninitializedNew:(usedDeviceBytesPerRow * height).
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   638
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   639
    "/ for now, only support some depths
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   640
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   641
    usedDeviceBitsPerPixel == 16 ifTrue:[
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   642
        "/ 16 bits/pixel
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   643
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   644
        "/ now, walk over the image and replace
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   645
        "/ colorMap indices by color values in the bits array
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   646
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   647
%{
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   648
        unsigned char *srcPtr = 0;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   649
        unsigned char *dstPtr = 0;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   650
        OBJ _bytes = __INST(bytes);
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   651
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   652
        if (__isByteArrayLike(_bytes)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   653
            srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   654
        } else {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   655
            if (__isExternalBytesLike(_bytes)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   656
                srcPtr = __externalBytesAddress(_bytes);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   657
            }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   658
        }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   659
        if (__isByteArray(imageBits)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   660
            dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   661
        } else {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   662
            if (__isExternalBytesLike(imageBits)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   663
                dstPtr = __externalBytesAddress(imageBits);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   664
            }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   665
        }
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   666
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   667
        if (__bothSmallInteger(__INST(height), __INST(width))
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   668
         && __isArrayLike(colorValues)
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   669
         && srcPtr
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   670
         && dstPtr) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   671
            int r,p;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   672
            int x, y, w, h, nPix;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   673
            unsigned short pixels[256];
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   674
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   675
            OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   676
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   677
            nPix = __arraySize(colorValues);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   678
            for (p=0; p<nPix; p++) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   679
                pixels[p] = __intVal(ap[p]);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   680
            }
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   681
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   682
            w = __intVal(__INST(width));
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   683
            h = __intVal(__INST(height));
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   684
            r = w;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   685
            p = __intVal(padd);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   686
            nPix = w * h;
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   687
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   688
            while (nPix > 0) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   689
                unsigned idx, v;
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   690
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   691
                if (((unsigned INT)srcPtr & 3) == 0) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   692
                    unsigned INT idx4;
2296
bc86cd7968d7 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2295
diff changeset
   693
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   694
                    while (r > 4) {
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   695
#ifdef __MSBFIRST
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   696
                        idx4 = ((unsigned int *)srcPtr)[0];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   697
                        v = pixels[(idx4 >> 24) & 0xFF];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   698
                        ((short *)dstPtr)[0] = v;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   699
                        v = pixels[(idx4 >> 16) & 0xFF];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   700
                        ((short *)dstPtr)[1] = v;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   701
                        v = pixels[(idx4 >> 8) & 0xFF];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   702
                        ((short *)dstPtr)[2] = v;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   703
                        v = pixels[idx4 & 0xFF];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   704
                        ((short *)dstPtr)[3] = v;
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   705
#else
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   706
# ifdef __LSBFIRST
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   707
                        idx4 = ((unsigned int *)srcPtr)[0];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   708
                        v = pixels[idx4 & 0xFF];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   709
                        dstPtr[0] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   710
                        dstPtr[1] = (v) & 0xFF;
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   711
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   712
                        v = pixels[(idx4 >> 8) & 0xFF];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   713
                        dstPtr[2] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   714
                        dstPtr[3] = (v) & 0xFF;
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   715
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   716
                        v = pixels[(idx4 >> 16) & 0xFF];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   717
                        dstPtr[4] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   718
                        dstPtr[5] = (v) & 0xFF;
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   719
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   720
                        v = pixels[(idx4 >> 24) & 0xFF];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   721
                        dstPtr[6] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   722
                        dstPtr[7] = (v) & 0xFF;
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   723
# else /* unknown/unspecified - code below works on any machine */
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   724
                        idx = srcPtr[0];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   725
                        v = pixels[idx];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   726
                        dstPtr[0] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   727
                        dstPtr[1] = (v) & 0xFF;
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   728
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   729
                        idx = srcPtr[1];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   730
                        v = pixels[idx];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   731
                        dstPtr[2] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   732
                        dstPtr[3] = (v) & 0xFF;
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   733
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   734
                        idx = srcPtr[2];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   735
                        v = pixels[idx];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   736
                        dstPtr[4] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   737
                        dstPtr[5] = (v) & 0xFF;
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   738
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   739
                        idx = srcPtr[3];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   740
                        v = pixels[idx];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   741
                        dstPtr[6] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   742
                        dstPtr[7] = (v) & 0xFF;
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
   743
# endif
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   744
#endif
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   745
                        r -= 4;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   746
                        dstPtr += 8;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   747
                        nPix -= 4;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   748
                        srcPtr +=4;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   749
                    }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   750
                }
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   751
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   752
                nPix--;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   753
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   754
                idx = *srcPtr++;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   755
                v = pixels[idx];
2401
025c115d121a mips (MSBFIRST) fixes
Claus Gittinger <cg@exept.de>
parents: 2296
diff changeset
   756
#ifdef __MSBFIRST
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   757
                ((short *)dstPtr)[0] = v;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   758
#else
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   759
                dstPtr[0] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   760
                dstPtr[1] = (v) & 0xFF;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   761
#endif
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   762
                dstPtr += 2;
1994
2f12026904e3 oops - care for image padding
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
   763
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   764
                if (--r == 0) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   765
                    dstPtr += p;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   766
                    r = w;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   767
                }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   768
            }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   769
        }
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   770
%}.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   771
    ] ifFalse:[
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   772
        usedDeviceBitsPerPixel == 32 ifTrue:[
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   773
            "/ 32 bits/pixel
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   774
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   775
            "/ now, walk over the image and replace
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   776
            "/ colorMap indices by color values in the bits array
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   777
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   778
%{
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   779
            unsigned char *srcPtr = 0;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   780
            unsigned char *dstPtr = 0;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   781
            OBJ _bytes = __INST(bytes);
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   782
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   783
            if (__isByteArrayLike(_bytes)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   784
                srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   785
            } else {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   786
                if (__isExternalBytesLike(_bytes)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   787
                    srcPtr = __externalBytesAddress(_bytes);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   788
                }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   789
            }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   790
            if (__isByteArray(imageBits)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   791
                dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   792
            } else {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   793
                if (__isExternalBytesLike(imageBits)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   794
                    dstPtr = __externalBytesAddress(imageBits);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   795
                }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   796
            }
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   797
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   798
            if (__bothSmallInteger(__INST(height), __INST(width))
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   799
             && __isArrayLike(colorValues)
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   800
             && srcPtr
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   801
             && dstPtr) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   802
                int x, y, w, h, nPix;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   803
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   804
                OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   805
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   806
                w = __intVal(__INST(width));
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   807
                h = __intVal(__INST(height));
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   808
                nPix = w * h;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   809
                while (nPix > 0) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   810
                    unsigned idx, v;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   811
                    OBJ clr;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   812
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   813
                    idx = *srcPtr;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   814
                    clr = ap[idx];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   815
                    v = __intVal(clr);
2401
025c115d121a mips (MSBFIRST) fixes
Claus Gittinger <cg@exept.de>
parents: 2296
diff changeset
   816
#ifdef __MSBFIRST
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   817
                    ((long *)dstPtr)[0] = v;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   818
#else
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   819
                    dstPtr[0] = (v>>24) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   820
                    dstPtr[1] = (v>>16) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   821
                    dstPtr[2] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   822
                    dstPtr[3] = (v) & 0xFF;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   823
#endif
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   824
                    dstPtr += 4;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   825
                    srcPtr += 1;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   826
                    nPix--;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   827
                }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   828
            }
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   829
%}.
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   830
        ] ifFalse:[
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   831
            usedDeviceBitsPerPixel == 8 ifTrue:[
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   832
                "/ 8 bits/pixel
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   833
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   834
                "/ now, walk over the image and replace
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   835
                "/ colorMap indices by color values in the bits array
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   836
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   837
%{
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   838
                unsigned char *srcPtr = 0;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   839
                unsigned char *dstPtr = 0;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   840
                OBJ _bytes = __INST(bytes);
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   841
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   842
                if (__isByteArrayLike(_bytes)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   843
                    srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   844
                } else {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   845
                    if (__isExternalBytesLike(_bytes)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   846
                        srcPtr = __externalBytesAddress(_bytes);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   847
                    }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   848
                }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   849
                if (__isByteArray(imageBits)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   850
                    dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   851
                } else {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   852
                    if (__isExternalBytesLike(imageBits)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   853
                        dstPtr = __externalBytesAddress(imageBits);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   854
                    }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   855
                }
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   856
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   857
                if (__bothSmallInteger(__INST(height), __INST(width))
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   858
                 && __isArrayLike(colorValues)
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   859
                 && srcPtr
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   860
                 && dstPtr) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   861
                    int x, y, w, h, nPix;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   862
                    int r,p;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   863
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   864
                    OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   865
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   866
                    w = __intVal(__INST(width));
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   867
                    h = __intVal(__INST(height));
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   868
                    r = w;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   869
                    p = __intVal(padd);
1994
2f12026904e3 oops - care for image padding
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
   870
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   871
                    nPix = w * h;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   872
                    while (nPix > 0) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   873
                        unsigned idx, v;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   874
                        OBJ clr;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   875
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   876
                        idx = *srcPtr;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   877
                        clr = ap[idx];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   878
                        v = __intVal(clr);
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   879
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   880
                        dstPtr[0] = v;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   881
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   882
                        dstPtr += 1;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   883
                        srcPtr += 1;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   884
                        nPix--;
1994
2f12026904e3 oops - care for image padding
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
   885
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   886
                        if (--r == 0) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   887
                          dstPtr += p;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   888
                          r = w;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   889
                        }
1994
2f12026904e3 oops - care for image padding
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
   890
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   891
                    }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   892
                }
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   893
%}.
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   894
            ] ifFalse:[
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   895
                usedDeviceBitsPerPixel == 24 ifTrue:[
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   896
                    "/ 24 bits/pixel
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   897
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   898
                    "/ now, walk over the image and replace
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   899
                    "/ colorMap indices by color values in the bits array
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   900
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   901
%{
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   902
                    unsigned char *srcPtr = 0;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   903
                    unsigned char *dstPtr = 0;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   904
                    OBJ _bytes = __INST(bytes);
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   905
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   906
                    if (__isByteArrayLike(_bytes)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   907
                        srcPtr = __ByteArrayInstPtr(_bytes)->ba_element;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   908
                    } else {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   909
                        if (__isExternalBytesLike(_bytes)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   910
                            srcPtr = __externalBytesAddress(_bytes);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   911
                        }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   912
                    }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   913
                    if (__isByteArray(imageBits)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   914
                        dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   915
                    } else {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   916
                        if (__isExternalBytesLike(imageBits)) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   917
                            dstPtr = __externalBytesAddress(imageBits);
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   918
                        }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   919
                    }
3851
34637f468b2a also handle subclasses of ExternalBytes (Mapped..)
Claus Gittinger <cg@exept.de>
parents: 3842
diff changeset
   920
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   921
                    if (__bothSmallInteger(__INST(height), __INST(width))
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   922
                     && __isArrayLike(colorValues)
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   923
                     && srcPtr
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   924
                     && dstPtr) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   925
                        int x, y, w, h, nPix;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   926
                        int r,p;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   927
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   928
                        OBJ *ap = __ArrayInstPtr(colorValues)->a_element;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   929
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   930
                        w = __intVal(__INST(width));
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   931
                        h = __intVal(__INST(height));
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   932
                        r = w;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   933
                        p = __intVal(padd);
1994
2f12026904e3 oops - care for image padding
Claus Gittinger <cg@exept.de>
parents: 1932
diff changeset
   934
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   935
                        nPix = w * h;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   936
                        while (nPix > 0) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   937
                            unsigned idx, v;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   938
                            OBJ clr;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   939
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   940
                            idx = *srcPtr;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   941
                            clr = ap[idx];
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   942
                            v = __intVal(clr);
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   943
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   944
                            dstPtr[0] = (v>>16) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   945
                            dstPtr[1] = (v>>8) & 0xFF;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   946
                            dstPtr[2] = (v) & 0xFF;
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   947
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   948
                            dstPtr += 3;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   949
                            srcPtr += 1;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   950
                            nPix--;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   951
                            if (--r == 0) {
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   952
                              dstPtr += p;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   953
                              r = w;
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   954
                            }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   955
                        }
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   956
                    }
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   957
%}.
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   958
                ]
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   959
            ]
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   960
        ]
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   961
    ].
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   962
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   963
    imageBits isNil ifTrue:[
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   964
        'Image [warning]: unimplemented trueColor depth in paletteImageAsTrueColorFormOn: ' errorPrint. usedDeviceBitsPerPixel errorPrintCR.
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   965
        ^ self asMonochromeFormOn:aDevice
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   966
    ].
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   967
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   968
    form := Form imageForm width:width height:height depth:usedDeviceDepth onDevice:aDevice.
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   969
    form isNil ifTrue:[^ nil].
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   970
    form initGC.
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   971
1997
9981ce9722f4 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1994
diff changeset
   972
    form
7496
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   973
        copyBitsFrom:imageBits
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   974
        bitsPerPixel:usedDeviceBitsPerPixel
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   975
        depth:usedDeviceDepth
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   976
        padding:usedDevicePadding
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   977
        width:width height:height
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   978
        x:0 y:0
b13b7aa23e62 #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7424
diff changeset
   979
        toX:0 y:0.
1603
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   980
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   981
    ^ form
8697ffae0880 moved #paletteImageAsTrueColorForm from Image
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   982
4764
80e412455815 ...:on: -> ...:onDevice:
Claus Gittinger <cg@exept.de>
parents: 4724
diff changeset
   983
    "Created: / 20-10-1995 / 22:05:10 / cg"
80e412455815 ...:on: -> ...:onDevice:
Claus Gittinger <cg@exept.de>
parents: 4724
diff changeset
   984
    "Modified: / 29-05-2007 / 19:22:06 / cg"
2202
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
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   987
asGray8FormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   988
    "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
   989
     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
   990
2774
fff1f399e362 unused variable removed
Claus Gittinger <cg@exept.de>
parents: 2773
diff changeset
   991
    |greyBits map|
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   992
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   993
    greyBits := ByteArray uninitializedNew:(width * height).
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   994
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   995
    map := ByteArray uninitializedNew:256.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   996
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
   997
    1 to:256 do:[:i |
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
   998
	map at:i put:((self colorFromValue:(i-1)) brightness * 255) rounded
2202
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
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1001
    self bits
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1002
	expandPixels:8         "xlate only"
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1003
	width:width
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1004
	height:height
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1005
	into:greyBits
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1006
	mapping:map.
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1007
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1008
    ^ self makeDeviceGrayPixmapOn:aDevice depth:8 fromArray:greyBits
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
    "Modified: 10.6.1996 / 20:10:14 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1011
    "Created: 14.6.1996 / 15:23:09 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1012
!
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1013
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1014
asGrayFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1015
    "get a gray device form.
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1016
     Redefined, since we can do it with simple translate,
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1017
     if the depth matches my depth."
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1018
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1019
    (aDevice visualType == #StaticGray) ifTrue:[
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1020
	(aDevice depth == 8) ifTrue:[
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1021
	    ^ self asGray8FormOn:aDevice
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  1022
	].
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1023
    ].
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1024
    ^ super asGrayFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1025
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1026
    "Created: 10.6.1996 / 18:51:19 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1027
    "Modified: 10.6.1996 / 18:54:36 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1028
!
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1029
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1030
greyImageAsPseudoFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1031
    "return a pseudoForm from the gray picture. The main work is
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
  1032
     in color reduction, when not all colors can be acquired."
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1033
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1034
    ^ self anyImageAsPseudoFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1035
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1036
    "Modified: 19.10.1997 / 04:57:39 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1037
    "Created: 19.10.1997 / 04:58:41 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1038
!
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1039
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1040
greyImageAsTrueColorFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1041
    "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
  1042
     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
  1043
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1044
    |f|
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1045
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1046
    f := self anyImageAsTrueColorFormOn:aDevice.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1047
    f notNil ifTrue:[^ f].
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1048
    ^ super greyImageAsTrueColorFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1049
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1050
    "Created: / 29.7.1998 / 00:19:46 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1051
!
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1052
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1053
paletteImageAsPseudoFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1054
    "return a pseudoForm from the palette picture. The main work is
7407
42d2b51f3c19 #OTHER by mawalch
mawalch
parents: 7361
diff changeset
  1055
     in color reduction, when not all colors can be acquired."
2202
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1056
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1057
    ^ self anyImageAsPseudoFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1058
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1059
    "Modified: 19.10.1997 / 04:57:39 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1060
!
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1061
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1062
paletteImageAsTrueColorFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1063
    "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
  1064
     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
  1065
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1066
    |f|
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1067
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1068
    f := self anyImageAsTrueColorFormOn:aDevice.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1069
    f notNil ifTrue:[^ f].
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1070
    ^ super paletteImageAsTrueColorFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1071
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1072
    "Created: / 24.7.1998 / 01:20:46 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1073
    "Modified: / 29.7.1998 / 00:19:27 / cg"
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1074
!
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1075
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1076
rgbImageAsTrueColorFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1077
    "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
  1078
     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
  1079
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1080
    |f|
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1081
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1082
    f := self anyImageAsTrueColorFormOn:aDevice.
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1083
    f notNil ifTrue:[^ f].
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1084
    ^ super rgbImageAsTrueColorFormOn:aDevice
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1085
03d4cf38f4a5 tuned conversion to rgb-device form
Claus Gittinger <cg@exept.de>
parents: 2184
diff changeset
  1086
    "Created: / 29.7.1998 / 00:21:25 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1087
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
  1088
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1089
!Depth8Image methodsFor:'dither helpers'!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1090
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1091
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1092
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1093
     which must be a depth-8 image.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1094
     This method expects an array of colors to be used for dithering
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1095
     (which need not be a colorCubes colors)."
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1096
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1097
    |pseudoBits
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1098
     rgbBytes
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1099
     ditherRGBBytes ditherColors
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1100
     w       "{Class: SmallInteger }"
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1101
     h       "{Class: SmallInteger }"
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1102
     index   "{Class: SmallInteger }"
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1103
     ditherIds failed lastColor qScramble
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1104
     clrLookup lookupPos
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1105
     error clr|
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1106
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1107
    "/
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1108
    "/ collect color components as integer values (for integer arithmetic)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1109
    "/
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1110
    rgbBytes := ByteArray uninitializedNew:256 * 3.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1111
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1112
    photometric == #palette ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1113
	lastColor := colorMap size - 1
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1114
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1115
	lastColor := 255.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1116
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1117
    index := 1.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1118
    0 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1119
	clr := self colorFromValue:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1120
	rgbBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1121
	rgbBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1122
	rgbBytes at:index+2 put:(clr blueByte).
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1123
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1124
	index := index + 3.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1125
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1126
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1127
    "/ collect valid ditherColors ...
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1128
    aMapOrNil isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1129
	ditherColors := colors select:[:clr | clr notNil].
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1130
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1131
	ditherColors := colors
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1132
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1133
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1134
    "/ ... and sort by manhatten distance from black
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1135
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1136
    qScramble := #(
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1137
		"/  2rX00X00X00X00
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1138
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1139
		    2r000000000000    "/ 0
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1140
		    2r000000000100    "/ 1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1141
		    2r000000100000    "/ 2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1142
		    2r000000100100    "/ 3
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1143
		    2r000100000000    "/ 4
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1144
		    2r000100000100    "/ 5
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1145
		    2r000100100000    "/ 6
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1146
		    2r000100100100    "/ 7
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1147
		    2r100000000000    "/ 8
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1148
		    2r100000000100    "/ 9
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1149
		    2r100000100000    "/ a
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1150
		    2r100000100100    "/ b
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1151
		    2r100100000000    "/ c
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1152
		    2r100100000100    "/ d
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1153
		    2r100100100000    "/ e
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1154
		    2r100100100100    "/ f
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1155
		  ).
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1156
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1157
    ditherColors := ditherColors sort:[:a :b |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1158
				|cr "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1159
				 cg "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1160
				 cb "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1161
				 i1 "{Class: SmallInteger }"
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1162
				 i2 "{Class: SmallInteger }"|
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1163
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1164
				cr := a redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1165
				cg := a greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1166
				cb := a blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1167
				i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1168
				i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1169
				i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1170
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1171
				cr := b redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1172
				cg := b greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1173
				cb := b blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1174
				i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1175
				i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1176
				i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1177
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1178
				i1 < i2
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1179
		    ].
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1180
    aMapOrNil isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1181
	ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1182
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1183
	ditherIds := aMapOrNil asByteArray
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1184
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1185
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1186
    "/ build an index table, for fast lookup from manhatten-r-g-b distance
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1187
    "/ to the position in the colorList
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1188
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1189
    clrLookup := ByteArray new:(4096).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1190
    index := 0.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1191
    ditherColors keysAndValuesDo:[:clrPosition :clr |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1192
	|r g b i|
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1193
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1194
	r := clr redByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1195
	g := clr greenByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1196
	b := clr blueByte.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1197
	i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1198
	i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1199
	i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1200
	lookupPos := i.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1201
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1202
	[index < lookupPos] whileTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1203
	    clrLookup at:(index+1) put:(clrPosition-1-1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1204
	    index := index + 1
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1205
	]
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1206
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1207
    clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1208
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1209
"/    [index <= (4095)] whileTrue:[
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1210
"/        clrLookup at:(index+1) put:(ditherColors size - 1).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1211
"/        index := index + 1.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1212
"/    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1213
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1214
    "/ collect ditherColor components
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1215
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1216
    lastColor := ditherColors size.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1217
    ditherIds := ByteArray uninitializedNew:lastColor.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1218
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1219
    index := 1.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1220
    1 to:lastColor do:[:pix |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1221
	clr := ditherColors at:pix.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1222
	ditherRGBBytes at:index put:(clr redByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1223
	ditherRGBBytes at:index+1 put:(clr greenByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1224
	ditherRGBBytes at:index+2 put:(clr blueByte).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1225
	aMapOrNil isNil ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1226
	    ditherIds at:pix put:clr colorId.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1227
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1228
	    ditherIds at:pix put:(aMapOrNil at:pix).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1229
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1230
	index := index + 3.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1231
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1232
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1233
    pseudoBits := ByteArray uninitializedNew:(width * height).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1234
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1235
    w := width + 2.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1236
    error := ByteArray uninitializedNew:w*(3*2).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1237
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1238
    w := width.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1239
    h := height.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1240
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1241
    failed := true.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1242
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1243
%{
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1244
    int __x, __y;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1245
    int __eR, __eG, __eB;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1246
    unsigned char *srcP, *dstP;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1247
    unsigned char *rgbP;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1248
    unsigned char *idP;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1249
    unsigned char *dp;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1250
    unsigned char *__clrLookup;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1251
    short *errP, *eP;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1252
    int __fR, __fG, __fB;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1253
    int iR, iG, iB;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1254
    int idx;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1255
    int __w = __intVal(w);
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1256
    int __h = __intVal(h);
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1257
    int __nColors = __intVal(lastColor);
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1258
    int __wR = -1, __wG, __wB;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1259
    static int __qScramble[16] = {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1260
		    0x000 /* 2r000000000000    0 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1261
		    0x004 /* 2r000000000100    1 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1262
		    0x020 /* 2r000000100000    2 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1263
		    0x024 /* 2r000000100100    3 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1264
		    0x100 /* 2r000100000000    4 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1265
		    0x104 /* 2r000100000100    5 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1266
		    0x120 /* 2r000100100000    6 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1267
		    0x124 /* 2r000100100100    7 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1268
		    0x800 /* 2r100000000000    8 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1269
		    0x804 /* 2r100000000100    9 */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1270
		    0x820 /* 2r100000100000    a */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1271
		    0x824 /* 2r100000100100    b */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1272
		    0x900 /* 2r100100000000    c */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1273
		    0x904 /* 2r100100000100    d */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1274
		    0x920 /* 2r100100100000    e */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1275
		    0x924 /* 2r100100100100    f */,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1276
		  };
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1277
5472
5508a0ac6319 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5453
diff changeset
  1278
    if (__isByteArrayLike(__INST(bytes))
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1279
     && __isByteArray(pseudoBits)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1280
     && __isByteArray(rgbBytes)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1281
     && __isByteArray(ditherRGBBytes)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1282
     && __isByteArray(ditherIds)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1283
     && __isByteArray(clrLookup)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1284
     && __isByteArray(error)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1285
	failed = false;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1286
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1287
	srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1288
	dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1289
	rgbP = __ByteArrayInstPtr(rgbBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1290
	idP = __ByteArrayInstPtr(ditherIds)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1291
	__clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1292
	errP = (short *) __ByteArrayInstPtr(error)->ba_element;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1293
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1294
	/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1295
	 * clear error accumulator
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1296
	 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1297
	eP = errP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1298
	bzero(eP, (__w+2) * 2 * 3);
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1299
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1300
	for (__y=__h; __y>0; __y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1301
	    __eR = __eG = __eB = 0;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1302
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1303
	    eP = &(errP[3]);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1304
	    __eR = eP[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1305
	    __eG = eP[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1306
	    __eB = eP[2];
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1307
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1308
	    for (__x=__w; __x>0; __x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1309
		int __want;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1310
		int pix;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1311
		int __wantR, __wantG, __wantB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1312
		int idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1313
		int tR, tG, tB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1314
		int nR, nG, nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1315
		int dR, dG, dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1316
		int minDelta, bestIdx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1317
		int cnt;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1318
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1319
		pix = *srcP++;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1320
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1321
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1322
		 * wR, wG and wB is the wanted r/g/b value;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1323
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1324
		idx = pix+pix+pix;  /* pix * 3 */
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1325
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1326
		__wantR = rgbP[idx] + __eR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1327
		__wantG = rgbP[idx+1] + __eG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1328
		__wantB = rgbP[idx+2] + __eB;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1329
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1330
#define RED_SCALE 30
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1331
#define GREEN_SCALE 59
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1332
#define BLUE_SCALE 11
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1333
#define GOOD_DELTA 30
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1334
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1335
#define xRED_SCALE 1
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1336
#define xGREEN_SCALE 1
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1337
#define xBLUE_SCALE 1
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1338
#define xGOOD_DELTA 3
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1339
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1340
#define FAST_LOOKUP
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1341
/* #define ONE_SHOT */
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1342
#define NPROBE 8
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1343
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1344
#ifndef FAST_LOOKUP
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1345
		if ((__wantR == __wR)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1346
		 && (__wantG == __wG)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1347
		 && (__wantB == __wB)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1348
		    /*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1349
		     * same color again - reuse last bestMatch
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1350
		     */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1351
		} else
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1352
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1353
		{
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1354
		    __wR = __wantR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1355
		    __wG = __wantG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1356
		    __wB = __wantB;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1357
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1358
#ifdef FAST_LOOKUP
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1359
		    if(__wR > 255) __wR = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1360
		    else if (__wR < 0) __wR = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1361
		    if(__wG > 255) __wG = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1362
		    else if (__wG < 0) __wG = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1363
		    if(__wB > 255) __wB = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1364
		    else if (__wB < 0) __wB = 0;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1365
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1366
		    {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1367
			int lookupIndex;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1368
			int idx, idx0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1369
			int d, delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1370
			unsigned char *dp0;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1371
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1372
			dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1373
			lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1374
			lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1375
			lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1376
			idx = bestIdx =__clrLookup[lookupIndex];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1377
			dp += (idx+idx+idx);
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1378
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1379
			/* try color at lookupIndex */
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1380
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1381
			d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1382
			delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1383
			if (delta < 0) delta = -delta;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1384
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1385
			d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1386
			if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1387
			    delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1388
			else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1389
			    delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1390
			d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1391
			if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1392
			    delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1393
			else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1394
			    delta += (d - __wB) * BLUE_SCALE;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1395
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1396
			if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1397
			    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1398
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1399
			minDelta = delta;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1400
# ifndef ONE_SHOT
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1401
			idx0 = idx; dp0 = dp;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1402
			cnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1403
			while ((++cnt <= NPROBE) && (idx > 0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1404
			    /* try previous color(s) */
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1405
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1406
			    idx--; dp -= 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1407
			    d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1408
			    delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1409
			    if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1410
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1411
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1412
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1413
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1414
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1415
			    d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1416
			    if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1417
				delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1418
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1419
				delta += (d - __wB) * BLUE_SCALE;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1420
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1421
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1422
				bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1423
				if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1424
				    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1425
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1426
				minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1427
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1428
			}
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1429
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1430
			idx = idx0; dp = dp0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1431
			cnt = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1432
			while ((++cnt <= NPROBE) && (++idx < __nColors)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1433
			    /* try next color */
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1434
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1435
			    dp += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1436
			    d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1437
			    delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1438
			    if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1439
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1440
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1441
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1442
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1443
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1444
			    d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1445
			    if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1446
				delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1447
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1448
				delta += (d - __wB) * BLUE_SCALE;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1449
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1450
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1451
				bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1452
				if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1453
				    goto foundBest;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1454
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1455
				minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1456
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1457
			}
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1458
# endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1459
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1460
	foundBest: ;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1461
#else
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1462
/*
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1463
		    if(__wR > 255) __wR = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1464
		    else if (__wR < 0) __wR = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1465
		    if(__wG > 255) __wG = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1466
		    else if (__wG < 0) __wG = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1467
		    if(__wB > 255) __wB = 255;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1468
		    else if (__wB < 0) __wB = 0;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1469
*/
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1470
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1471
		    /* find the best matching color */
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1472
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1473
		    minDelta = 99999;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1474
		    bestIdx = -1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1475
		    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1476
		    for (idx = 0; idx<__nColors; idx++) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1477
			int d, delta;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1478
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1479
			d = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1480
			delta = (__wR - d) * RED_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1481
			if (delta < 0) delta = -delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1482
			if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1483
			    d = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1484
			    if (__wG > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1485
				delta += (__wG - d) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1486
			    else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1487
				delta += (d - __wG) * GREEN_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1488
			    if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1489
				d = dp[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1490
				if (__wB > d)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1491
				    delta += (__wB - d) * BLUE_SCALE;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1492
				else
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1493
				    delta += (d - __wB) * BLUE_SCALE;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1494
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1495
				if (delta < minDelta) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1496
				    bestIdx = idx;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1497
				    if (delta <= GOOD_DELTA) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1498
					break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1499
				    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1500
				    minDelta = delta;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1501
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1502
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1503
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1504
			dp += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1505
		    }
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1506
#endif
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1507
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1508
		dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1509
		dp += bestIdx * 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1510
		dR = dp[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1511
		dG = dp[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1512
		dB = dp[2];
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1513
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1514
/*
4724
f7db00bce050 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4718
diff changeset
  1515
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1516
		__wantR, __wantG, __wantB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1517
		__wR, __wG, __wB,
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1518
		dR, dG, dB);
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1519
*/
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1520
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1521
		 * store the corresponding dither colors colorId
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1522
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1523
		*dstP++ = idP[bestIdx];
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1524
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1525
		/*
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1526
		 * the new error & distribute the error
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1527
		 */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1528
		__eR = __wantR - dR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1529
		if (__eR) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1530
		    tR = __eR >> 4;  /* 16th of error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1531
		    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1532
		    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1533
		    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1534
		    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1535
		    __eR = nR;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1536
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1537
		    __eR = eP[3];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1538
		    eP[0] = eP[-3] = eP[3] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1539
		}
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1540
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1541
		__eG = __wantG - dG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1542
		if (__eG) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1543
		    tG = __eG >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1544
		    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1545
		    eP[1] = tG*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1546
		    eP[-2] = tG*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1547
		    eP[4] = __eG - (tG*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1548
		    __eG = nG;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1549
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1550
		    __eG = eP[4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1551
		    eP[1] = eP[-2] = eP[4] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1552
		}
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1553
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1554
		__eB = __wantB - dB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1555
		if (__eB) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1556
		    tB = __eB >> 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1557
		    nB = eP[5] + (tB * 7);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1558
		    eP[2] = tB*5;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1559
		    eP[-1] = tB*3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1560
		    eP[5] = __eB - (tB*15);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1561
		    __eB = nB;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1562
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1563
		    __eB = eP[5];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1564
		    eP[2] = eP[-1] = eP[5] = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1565
		}
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1566
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1567
		eP += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1568
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1569
	}
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1570
    }
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1571
%}.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1572
    failed ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1573
	self primitiveFailed.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  1574
	^ nil
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1575
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1576
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1577
    ^ pseudoBits
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1578
!
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3900
diff changeset
  1579
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1658
diff changeset
  1580
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1581
    "return the bitmap for a dithered depth-bitmap from the image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1582
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1583
     Redefined to make use of knowing that pixels are 8-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1584
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1585
    |dH nDither bytes
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1586
     greyLevels greyMap1 greyMap2
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1587
     bytesPerRow  "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1588
     bytesPerOutRow  "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1589
     pixelsPerByte   "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1590
     outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1591
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1592
     h               "{Class: SmallInteger }" |
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1593
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1594
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1595
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1596
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1597
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1598
    h := height.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1599
    bytes := self bits.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1600
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1601
    greyLevels := 1 bitShift:depth.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1602
    pixelsPerByte := 8 / depth.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1603
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1604
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1605
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1606
    bytesPerOutRow := (w * depth + 7) // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1607
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1608
    (outBits isNil or:[bytes isNil]) ifTrue:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1609
	^ nil
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1610
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1611
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1612
    greyMap1 := self greyMapForRange:(greyLevels-1).                    "/ the pixels
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1613
    greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1614
					    0
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1615
					] ifFalse:[
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1616
					    b truncated
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1617
					]
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1618
				  ]) asByteArray.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1619
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1620
    greyMap2 := self greyMapForRange:(greyLevels-1).
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1621
    greyMap2 := (greyMap2 collect:[:el |
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1622
					el isNil ifTrue:[
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1623
					    0
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1624
					] ifFalse:[
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1625
					    ((el - el truncated)  "/ the error (0..1)
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1626
					    * nDither) rounded
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1627
					]]) asByteArray.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1628
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1629
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1630
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1631
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1632
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1633
    int __dT, __dO;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1634
    int __depth = __intVal(depth);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1635
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1636
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1637
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1638
    int __grey, __pixel;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1639
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1640
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1641
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1642
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1643
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1644
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1645
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1646
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1647
    int __bytesPerOutRow = __intVal(bytesPerOutRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1648
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1649
    unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1650
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1651
    unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1652
    unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1653
    unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1654
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1655
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1656
    for (__y=0; __y<__h; __y++) {
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1657
	__nextDst = __dstIdx + __bytesPerOutRow;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1658
	__nextSrc = __srcIdx + __bytesPerRow;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1659
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1660
	__byte = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1661
	__bitCnt = 8;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1662
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1663
	__oX = 0;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1664
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1665
	for (__x=0; __x<__w; __x++) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1666
	    __grey = __bytes[__srcIdx++];            /* 0..255 */
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1667
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1668
	    __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1669
	    __dO    = __greyMap2[__grey];            /* 0.. nDither-1) */
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1670
	    __dT = __ditherMatrix[__dY + __oX];
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1671
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1672
	    if (__dO > __dT)                         /* dither says: next pixel */
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1673
		__pixel++;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1674
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1675
	    __oX++;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1676
	    if (__oX == __dW) __oX = 0;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1677
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1678
	    __byte = (__byte << __depth) | __pixel;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1679
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1680
	    __bitCnt = __bitCnt - __depth;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1681
	    if (__bitCnt == 0) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1682
		__outBits[__dstIdx] = __byte;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1683
		__dstIdx++;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1684
		__byte = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1685
		__bitCnt = 8;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1686
	    }
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1687
	}
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1688
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1689
	if (__bitCnt != 8) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1690
	    __byte = __byte << __bitCnt;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1691
	    __outBits[__dstIdx] = __byte;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1692
	}
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1693
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1694
	__oY++; __dY += __dW;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1695
	if (__oY == __dH) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1696
	    __oY = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1697
	    __dY = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1698
	}
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1699
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1700
	__srcIdx = __nextSrc;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1701
	__dstIdx = __nextDst;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1702
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1703
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1704
    ^ outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1705
!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1706
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1707
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1708
    "return the dithered monochrome bits for the receiver image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1709
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1710
     Redefined to make use of knowing that pixels are 8-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1711
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1712
    |dH nDither bytes
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1713
     greyMap monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1714
     bytesPerMonoRow "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1715
     bytesPerRow     "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1716
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1717
     h               "{Class: SmallInteger }"|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1718
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1719
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1720
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1721
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1722
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1723
    h := height.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1724
    bytes := self bits.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1725
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1726
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1727
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1728
    bytesPerMonoRow := w + 7 // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1729
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1730
    (monoBits isNil or:[bytes isNil]) ifTrue:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1731
	^ nil
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1732
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1733
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1734
    greyMap := self greyByteMapForRange:nDither.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1735
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1736
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1737
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1738
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1739
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1740
    int __dT;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1741
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1742
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1743
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1744
    int __grey;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1745
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1746
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1747
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1748
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1749
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1750
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1751
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1752
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1753
    int __bytesPerMonoRow = __intVal(bytesPerMonoRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1754
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1755
    unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1756
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1757
    unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1758
    unsigned char *__greyMap = __ByteArrayInstPtr(greyMap)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1759
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1760
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1761
    for (__y=0; __y<__h; __y++) {
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1762
	__nextDst = __dstIdx + __bytesPerMonoRow;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1763
	__nextSrc = __srcIdx + __bytesPerRow;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1764
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1765
	__byte = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1766
	__bitCnt = 8;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1767
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1768
	__oX = 0;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1769
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1770
	for (__x=__w; __x>0; __x--) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1771
	    __grey = __bytes[__srcIdx];   /* 0..255 */
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1772
	    __srcIdx++;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1773
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1774
	    __grey = __greyMap[__grey];
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1775
	    __dT = __ditherMatrix[__dY + __oX];
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1776
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1777
	    __oX++;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1778
	    if (__oX == __dW) __oX = 0;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1779
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1780
	    __byte = __byte << 1;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1781
	    if (__grey > __dT) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1782
		__byte = __byte | 1;           /* white */
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1783
	    }
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1784
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1785
	    __bitCnt--;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1786
	    if (__bitCnt == 0) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1787
		__monoBits[__dstIdx] = __byte;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1788
		__dstIdx++;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1789
		__byte = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1790
		__bitCnt = 8;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1791
	    }
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1792
	}
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1793
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1794
	if (__bitCnt != 8) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1795
	    __byte = __byte << __bitCnt;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1796
	    __monoBits[__dstIdx] = __byte;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1797
	}
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1798
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1799
	__oY++; __dY += __dW;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1800
	if (__oY == __dH) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1801
	    __oY = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1802
	    __dY = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1803
	}
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1804
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1805
	__srcIdx = __nextSrc;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1806
	__dstIdx = __nextDst;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1807
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1808
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1809
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1810
    ^ monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1811
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1812
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1813
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1814
1609
42e9d60aaca9 comments
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
  1815
     i := Image fromFile:'bitmaps/gifImages/claus.gif'.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1816
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1817
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1818
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1819
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1820
1609
42e9d60aaca9 comments
Claus Gittinger <cg@exept.de>
parents: 1604
diff changeset
  1821
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1822
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1823
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1824
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1825
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1826
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1827
     i := (Image fromFile:'bitmaps/PasteButton.tiff') magnifiedBy:10.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1828
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1829
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1830
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1831
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1832
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1833
     i := (Image fromFile:'bitmaps/blue-ball.gif') magnifiedBy:1.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1834
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1835
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1836
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1837
    "Created: 7.6.1996 / 10:48:06 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1838
    "Modified: 7.6.1996 / 11:08:50 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1839
! !
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1840
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1841
!Depth8Image methodsFor:'enumerating'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1842
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1843
colorsAtY:y from:xLow to:xHigh do:aBlock
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1844
    "perform aBlock for each pixel from x1 to x2 in row y.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1845
     The block is passed the color at each pixel.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1846
     This method allows slighly faster processing of an
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1847
     image than using atX:y:, since some processing can be
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1848
     avoided when going from pixel to pixel. However, for
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1849
     real image processing, specialized methods should be written."
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1850
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1851
    |srcIndex "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1852
     value    "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1853
     x1       "{ Class: SmallInteger }"
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1854
     x2       "{ Class: SmallInteger }"
7322
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1855
     color cachedColorArray pixelBytes lastValue lastColor|
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1856
7322
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1857
    pixelBytes := self bits.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1858
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1859
    x1 := xLow.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1860
    x2 := xHigh.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1861
    srcIndex := (width * y) + 1 + x1.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1862
7322
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1863
    cachedColorArray := Array new:256.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1864
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1865
    x1 to:x2 do:[:x |
7322
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1866
        value := pixelBytes at:srcIndex.
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1867
        srcIndex := srcIndex + 1.
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1868
        
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1869
        value == lastValue ifTrue:[
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1870
            color := lastColor
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1871
        ] ifFalse:[    
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1872
            color := cachedColorArray at:value+1.
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1873
            color isNil ifTrue:[
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1874
                color := self colorFromValue:value.
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1875
                cachedColorArray at:value+1 put:color
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1876
            ].
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1877
            lastValue := value. lastColor := color.
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1878
        ].
051a91207011 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7276
diff changeset
  1879
        aBlock value:x value:color
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1880
    ]
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1881
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1882
    "Created: 7.6.1996 / 19:12:35 / cg"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1883
    "Modified: 11.7.1996 / 20:22:32 / cg"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1884
!
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1885
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1886
colorsFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1887
    "perform aBlock for each pixel in the rectangle
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1888
     yStart..yEnd / xStart..xEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1889
     The block is passed the color at each pixel.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1890
     This method allows slighly faster processing of an
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1891
     image than using individual atX:y: accesses,
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1892
     both since some processing can be avoided when going from pixel to pixel,
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1893
     and since the color composition is done outside of the pixel loop.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1894
     However, for real high performance image processing, specialized methods
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1895
     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
  1896
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1897
    |srcIndex    "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1898
     srcNext     "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1899
     bytesPerRow "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1900
     value    "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1901
     x1       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1902
     x2       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1903
     y1       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1904
     y2       "{ Class: SmallInteger }"
2248
20fc22184ef5 care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents: 2202
diff changeset
  1905
     colorArray
7323
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1906
     maxColor pixelBytes lastPixel lastColor|
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1907
7323
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1908
    pixelBytes := self bits.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1909
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1910
    x1 := xStart.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1911
    x2 := xEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1912
    y1 := yStart.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1913
    y2 := yEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1914
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1915
    srcIndex := (width * y1) + x1 + 1 .
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1916
    bytesPerRow := self bytesPerRow.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1917
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1918
    colorArray := self realColorMap.
2248
20fc22184ef5 care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents: 2202
diff changeset
  1919
    maxColor := colorArray size.
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1920
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1921
    y1 to:y2 do:[:y |
7323
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1922
        srcNext := srcIndex + bytesPerRow.
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1923
        x1 to:x2 do:[:x |
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1924
            value := pixelBytes at:srcIndex ifAbsent:0.
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1925
            srcIndex := srcIndex + 1.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1926
7323
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1927
            value ~~ lastPixel ifTrue:[
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1928
                lastPixel := value.
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1929
                value >= maxColor ifTrue:[
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1930
                    value := 0.
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1931
                ].
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1932
                lastColor := colorArray at:value+1.
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1933
            ].
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1934
            aBlock value:x value:y value:lastColor
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1935
        ].
42cd85aec8ea #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7322
diff changeset
  1936
        srcIndex := srcNext.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1937
    ].
746
f5479d603f64 gray vs. grey
Claus Gittinger <cg@exept.de>
parents: 694
diff changeset
  1938
2248
20fc22184ef5 care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents: 2202
diff changeset
  1939
    "Created: / 7.6.1996 / 19:12:35 / cg"
20fc22184ef5 care for invalid pixel values in image
Claus Gittinger <cg@exept.de>
parents: 2202
diff changeset
  1940
    "Modified: / 17.8.1998 / 10:17:45 / cg"
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1941
!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1942
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1943
valuesAtY:y from:xLow to:xHigh do:aBlock
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1944
    "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
  1945
     The block is passed the pixelValue at each pixel.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1946
     This method allows slighly faster processing of an
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1947
     image than using valueAtX:y:, since some processing can be
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1948
     avoided when going from pixel to pixel. However, for
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1949
     real image processing, specialized methods should be written."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1950
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1951
    |srcIndex   "{ Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1952
     pixelValue "{ Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1953
     x1         "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1954
     x2         "{ Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1955
     bytes|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1956
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1957
    x1 := xLow.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1958
    x2 := xHigh.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1959
    srcIndex := (width * y) + 1 + x1.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1960
    bytes := self bits.
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1961
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1962
    x1 to:x2 do:[:x |
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1963
	pixelValue := bytes at:srcIndex.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1964
	srcIndex := srcIndex + 1.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1965
	aBlock value:x value:pixelValue
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  1966
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1967
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1968
    "Created: 7.6.1996 / 19:09:47 / cg"
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1969
!
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1970
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1971
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1972
    "perform aBlock for each pixel in the rectangle
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1973
     yStart..yEnd / xStart..xEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1974
     The block is passed the pixelValue at each pixel.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1975
     This method allows slighly faster processing of an
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1976
     image than using individual valueAtX:y: accesses,
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1977
     since some processing can be avoided when going from pixel to pixel..
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  1978
     However, for real high performance image processing, specialized methods
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1979
     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
  1980
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1981
    |srcIndex    "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1982
     srcNext     "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1983
     bytesPerRow "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1984
     value    "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1985
     x1       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1986
     x2       "{ Class: SmallInteger }"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1987
     y1       "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1988
     y2       "{ Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1989
     bytes|
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1990
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1991
    x1 := xStart.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1992
    x2 := xEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1993
    y1 := yStart.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1994
    y2 := yEnd.
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1995
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1996
    srcIndex := (width * y1) + x1 + 1 .
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1997
    bytesPerRow := self bytesPerRow.
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1998
    bytes := self bits.
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  1999
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  2000
    y1 to:y2 do:[:y |
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2001
	srcNext := srcIndex + bytesPerRow.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2002
	x1 to:x2 do:[:x |
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2003
	    value := bytes at:srcIndex.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2004
	    srcIndex := srcIndex + 1.
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  2005
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2006
	    aBlock value:x value:y value:value
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2007
	].
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2008
	srcIndex := srcNext.
941
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  2009
    ].
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  2010
    ^ self
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  2011
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  2012
    "Modified: 11.7.1996 / 20:06:47 / cg"
11fb72fb105c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  2013
    "Created: 11.7.1996 / 20:08:11 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2014
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
  2015
12
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
  2016
!Depth8Image methodsFor:'image manipulations'!
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
  2017
7533
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2018
easyRotateBitsInto:destinationImage angle:degrees
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2019
    "tuned helper for rotation - does the actual pixel shuffling, by degrees clockwise. 
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2020
     Here, only 90, 180 and 270 degrees are implemented. 
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2021
     Hard angles are done in #hardRotate:.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2022
     The code here a tuned version of the inherited for more performance"
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2023
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2024
    |srcBytesPerRow dstBytesPerRow
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2025
     srcWidth srcHeight
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2026
     dstWidth dstHeight
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2027
     srcBytes dstBytes|
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2028
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2029
    srcBytesPerRow := self bytesPerRow.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2030
    srcBytes := self bits.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2031
    srcWidth := width.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2032
    srcHeight := height.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2033
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2034
    dstBytesPerRow := destinationImage bytesPerRow.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2035
    dstBytes := destinationImage bits.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2036
    dstWidth := destinationImage width.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2037
    dstHeight := destinationImage height.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2038
%{
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2039
    if (__bothSmallInteger(srcWidth, srcHeight)
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2040
     && __bothSmallInteger(dstWidth, dstHeight)
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2041
     && __bothSmallInteger(dstBytesPerRow, srcBytesPerRow)
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2042
     && __isByteArrayLike(srcBytes)
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2043
     && __isByteArrayLike(dstBytes)
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2044
    ) {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2045
        int c_srcW = __intVal(srcWidth);
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2046
        int c_srcH = __intVal(srcHeight);
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2047
        int c_dstW = __intVal(dstWidth);
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2048
        int c_dstH = __intVal(dstHeight);
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2049
        int c_srcBytesPerRow = __intVal(srcBytesPerRow);
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2050
        int c_dstBytesPerRow = __intVal(dstBytesPerRow);
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2051
        int c_srcW4 = c_srcW-4;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2052
        
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2053
        {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2054
            unsigned char *c_srcBytes = (unsigned char*)__ByteArrayInstPtr(srcBytes)->ba_element;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2055
            unsigned char *c_dstBytes = (unsigned char*)__ByteArrayInstPtr(dstBytes)->ba_element;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2056
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2057
            int c_dstNextRowOffset;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2058
            int c_dstNextColOffset;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2059
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2060
            if (degrees == __mkSmallInteger(90)) {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2061
                // destinationImage pixelAtX:(h-row) y:col put:pixel
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2062
                c_dstNextRowOffset = -1;                                // going to previous column
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2063
                c_dstNextColOffset = c_dstBytesPerRow;                  // going to next row
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2064
                c_dstBytes += (c_dstW-1);                               // start in the upper-right of dest
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2065
            } else if (degrees == __mkSmallInteger(180)) {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2066
                // destinationImage pixelAtX:(w-col) y:(h-row) put:pixel
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2067
                c_dstNextRowOffset = -c_dstBytesPerRow;                 // going to previous row
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2068
                c_dstNextColOffset = -1;                                // going to prev col
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2069
                c_dstBytes += (c_dstH-1)*c_dstBytesPerRow+(c_dstW-1);   // start in the lower-right of dest
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2070
            } else {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2071
                // destinationImage pixelAtX:row y:(w-col) put:pixel
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2072
                c_dstNextRowOffset = 1;                                 // going to next col
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2073
                c_dstNextColOffset = -c_dstBytesPerRow;                 // going to prev row
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2074
                c_dstBytes += (c_dstH-1)*c_dstBytesPerRow;              // start in the lower-left of dest
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2075
            }
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2076
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2077
            if ((c_srcBytesPerRow * c_srcH) <= __byteArraySize(srcBytes)) {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2078
                int c_y;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2079
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2080
                for (c_y=0; c_y<c_srcH; c_y++) {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2081
                    unsigned char *c_srcNext = c_srcBytes + c_srcBytesPerRow;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2082
                    unsigned char *c_dstNext = c_dstBytes + c_dstNextRowOffset;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2083
                    int c_x;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2084
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2085
                    c_x = 0;    
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2086
#if 1
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2087
                    if (sizeof(int) == 4) {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2088
                        for (c_x = 0; c_x < c_srcW4; c_x += 4) {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2089
                            int c_value;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2090
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2091
                            c_value = ((int *)c_srcBytes)[0];
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2092
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2093
                            c_dstBytes[0] = (c_value) & 0xFF;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2094
                            c_dstBytes += c_dstNextColOffset;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2095
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2096
                            c_dstBytes[0] = (c_value>>8) & 0xFF;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2097
                            c_dstBytes += c_dstNextColOffset;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2098
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2099
                            c_dstBytes[0] = (c_value>>16) & 0xFF;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2100
                            c_dstBytes += c_dstNextColOffset;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2101
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2102
                            c_dstBytes[0] = (c_value>>24) & 0xFF;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2103
                            c_dstBytes += c_dstNextColOffset;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2104
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2105
                            c_srcBytes += 4;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2106
                        }
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2107
                    }
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2108
#endif
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2109
                    for (; c_x < c_srcW; c_x++) {
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2110
                        int c_value;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2111
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2112
                        c_value = c_srcBytes[0];
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2113
                        c_dstBytes[0] = c_value;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2114
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2115
                        c_srcBytes++;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2116
                        c_dstBytes += c_dstNextColOffset;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2117
                    }
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2118
                    c_srcBytes = c_srcNext;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2119
                    c_dstBytes = c_dstNext;
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2120
                }
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2121
                RETURN(self);
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2122
            }
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2123
        }
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2124
    }
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2125
%}.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2126
    self breakPoint:#cg.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2127
    super easyRotateBitsInto:destinationImage angle:degrees
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2128
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2129
    "
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2130
     |i|
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2131
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2132
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2133
     i inspect.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2134
     (i rotated:45) inspect.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2135
     (i rotated:90) inspect.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2136
     (i rotated:180) inspect.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2137
     (i rotated:270) inspect.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2138
    "
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2139
    "
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2140
     |i|
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2141
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2142
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2143
     Time millisecondsToRun:[
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2144
        1000 timesRepeat:[ (i rotated:90) ].
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2145
     ]
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2146
    "
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2147
!
514d5a9f46af #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7524
diff changeset
  2148
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2149
hardMagnifiedBy:scalePoint
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2150
    "return a new image magnified by scalePoint, aPoint.
12
9f0995fac1fa *** empty log message ***
claus
parents: 5
diff changeset
  2151
     This is the general magnification method, handling non-integral values"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2152
304f026e10cd Initial revision
claus
parents:
diff changeset
  2153
    |mX mY
304f026e10cd Initial revision
claus
parents:
diff changeset
  2154
     newWidth  "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2155
     newHeight "{ Class: SmallInteger }"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2156
     w         "{ Class: SmallInteger }"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2157
     h         "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2158
     newImage newBytes
304f026e10cd Initial revision
claus
parents:
diff changeset
  2159
     value     "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2160
     srcRowIdx "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2161
     srcIndex  "{ Class: SmallInteger }"
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2162
     dstIndex  "{ Class: SmallInteger }"
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2163
     newMask|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2164
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2165
    mX := scalePoint x.
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2166
    mY := scalePoint y.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2167
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
  2168
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
304f026e10cd Initial revision
claus
parents:
diff changeset
  2169
304f026e10cd Initial revision
claus
parents:
diff changeset
  2170
    newWidth := (width * mX) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2171
    newHeight := (height * mY) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2172
304f026e10cd Initial revision
claus
parents:
diff changeset
  2173
    newBytes := ByteArray uninitializedNew:(newWidth * newHeight).
304f026e10cd Initial revision
claus
parents:
diff changeset
  2174
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2175
    mask notNil ifTrue:[
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  2176
	newMask := (mask magnifiedBy:scalePoint)
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2177
    ].
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1569
diff changeset
  2178
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2179
    newImage := self species new.
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2180
    newImage
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2181
	width:newWidth
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2182
	height:newHeight
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2183
	photometric:photometric
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2184
	samplesPerPixel:samplesPerPixel
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2185
	bitsPerSample:#(8)
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  2186
	colorMap:colorMap copy
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  2187
	bits:newBytes
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  2188
	mask:newMask.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2189
304f026e10cd Initial revision
claus
parents:
diff changeset
  2190
    "walk over destination image fetching pixels from source image"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2191
304f026e10cd Initial revision
claus
parents:
diff changeset
  2192
    mY := mY asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2193
    mX := mX asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2194
%{
2042
58c0228331bb single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents: 2006
diff changeset
  2195
    unsigned char *__dstP = __ByteArrayInstPtr(newBytes)->ba_element;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2196
    unsigned char *__srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  2197
    unsigned char *__srcRowP;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2198
    int __width = __intVal(__INST(width));
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  2199
    int __w = __intVal(newWidth) - 1;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  2200
    int __h = __intVal(newHeight) - 1;
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  2201
    int __row, __col;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2202
    double __mX = __floatVal(mX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2203
    double __mY = __floatVal(mY);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2204
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  2205
    for (__row = 0; __row <= __h; __row++) {
2786
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  2206
	__srcRowP = __srcP + (__width * (int)((double)__row / __mY));
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  2207
	for (__col = 0; __col <= __w; __col++) {
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  2208
	    *__dstP++ = __srcRowP[(int)((double)__col / __mX)];
a6a053ee4c76 oops - image bug fix for hpux (MSB but __MSBFIRST not defined)
Claus Gittinger <cg@exept.de>
parents: 2774
diff changeset
  2209
	}
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2210
    }
304f026e10cd Initial revision
claus
parents:
diff changeset
  2211
%}
304f026e10cd Initial revision
claus
parents:
diff changeset
  2212
.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2213
"/   the above C-code is equivalent to:
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2214
"/
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2215
"/    dstIndex := 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2216
"/    w := newWidth - 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2217
"/    h := newHeight - 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2218
"/    0 to:h do:[:row |
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2219
"/        srcRowIdx := (width * (row // mY)) + 1.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2220
"/        0 to:w do:[:col |
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2221
"/            srcIndex := srcRowIdx + (col // mX).
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2222
"/            value := bytes at:srcIndex.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2223
"/            newBytes at:dstIndex put:value.
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2224
"/            dstIndex := dstIndex + 1
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2225
"/        ]
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2226
"/    ].
ea2bf46eb669 *** empty log message ***
claus
parents: 86
diff changeset
  2227
"/
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2228
304f026e10cd Initial revision
claus
parents:
diff changeset
  2229
    ^ newImage
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2230
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2231
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2232
magnifyRowFrom:srcBytes offset:srcStart
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2233
	  into:dstBytes offset:dstStart factor:mX
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2234
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2235
    "magnify a single pixel row - can only magnify by integer factors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2236
     Specially tuned for factors 2,3 and 4."
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2237
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2238
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2239
    REGISTER unsigned char *srcP, *dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2240
    REGISTER unsigned char _byte;
2184
b8daa402967f tuned magnification by multiples-of-2
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2241
    unsigned _word;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2242
    int _mag;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2243
    REGISTER int i;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2244
    int _pixels;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2245
    OBJ w = __INST(width);
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2246
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2247
    if (__bothSmallInteger(srcStart, dstStart)
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2248
     && __bothSmallInteger(w, mX)
5472
5508a0ac6319 __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5453
diff changeset
  2249
     && __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2250
	_mag = __intVal(mX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2251
	srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2252
	dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2253
	_pixels = __intVal(w);
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2254
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2255
	switch (_mag) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2256
	    case 1:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2257
		break;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2258
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2259
	    case 2:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2260
		/* special code for common case */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2261
		if (((INT)dstP & 1) == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2262
		    while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2263
			_byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2264
			_word = (_byte<<8) | _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2265
			((short *)dstP)[0] = _word;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2266
			dstP += 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2267
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2268
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2269
		    while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2270
			_byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2271
			*dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2272
			*dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2273
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2274
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2275
		break;
2184
b8daa402967f tuned magnification by multiples-of-2
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  2276
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2277
	    case 3:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2278
		/* special code for common case */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2279
		while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2280
		    _byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2281
		    *dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2282
		    *dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2283
		    *dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2284
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2285
		break;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2286
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2287
	    case 4:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2288
		/* special code for common case */
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2289
		if (((INT)dstP & 3) == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2290
		    while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2291
			_byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2292
			_word = (_byte<<8) | _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2293
			_word = (_word<<16) | _word;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2294
			((int *)dstP)[0] = _word;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2295
			dstP += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2296
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2297
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2298
		    while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2299
			_byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2300
			*dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2301
			*dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2302
			*dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2303
			*dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2304
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2305
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2306
		break;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2307
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2308
	    default:
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2309
		if ((((INT)dstP & 1) == 0)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2310
		 && ((_mag & 1) == 0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2311
		    while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2312
			_byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2313
			_word = (_byte<<8) | _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2314
			for (i=_mag; i>0; i-=2) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2315
			    ((short *)dstP)[0] = _word;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2316
			    dstP += 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2317
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2318
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2319
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2320
		    while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2321
			_byte = *srcP++;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2322
			for (i=_mag; i>0; i--)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2323
			    *dstP++ = _byte;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2324
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2325
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2326
		break;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2327
	}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2328
	RETURN (self);
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2329
    }
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3600
diff changeset
  2330
%}.
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2331
    super
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2332
	magnifyRowFrom:srcBytes offset:srcStart
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2333
	into:dstBytes offset:dstStart factor:mX
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2334
! !
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2335
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2336
!Depth8Image methodsFor:'private'!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2337
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2338
dither1PlaneUsingMap:map on:aDevice
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2339
    "a helper for dithering palette and greyscale images"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2340
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2341
    |f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2342
     patterns formBytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2343
     pixel0bytes pixel1bytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2344
     clr ditherPattern
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2345
     nColors       "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2346
     w             "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2347
     h             "{Class: SmallInteger }"|
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2348
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2349
    nColors := map size.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2350
    w := width.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2351
    h := height.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2352
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2353
    formBytes := ByteArray uninitializedNew:(w + 7 // 8) * h.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2354
    patterns := Array new:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2355
    pixel0bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2356
    pixel1bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2357
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2358
    "
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2359
     extract dither patterns and values to use for 1/0 bits
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2360
     in those from the dithercolors
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2361
    "
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2362
    1 to:nColors do:[:i |
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2363
	clr := (map at:i) onDevice:aDevice.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2364
	ditherPattern := clr ditherForm.
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2365
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2366
	ditherPattern isNil ifTrue:[
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2367
	    patterns at:i put:#[2r11111111
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2368
				2r11111111
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2369
				2r11111111
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2370
				2r11111111
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2371
				2r11111111
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2372
				2r11111111
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2373
				2r11111111
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2374
				2r11111111].
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2375
	    pixel0bytes at:i put:clr colorId.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2376
	    pixel1bytes at:i put:clr colorId
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2377
	] ifFalse:[
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2378
	    patterns at:i put:(ditherPattern bits).
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2379
	    pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2380
	    pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2381
	].
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2382
    ].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2383
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2384
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2385
    unsigned char *_srcP, *_dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2386
    OBJ _patternBytes;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  2387
    unsigned char __mask = 0x80;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2388
    unsigned char _outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2389
    unsigned char _last, _v, _patternBits, _p0, _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2390
    int _h, _w;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2391
    int _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2392
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2393
    _srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
2042
58c0228331bb single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents: 2006
diff changeset
  2394
    _dstP = __ByteArrayInstPtr(formBytes)->ba_element;
2044
9ea84b4ba249 more single-underline macros
Claus Gittinger <cg@exept.de>
parents: 2042
diff changeset
  2395
    for (_h = __intVal(h); _h; _h--) {
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2396
	_last = -1;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2397
	for (_w = __intVal(w); _w; _w--) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2398
	    _v = *_srcP++;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2399
	    if (_v != _last) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2400
		_patternBytes = __ArrayInstPtr(patterns)->a_element[_v];
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2401
		if (__isByteArray(_patternBytes)) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2402
		    _patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2403
		} else if (__isArrayLike(_patternBytes)) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2404
		    _patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2405
		}
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2406
		_p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2407
		_p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2408
		_last = _v;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2409
	    }
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2410
	    _outBits <<= 1;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2411
	    if (_patternBits & __mask)
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2412
		_outBits |= _p1;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2413
	    else
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2414
		_outBits |= _p0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2415
	    __mask >>= 1;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2416
	    if (__mask == 0) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2417
		__mask = 0x80;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2418
		*_dstP++ = _outBits;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2419
		_outBits = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2420
	    }
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2421
	}
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2422
	if (__mask != 0x80) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2423
	    while (__mask != 0) {
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2424
		_outBits <<= 1;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2425
		__mask >>= 1;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2426
	    }
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2427
	    *_dstP++ = _outBits;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2428
	    __mask = 0x80;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2429
	    _outBits = 0;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2430
	}
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2431
	_patternOffset++;
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2432
	if (_patternOffset == 8)
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2433
	    _patternOffset = 0;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2434
    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2435
%}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2436
.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2437
    f := Form width:w height:h fromArray:formBytes.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2438
    ^ f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2439
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2440
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2441
dither2PlaneUsingMap:map on:aDevice
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2442
    "a helper for dithering palette and greyscale images"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2443
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2444
    |f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2445
     patterns formBytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2446
     pixel0bytes pixel1bytes
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2447
     clr ditherPattern
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2448
     nColors       "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2449
     w             "{Class: SmallInteger }"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2450
     h             "{Class: SmallInteger }"|
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2451
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2452
    nColors := map size.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2453
    w := width.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2454
    h := height.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2455
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2456
    formBytes := ByteArray uninitializedNew:(w * 2 + 7 // 8) * h.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2457
    patterns := Array new:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2458
    pixel0bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2459
    pixel1bytes := ByteArray uninitializedNew:nColors.
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2460
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2461
    "extract dither patterns and values to use for 1/0 bits
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2462
     in those from the dithercolors"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2463
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2464
    1 to:nColors do:[:i |
6837
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2465
        clr := (map at:i) onDevice:aDevice.
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2466
        ditherPattern := clr ditherForm.
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2467
6837
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2468
        ditherPattern isNil ifTrue:[
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2469
            patterns at:i put:#[2r11111111
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2470
                                2r11111111
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2471
                                2r11111111
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2472
                                2r11111111
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2473
                                2r11111111
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2474
                                2r11111111
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2475
                                2r11111111
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2476
                                2r11111111].
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2477
            pixel0bytes at:i put:clr colorId.
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2478
            pixel1bytes at:i put:clr colorId
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2479
        ] ifFalse:[
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2480
            patterns at:i put:(ditherPattern bits).
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2481
            pixel0bytes at:i put:(ditherPattern colorMap at:1) colorId.
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2482
            pixel1bytes at:i put:(ditherPattern colorMap at:2) colorId.
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2483
        ].
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2484
    ].
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2485
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2486
%{
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2487
    unsigned char *_srcP, *_dstP;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2488
    OBJ _patternBytes;
1658
4c81124d0b37 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
  2489
    unsigned char __mask = 0x80;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2490
    unsigned char _outBits = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2491
    unsigned char _last, _v, _patternBits, _p0, _p1;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2492
    int _h, _w;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2493
    int _patternOffset = 0;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2494
    int _outCount;
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2495
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6039
diff changeset
  2496
    _srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
2042
58c0228331bb single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents: 2006
diff changeset
  2497
    _dstP = __ByteArrayInstPtr(formBytes)->ba_element;
2044
9ea84b4ba249 more single-underline macros
Claus Gittinger <cg@exept.de>
parents: 2042
diff changeset
  2498
    for (_h = __intVal(h); _h; _h--) {
6837
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2499
        _last = -1;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2500
        _outCount = 0;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2501
        for (_w = __intVal(w); _w; _w--) {
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2502
            _v = *_srcP++;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2503
            if (_v != _last) {
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2504
                _patternBytes = __ArrayInstPtr(patterns)->a_element[_v];
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2505
                if (__isByteArray(_patternBytes)) {
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2506
                    _patternBits = __ByteArrayInstPtr(_patternBytes)->ba_element[_patternOffset];
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2507
                } else if (__isArrayLike(_patternBytes)) {
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2508
                    _patternBits = __intVal(__ArrayInstPtr(_patternBytes)->a_element[_patternOffset]);
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2509
                }
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2510
                _p0 = __ByteArrayInstPtr(pixel0bytes)->ba_element[_v];
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2511
                _p1 = __ByteArrayInstPtr(pixel1bytes)->ba_element[_v];
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2512
                _last = _v;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2513
            }
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2514
            _outBits <<= 2;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2515
            if (_patternBits & __mask)
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2516
                _outBits |= _p1;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2517
            else
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2518
                _outBits |= _p0;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2519
            __mask >>= 1;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2520
            _outCount++;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2521
            if (_outCount == 4) {
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2522
                *_dstP++ = _outBits;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2523
                _outCount = 0;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2524
                if (__mask == 0) {
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2525
                    __mask = 0x80;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2526
                }
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2527
            }
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2528
        }
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2529
        if (_outCount) {
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2530
            do {
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2531
                _outBits <<= 2;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2532
            } while (++_outCount != 4);
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2533
            *_dstP++ = _outBits;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2534
        }
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2535
        __mask = 0x80;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2536
        _outBits = 0;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2537
        _patternOffset++;
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2538
        if (_patternOffset == 8)
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2539
            _patternOffset = 0;
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2540
    }
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2541
%}
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2542
.
6837
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2543
    f := Form width:w height:h depth:2 onDevice:aDevice.
7361
ebd5415005b8 #QUALITY by sr
sr
parents: 7323
diff changeset
  2544
    f isNil ifTrue:[^ nil].
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2545
    f initGC.
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2546
    f graphicsDevice
6837
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2547
        drawBits:formBytes
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2548
        depth:2
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2549
        padding:8
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2550
        width:w height:h
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2551
        x:0 y:0
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2552
        into:f id
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2553
        x:0 y:0
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2554
        width:w height:h
e511316c0ed9 class: Depth8Image
Claus Gittinger <cg@exept.de>
parents: 6310
diff changeset
  2555
        with:f gcId.
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2556
    ^ f
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2557
! !
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2558
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2559
!Depth8Image methodsFor:'queries'!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2560
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2561
bitsPerPixel
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2562
    "return the number of bits per pixel"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2563
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2564
    ^ 8
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2565
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2566
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2567
bitsPerRow
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2568
    "return the number of bits in one scanline of the image"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2569
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  2570
    ^ width * 8
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2571
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2572
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2573
bytesPerRow
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2574
    "return the number of bytes in one scanline of the image"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2575
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2576
    ^ width
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2577
!
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2578
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2579
colorFromValue:pixelValue
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2580
    "given a pixel value, return the corresponding color.
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2581
     Pixel values start with 0."
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2582
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2583
    photometric == #whiteIs0 ifTrue:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2584
	^ Color gray:100 - (100 / 255 * pixelValue)
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2585
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2586
    photometric == #blackIs0 ifTrue:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2587
	^ Color gray:(100 / 255 * pixelValue)
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2588
    ].
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2589
    photometric == #palette ifTrue:[
4718
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2590
	pixelValue < colorMap size ifTrue:[
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2591
	    ^ colorMap at:(pixelValue + 1)
11e89d5330e7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4405
diff changeset
  2592
	]
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2593
    ].
3869
cd40d1912c03 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
  2594
    ^ super colorFromValue:pixelValue
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2595
!
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2596
7597
5abdbcd771e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7533
diff changeset
  2597
nColorsUsed
5abdbcd771e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7533
diff changeset
  2598
    ^ colorMap size
5abdbcd771e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7533
diff changeset
  2599
!
5abdbcd771e5 #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7533
diff changeset
  2600
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  2601
realUsedValues
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  2602
    "return a collection of color values used in the receiver."
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  2603
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2604
    ^ self bits usedValues
3273
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  2605
!
f4cb380e0ae9 usedValues vs. realUsedValues
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  2606
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2607
usedValues
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2608
    "return a collection of color values used in the receiver."
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2609
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2610
    ^ self bits usedValues
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2611
! !
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2612
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 941
diff changeset
  2613
!Depth8Image class methodsFor:'documentation'!
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2614
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2615
version
7276
3af688594d98 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 6837
diff changeset
  2616
    ^ '$Header$'
5371
8825c8866613 changed: #colorsFromX:y:toX:y:do:
Claus Gittinger <cg@exept.de>
parents: 5331
diff changeset
  2617
!
8825c8866613 changed: #colorsFromX:y:toX:y:do:
Claus Gittinger <cg@exept.de>
parents: 5331
diff changeset
  2618
8825c8866613 changed: #colorsFromX:y:toX:y:do:
Claus Gittinger <cg@exept.de>
parents: 5331
diff changeset
  2619
version_CVS
7276
3af688594d98 #QUALITY by cg
Claus Gittinger <cg@exept.de>
parents: 6837
diff changeset
  2620
    ^ '$Header$'
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
  2621
! !
6036
d1969789036e Refactoring:
Stefan Vogel <sv@exept.de>
parents: 5851
diff changeset
  2622