Depth24Image.st
author Stefan Vogel <sv@exept.de>
Tue, 28 Apr 2020 15:28:14 +0200
changeset 9038 dd177fea6408
parent 8967 0a8df312e486
permissions -rw-r--r--
#REFACTORING by stefan class: Font changed: #setFamily:face:style:size:sizeUnit:encoding:device:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     1
"
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
81
4ba554473294 *** empty log message ***
claus
parents: 66
diff changeset
     3
	      All Rights Reserved
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     4
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     5
 This software is furnished under a license and may be used
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     6
 only in accordance with the terms of that license and with the
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     8
 be provided or otherwise made available to, or used by, any
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
     9
 other person.  No title to or ownership of the software is
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    10
 hereby transferred.
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    11
"
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
    12
"{ Package: 'stx:libview' }"
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
    13
6795
f945a03cf2ac class: Depth24Image
Claus Gittinger <cg@exept.de>
parents: 6301
diff changeset
    14
"{ NameSpace: Smalltalk }"
f945a03cf2ac class: Depth24Image
Claus Gittinger <cg@exept.de>
parents: 6301
diff changeset
    15
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    16
Image subclass:#Depth24Image
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    17
	instanceVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    18
	classVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    19
	poolDictionaries:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    20
	category:'Graphics-Images'
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    21
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    22
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
    23
!Depth24Image class methodsFor:'documentation'!
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    24
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    25
copyright
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    26
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    27
 COPYRIGHT (c) 1993 by Claus Gittinger
81
4ba554473294 *** empty log message ***
claus
parents: 66
diff changeset
    28
	      All Rights Reserved
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    29
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    30
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    31
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    33
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    34
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    35
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    36
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    37
!
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    38
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    39
documentation
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    40
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    41
    this class represents true-color (24 bit / pixel) images.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    42
    It mainly consists of methods already implemented in Image,
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    43
    reimplemented here for more performance.
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    44
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
    45
    Only the #rgb format is supported here.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
    46
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    47
    with #rgb, pixels are internally stored byte-wise in rgb order
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    48
    (i.e. r at low byte, b at high byte).
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    49
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    50
    When reading pixel values, these are returned as rrggbb,
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    51
    both on LSB and on MSB machines.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    52
    (red in high bits of the returned 24bit integer)
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    53
    Thus, pixelValues and rgbValues are identical, simulating MSB on all
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    54
    architectures (this should be transparent, if you use the rgbValueAt
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    55
    accessors; however, some old code uses pixelValueAt:, assuming that the
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    56
    returned pixel value is rrggbb (which it would not be without this hack).
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    57
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    58
    [author:]
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    59
        Claus Gittinger
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    60
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    61
    [see also:]
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    62
        Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    63
        ImageReader
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    64
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    65
! !
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    66
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
    67
!Depth24Image class methodsFor:'queries'!
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    68
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    69
defaultPhotometric
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    70
    "return the default photometric pixel interpretation"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    71
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    72
    ^ #rgb
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    73
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    74
    "Created: 10.6.1996 / 18:08:25 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    75
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    76
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    77
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    78
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    79
     this class - here we return 24"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    80
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    81
    ^ 24
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    82
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    83
    "Modified: 20.4.1996 / 23:39:50 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    84
! !
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    85
3263
bd92a12c9316 category changes
Claus Gittinger <cg@exept.de>
parents: 2835
diff changeset
    86
!Depth24Image methodsFor:'accessing-pixels'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    87
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
    88
colorAtX:x y:y
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    89
    "retrieve a pixel at x/y; return a color.
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
    90
     Pixels start at x=0 , y=0 for upper left pixel,
7125
f37b7e5d26df #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
    91
     end at x = width-1, y=height-1 for lower right pixel"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    92
7550
b38f65fc5d21 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7549
diff changeset
    93
    |rgbVal|
b38f65fc5d21 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7549
diff changeset
    94
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    95
    rgbVal := self rgbValueAtX:x y:y.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
    96
    ^ Color rgbValue:rgbVal.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    97
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    98
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
    99
colorAtX:x y:y put:aColor
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   100
    "set the pixel at x/y to aColor.
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   101
     Pixels start at x=0 , y=0 for upper left pixel, end at
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   102
     x = width-1, y=height-1 for lower right pixel."
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   103
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   104
    self rgbValueAtX:x y:y put:(aColor rgbValue).
8155
5da09f4eaf56 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8133
diff changeset
   105
5da09f4eaf56 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8133
diff changeset
   106
    "Created: / 24-04-1997 / 17:32:59 / cg"
5da09f4eaf56 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8133
diff changeset
   107
    "Modified (format): / 31-08-2017 / 12:01:01 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   108
!
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   109
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   110
pixelAtX:x y:y
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   111
    "retrieve a pixel at x/y; 
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   112
     return a pixel value (0..16rFFFFFF) which is 24 bits RGB.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   113
     In theory, the interpretation of the pixel value depends on the photometric,
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   114
     however as the only one supported here is #rgb, the returned value
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   115
     is always rrggbb (with r in high bits, b in low 8 bits).
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   116
     Pixels start at x=0 , y=0 for upper left pixel, end at
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   117
     x = width-1, y=height-1 for lower right pixel."
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   118
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   119
    |index "{ Class: SmallInteger }"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   120
     rVal  "{ Class: SmallInteger }"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   121
     gVal  "{ Class: SmallInteger }"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   122
     bVal  "{ Class: SmallInteger }"|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   123
7273
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   124
%{  /* NOCONTEXT */
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   125
    OBJ b = __INST(bytes);
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   126
    OBJ w = __INST(width);
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   127
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   128
    if (__isByteArrayLike(b)
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   129
     && __bothSmallInteger(x, y)
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   130
     && __isSmallInteger(w)
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   131
     && (__INST(pixelFunction)==nil) ) {
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   132
        int _idx;
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   133
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   134
        _idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*3;
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   135
        if (((unsigned)(_idx+2)) < __byteArraySize(b)) {
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   136
            unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]);
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   137
            unsigned int _pix;
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   138
            _pix = (pPix[0]<<16) + (pPix[1] << 8) + pPix[2];
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   139
            RETURN( __MKSMALLINT(_pix) );
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   140
        }
7273
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   141
    }
894274c8169d #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7125
diff changeset
   142
%}.
6301
6eae8309c982 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   143
    pixelFunction notNil ifTrue:[^ pixelFunction value:x value:y].
6eae8309c982 pixelfunction support
Claus Gittinger <cg@exept.de>
parents: 6066
diff changeset
   144
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   145
    index := 1 + (((width * y) + x) * 3).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   146
    rVal := bytes at:(index).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   147
    gVal := bytes at:(index + 1).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   148
    bVal := bytes at:(index + 2).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   149
    ^ (((rVal bitShift:8) bitOr:gVal) bitShift:8) bitOr:bVal
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   150
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   151
    "Created: 24.4.1997 / 16:06:34 / cg"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   152
!
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   153
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   154
pixelAtX:x y:y put:aPixelValue
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   155
    "set a pixel at x/y to aPixelValue, (0..16rFFFFFF) which is 24 bits RGB.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   156
     In theory, the interpretation of the pixel value depends on the photometric,
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   157
     however as the only one supported here is #rgb, the expected value
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   158
     is always rrggbb (with r in high bits, b in low 8 bits).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   159
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
   160
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
   161
304f026e10cd Initial revision
claus
parents:
diff changeset
   162
    |index "{ Class: SmallInteger }"
7512
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   163
     val   "{ Class: SmallInteger }"|
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   164
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   165
%{  /* NOCONTEXT */
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   166
    OBJ b = __INST(bytes);
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   167
    OBJ w = __INST(width);
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   168
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   169
    if (__isByteArrayLike(b)
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   170
     && __bothSmallInteger(x, y)
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   171
     && __bothSmallInteger(w, aPixelValue)
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   172
     && (__INST(pixelFunction)==nil) ) {
8197
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   173
        int _idx;
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   174
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   175
        _idx = ((__intVal(w) * __intVal(y)) + __intVal(x))*3;
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   176
        if (((unsigned)(_idx+2)) < __byteArraySize(b)) {
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   177
            unsigned char *pPix = &(__ByteArrayInstPtr(b)->ba_element[_idx]);
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   178
            unsigned int _pix = __intVal(aPixelValue);
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   179
            pPix[0] = (_pix>>16) & 0xFF;    // r
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   180
            pPix[1] = (_pix>>8) & 0xFF;     // g 
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   181
            pPix[2] = (_pix) & 0xFF;        // b 
8197
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   182
            RETURN( self );
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   183
        }
7512
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   184
    }
f094e73e5bf8 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7495
diff changeset
   185
%}.
8197
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   186
    bytes isNil ifTrue:[ self createPixelStore ].
ac41cb09e3f6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8170
diff changeset
   187
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   188
    index := 1 + (((width * y) + x) * 3).
304f026e10cd Initial revision
claus
parents:
diff changeset
   189
    val := aPixelValue.
304f026e10cd Initial revision
claus
parents:
diff changeset
   190
    bytes at:(index + 2) put:(val bitAnd:16rFF).
304f026e10cd Initial revision
claus
parents:
diff changeset
   191
    val := val bitShift:-8.
304f026e10cd Initial revision
claus
parents:
diff changeset
   192
    bytes at:(index + 1) put:(val bitAnd:16rFF).
304f026e10cd Initial revision
claus
parents:
diff changeset
   193
    val := val bitShift:-8.
304f026e10cd Initial revision
claus
parents:
diff changeset
   194
    bytes at:(index) put:val.
304f026e10cd Initial revision
claus
parents:
diff changeset
   195
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   196
4118
Claus Gittinger <cg@exept.de>
parents: 3907
diff changeset
   197
rgbValueAtX:x y:y
8121
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
   198
    "retrieve a pixel's rgb value at x/y; 
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
   199
     return a 24bit rgbValue (rrggbb, red is MSB).
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
   200
     Pixels start at 0@0 for the upper left pixel, 
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
   201
     and end at (width-1)@(height-1) for the lower right pixel."
4118
Claus Gittinger <cg@exept.de>
parents: 3907
diff changeset
   202
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   203
    photometric == #rgb ifTrue:[
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   204
        ^ self pixelAtX:x y:y
8170
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   205
    ].
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   206
    ^ super rgbValueAtX:x y:y
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   207
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   208
    "Modified: / 10-09-2017 / 16:21:25 / cg"
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   209
!
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   210
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   211
rgbValueAtX:x y:y put:rgbValue
8170
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   212
    "store a pixel's rgb value at x/y; 
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   213
     return a 24bit rgbValue (rrggbb, red is MSB).
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   214
     Pixels start at 0@0 for the upper left pixel, 
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   215
     and end at (width-1)@(height-1) for the lower right pixel."
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   216
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   217
    photometric == #rgb ifTrue:[
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   218
        self pixelAtX:x y:y put:rgbValue
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   219
    ] ifFalse:[
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   220
        super rgbValueAtX:x y:y put:rgbValue
8170
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   221
    ].
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   222
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   223
    "Created: / 10-09-2017 / 16:21:50 / cg"
4118
Claus Gittinger <cg@exept.de>
parents: 3907
diff changeset
   224
!
Claus Gittinger <cg@exept.de>
parents: 3907
diff changeset
   225
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
   226
rowAt:y putAll:pixelArray startingAt:startIndex
8170
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   227
    "store a single row's bits from bits in the pixelArray argument;
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   228
     The interpretation of the pixel values depends on the photometric.
3872
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
   229
     Return the pixelArray.
390fabbc3036 comments and slight cleanup
Claus Gittinger <cg@exept.de>
parents: 3868
diff changeset
   230
     Notice: row coordinate starts at 0."
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   231
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   232
    |bytes dstIdx pixel|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   233
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   234
    photometric == #rgb ifTrue:[
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   235
        bytes := self bits.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   236
        dstIdx := (y * self bytesPerRow) + 1.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   237
        0 to:width-1 do:[:col |
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   238
            pixel := pixelArray at:(startIndex + col).
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   239
            "/ msbFirst
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   240
            bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   241
            bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   242
            bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   243
            dstIdx := dstIdx + 3.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   244
        ].
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   245
        ^ self
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   246
    ].
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
   247
    super rowAt:y putAll:pixelArray startingAt:startIndex.
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   248
8170
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   249
    "Created: / 24-04-1997 / 15:50:27 / cg"
baac5c2583e6 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8155
diff changeset
   250
    "Modified (comment): / 10-09-2017 / 16:22:39 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   251
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
   252
304f026e10cd Initial revision
claus
parents:
diff changeset
   253
!Depth24Image methodsFor:'converting rgb images'!
304f026e10cd Initial revision
claus
parents:
diff changeset
   254
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   255
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   256
    "return a grey form from the receiver.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   257
     Redefined to use special code when converting to 8-bit
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   258
     greyScale displays."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   259
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   260
    (aDevice visualType == #StaticGray) ifTrue:[
8098
489f84d2fc13 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8090
diff changeset
   261
        aDevice depth == 8 ifTrue:[
489f84d2fc13 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8090
diff changeset
   262
            ^ self 
489f84d2fc13 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8090
diff changeset
   263
                makeDeviceGrayPixmapOn:aDevice depth:aDevice depth 
489f84d2fc13 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8090
diff changeset
   264
                fromArray:(self threshold8BitGrayBits)
489f84d2fc13 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8090
diff changeset
   265
        ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   266
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   267
    ^ super asGrayFormOn:aDevice
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   268
8098
489f84d2fc13 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8090
diff changeset
   269
    "Created: / 10-06-1996 / 19:00:45 / cg"
489f84d2fc13 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8090
diff changeset
   270
    "Modified: / 10-06-1996 / 20:10:19 / cg"
489f84d2fc13 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 8090
diff changeset
   271
    "Modified (format): / 24-08-2017 / 15:18:31 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   272
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   273
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   274
asThresholdGrayImageDepth:depth
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   275
    "return an 8-bit grey image from the rgb picture.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   276
     Pixel values are reduced to a 0..255 grey level."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   277
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   278
    depth == 8 ifTrue:[
8127
826558a642a9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8121
diff changeset
   279
        photometric == #rgb ifTrue:[
826558a642a9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8121
diff changeset
   280
            ^ (Depth8Image
826558a642a9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8121
diff changeset
   281
                width:width height:height fromArray:(self threshold8BitGrayBits))
826558a642a9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8121
diff changeset
   282
                photometric:#blackIs0    
826558a642a9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8121
diff changeset
   283
        ]
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   284
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   285
    ^ super asThresholdGrayImageDepth:depth
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   286
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   287
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   288
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   289
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   290
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   291
     (i asThresholdGrayImageDepth:8) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   292
     (i asThresholdGrayImageDepth:4) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   293
     (i asThresholdGrayImageDepth:2) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   294
     (i asThresholdGrayImageDepth:1) inspect.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   295
    "
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   296
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   297
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   298
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   299
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   300
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   301
     ((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:2) inspect
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   302
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   303
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   304
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   305
     |i|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   306
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   307
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   308
     ((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:4) inspect
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   309
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   310
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   311
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   312
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   313
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   314
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   315
     (i asThresholdGrayImageDepth:8) asOrderedDitheredMonochromeImage inspect
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   316
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   317
8127
826558a642a9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8121
diff changeset
   318
    "Created: / 08-06-1996 / 13:58:46 / cg"
826558a642a9 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8121
diff changeset
   319
    "Modified: / 29-08-2017 / 22:28:55 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   320
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   321
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   322
rgbImageAsDitheredPseudoFormOn:aDevice
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   323
    "return a dithered pseudocolor form from the rgb-picture.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   324
     This method depends on fixColors being allocated (see Color>>getColors*)"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   325
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   326
    |ditherColors|
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   327
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   328
    (ditherColors := aDevice fixColors) notNil ifTrue:[
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
   329
	^ self
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
   330
		rgbImageAsDitheredPseudoFormOn:aDevice
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
   331
		colors:ditherColors
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
   332
		nRed:aDevice numFixRed
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
   333
		nGreen:aDevice numFixGreen
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
   334
		nBlue:aDevice numFixBlue
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   335
    ].
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   336
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   337
    ditherColors := Set new.
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   338
    ditherColors addAll:(aDevice ditherColors).
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   339
    ditherColors addAll:(aDevice deviceColors).
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   340
    ditherColors := ditherColors asArray.
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
   341
    ^ self
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
   342
	rgbImageAsDitheredPseudoFormOn:aDevice
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
   343
	colors:ditherColors.
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   344
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   345
    "Modified: 22.4.1997 / 11:59:44 / cg"
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   346
!
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   347
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   348
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   349
    "return a dithered 8-bit pseudocolor form from the rgb-picture, using
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   350
     arbitrary fix colors in fixColors."
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   351
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   352
    |pseudoBits f
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   353
     h        "{ Class: SmallInteger }"
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   354
     w        "{ Class: SmallInteger }"
4778
799620f24088 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4760
diff changeset
   355
     numFix   "{Class: SmallInteger }" deviceDepth
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   356
     fixIds fixRed fixGreen fixBlue failed cache idsUsed usedColors
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   357
     fixColorArray|
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   358
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   359
    numFix := fixColors size.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   360
    numFix == 256 ifTrue:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   361
        "/ algorithm below only handles 255 colors.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   362
        numFix := 255.
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   363
    ].
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   364
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   365
    fixColorArray := fixColors asArray.
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   366
    fixIds := (fixColorArray collect:[:clr | clr colorId]) asByteArray.
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   367
2773
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   368
    fixRed := (fixColorArray collect:[:clr | clr redByte]) asByteArray.
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   369
    fixGreen := (fixColorArray collect:[:clr | clr greenByte]) asByteArray.
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   370
    fixBlue := (fixColorArray collect:[:clr | clr blueByte]) asByteArray.
8aefa2576a50 a few more smallInteger type hints
Claus Gittinger <cg@exept.de>
parents: 2535
diff changeset
   371
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   372
    cache := ByteArray new:(1 bitShift:14).
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   373
    cache atAllPut:16rFF.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   374
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   375
    deviceDepth := aDevice depth.
2529
637a5979a3d0 use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2401
diff changeset
   376
    deviceDepth == 8 ifFalse:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   377
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   378
            ^ nil
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   379
        ]
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   380
    ].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   381
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   382
    idsUsed := ByteArray new:(fixIds size).
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   383
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   384
    'Depth24Image [info]: dithering ...' infoPrintCR.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   385
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   386
    pseudoBits := ByteArray uninitializedNew:(width * height).
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   387
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   388
    h := height.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   389
    w := width.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   390
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   391
%{
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   392
    int __x, __y, __numFix;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   393
    int __eR, __eG, __eB;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   394
    unsigned char *srcP, *dstP;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   395
    int pix;
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   396
    unsigned char *idP, *usedIdP, *redP, *greenP, *blueP, *cacheP;
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   397
    int __w = __intVal(w);
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   398
5480
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   399
    if (__isByteArrayLike(__INST(bytes))
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   400
     && __isSmallInteger(numFix)
5480
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   401
     && __isByteArrayLike(pseudoBits)
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   402
     && __isByteArrayLike(cache)
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   403
     && __isByteArrayLike(fixIds)
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   404
     && __isByteArrayLike(idsUsed)
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   405
     && __isByteArrayLike(fixRed)
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   406
     && __isByteArrayLike(fixGreen)
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   407
     && __isByteArrayLike(fixBlue) ) {
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   408
        failed = false;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   409
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   410
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   411
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   412
        idP = __ByteArrayInstPtr(fixIds)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   413
        usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   414
        redP = __ByteArrayInstPtr(fixRed)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   415
        greenP = __ByteArrayInstPtr(fixGreen)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   416
        blueP = __ByteArrayInstPtr(fixBlue)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   417
        cacheP = __ByteArrayInstPtr(cache)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   418
        __numFix = __intVal(numFix);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   419
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   420
        for (__y=__intVal(h); __y>0; __y--) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   421
            __eR = __eG = __eB = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   422
            for (__x=__w; __x>0; __x--) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   423
                int cacheIdx, clrIdx;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   424
                int __wantR, __wantG, __wantB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   425
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   426
                __wantR = srcP[0] + __eR;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   427
                if (__wantR > 255) __wantR = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   428
                else if (__wantR < 0) __wantR = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   429
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   430
                __wantG = srcP[1] + __eG;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   431
                if (__wantG > 255) __wantG = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   432
                else if (__wantG < 0) __wantG = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   433
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   434
                __wantB = srcP[2] + __eB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   435
                if (__wantB > 255) __wantB = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   436
                else if (__wantB < 0) __wantB = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   437
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   438
                /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   439
                 * compute cache index
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   440
                 */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   441
                cacheIdx = ((__wantR & 0xF8) >> 3);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   442
                cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   443
                cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   444
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   445
                clrIdx = cacheP[cacheIdx];
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   446
                if (clrIdx == 0xFF) {   /* invalid slot */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   447
                    unsigned minErr, minIdx;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   448
                    int i;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   449
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   450
                    /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   451
                     * must search ...
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   452
                     */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   453
                    minErr = 0x7FFFFFF; minIdx = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   454
                    for (i=0; i<__numFix; i++) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   455
                        unsigned cR, cG, cB, e;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   456
                        int eR, eG, eB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   457
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   458
                        cR = redP[i]; cG = greenP[i]; cB = blueP[i];
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   459
                        eR = cR - __wantR;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   460
                        if (eR < 0) eR = -eR;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   461
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   462
                        eG = cG - __wantG;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   463
                        if (eG < 0) eG = -eG;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   464
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   465
                        eB = cB - __wantB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   466
                        if (eB < 0) eB = -eB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   467
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   468
                        e = eR + eG + eB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   469
                        if (e < minErr) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   470
                            minErr = e;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   471
                            minIdx = i;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   472
                            if (e < 7) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   473
                                break;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   474
                            }
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   475
                        }
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   476
                    }
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   477
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   478
                    /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   479
                     * minIdx is now index into fixColors
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   480
                     */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   481
                    cacheP[cacheIdx] = clrIdx = minIdx;
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   482
/*
4721
ece6b3ce6b99 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
   483
console_fprintf(stderr, "want %d/%d/%d best: %d [%d/%d/%d]\n", __wantR, __wantG, __wantB, clrIdx, redP[clrIdx], greenP[clrIdx], blueP[clrIdx]);
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   484
*/
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   485
                }
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   486
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   487
                /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   488
                 * store the corresponding dither colorId
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   489
                 */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   490
                *dstP++ = idP[clrIdx];
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   491
                usedIdP[clrIdx] = 1;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   492
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   493
                srcP += 3;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   494
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   495
                /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   496
                 * the new error:
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   497
                 */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   498
                __eR = __wantR - redP[clrIdx];
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   499
                __eG = __wantG - greenP[clrIdx];
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   500
                __eB = __wantB - blueP[clrIdx];
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   501
            }
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   502
        }
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   503
    }
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   504
%}.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   505
    failed ifTrue:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   506
        self primitiveFailed.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   507
        ^ nil
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   508
    ].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   509
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   510
    "/ not all colors may be really in use ...
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   511
    usedColors := fixColors copy.
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   512
    idsUsed keysAndValuesDo:[:idx :flag |
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   513
        flag == 0 ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   514
            usedColors at:idx put:nil
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   515
        ]
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   516
    ].
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   517
7495
c62bd4c05a4d #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7278
diff changeset
   518
    f := Form imageForm width:width height:height depth:aDevice depth onDevice:aDevice.
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   519
    f isNil ifTrue:[^ nil].
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   520
    f colorMap:usedColors.
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
   521
    aDevice
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   522
        drawBits:pseudoBits
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   523
        bitsPerPixel:8
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   524
        depth:aDevice depth
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   525
        padding:8
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   526
        width:width height:height
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   527
        x:0 y:0
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   528
        into:(f id)
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   529
        x:0 y:0
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   530
        width:width height:height
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   531
        with:(f initGC).
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   532
    ^ f
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   533
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   534
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   535
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors nRed:nRed nGreen:nGreen nBlue:nBlue
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   536
    "return a dithered pseudocolor form from the rgb-picture,
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   537
     using colors from a colorCube for dithering."
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   538
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   539
    |pseudoBits f
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   540
     h        "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   541
     w        "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   542
"/     eR    "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   543
"/     eG    "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   544
"/     eB    "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   545
"/     wantR "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   546
"/     wantG "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   547
"/     wantB "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   548
     fixR  "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   549
     fixG  "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   550
     fixB  "{Class: SmallInteger }"
2529
637a5979a3d0 use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2401
diff changeset
   551
     deviceDepth
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   552
     fixIds idsUsed failed usedColors|
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   553
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   554
    fixR := nRed.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   555
    fixR == 0 ifTrue:[ ^ nil].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   556
    fixG := nGreen.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   557
    fixG == 0 ifTrue:[ ^ nil].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   558
    fixB := nBlue.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   559
    fixB == 0 ifTrue:[ ^ nil].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   560
    "/ simple check
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   561
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   562
        self error:'invalid color array passed'.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   563
        ^ nil
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   564
    ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   565
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   566
    idsUsed := ByteArray new:(fixIds size).
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   567
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   568
    deviceDepth := aDevice depth.
2529
637a5979a3d0 use new supportedImageFormat query from Device
Claus Gittinger <cg@exept.de>
parents: 2401
diff changeset
   569
    deviceDepth == 8 ifFalse:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   570
        (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   571
            ^ nil
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   572
        ]
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   573
    ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   574
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
   575
    'Depth24Image [info]: dithering ...' infoPrintCR.
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   576
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   577
    pseudoBits := ByteArray uninitializedNew:(width * height).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   578
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   579
    h := height.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   580
    w := width.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   581
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   582
%{
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   583
    int __x, __y;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   584
    int __eR, __eG, __eB;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   585
    int __wantR, __wantG, __wantB;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   586
    unsigned char *srcP, *dstP;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   587
    unsigned char *redP, *greenP, *blueP;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   588
    int pix;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   589
    unsigned char *idP;
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   590
    unsigned char *usedIdP;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   591
    int __fR, __fG, __fB;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   592
    int iR, iG, iB;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   593
    int idx;
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   594
    int __w = __intVal(w);
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   595
    int leftToRight;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   596
5480
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   597
    if (__isByteArrayLike(__INST(bytes))
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   598
     && __isByteArray(pseudoBits)
5480
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   599
     && __isByteArrayLike(fixIds)
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
   600
     && __isByteArrayLike(idsUsed)
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   601
     && __bothSmallInteger(fixR, fixG)
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   602
     && __isSmallInteger(fixB)) {
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   603
        failed = false;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   604
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   605
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   606
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   607
        idP = __ByteArrayInstPtr(fixIds)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   608
        usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   609
        __fR = __intVal(fixR)-1;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   610
        __fG = __intVal(fixG)-1;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   611
        __fB = __intVal(fixB)-1;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   612
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   613
        __eR = __eG = __eB = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   614
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   615
        leftToRight = 1;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   616
        for (__y=__intVal(h); __y>0; __y--) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   617
            if (leftToRight) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   618
                for (__x=__w; __x>0; __x--) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   619
                    int __want;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   620
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   621
                    /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   622
                     * wR, wG and wB is the wanted r/g/b value;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   623
                     * compute the index into the dId table ..
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   624
                     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   625
                     *
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   626
                     * bad kludge: knows how to index into FixColor table
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   627
                     */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   628
                    __wantR = __want = srcP[0] + __eR;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   629
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   630
                    if (__want > 255) __want = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   631
                    else if (__want < 0) __want = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   632
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   633
                    iR = __want * __fR / 128;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   634
                    iR = (iR / 2) + (iR & 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   635
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   636
                    __wantG = __want = srcP[1] + __eG;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   637
                    if (__want > 255) __want = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   638
                    else if (__want < 0) __want = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   639
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   640
                    iG = __want * __fG / 128;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   641
                    iG = (iG / 2) + (iG & 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   642
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   643
                    __wantB = __want = srcP[2] + __eB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   644
                    if (__want > 255) __want = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   645
                    else if (__want < 0) __want = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   646
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   647
                    iB = __want * __fB / 128;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   648
                    iB = (iB / 2) + (iB & 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   649
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   650
                    idx = iR * (__fG+1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   651
                    idx = (idx + iG) * (__fB+1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   652
                    idx = idx + iB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   653
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   654
                    /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   655
                     * store the corresponding dither colorId
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   656
                     */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   657
                    *dstP++ = idP[idx];
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   658
                    usedIdP[idx] = 1;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   659
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   660
                    srcP += 3;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   661
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   662
                    /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   663
                     * the new error:
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   664
                     */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   665
                    __eR = __wantR - (iR * 256 / __fR);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   666
                    __eG = __wantG - (iG * 256 / __fG);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   667
                    __eB = __wantB - (iB * 256 / __fB);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   668
                }
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   669
                leftToRight = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   670
            } else {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   671
                srcP += (__w*3);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   672
                dstP += __w;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   673
                for (__x=__w; __x>0; __x--) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   674
                    int __want;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   675
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   676
                    /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   677
                     * wR, wG and wB is the wanted r/g/b value;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   678
                     * compute the index into the dId table ..
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   679
                     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   680
                     *
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   681
                     * bad kludge: knows how to index into FixColor table
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   682
                     */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   683
                    srcP -= 3;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   684
                    __wantR = __want = srcP[0] + __eR;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   685
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   686
                    if (__want > 255) __want = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   687
                    else if (__want < 0) __want = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   688
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   689
                    iR = __want * __fR / 128;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   690
                    iR = (iR / 2) + (iR & 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   691
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   692
                    __wantG = __want = srcP[1] + __eG;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   693
                    if (__want > 255) __want = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   694
                    else if (__want < 0) __want = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   695
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   696
                    iG = __want * __fG / 128;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   697
                    iG = (iG / 2) + (iG & 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   698
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   699
                    __wantB = __want = srcP[2] + __eB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   700
                    if (__want > 255) __want = 255;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   701
                    else if (__want < 0) __want = 0;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   702
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   703
                    iB = __want * __fB / 128;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   704
                    iB = (iB / 2) + (iB & 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   705
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   706
                    idx = iR * (__fG+1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   707
                    idx = (idx + iG) * (__fB+1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   708
                    idx = idx + iB;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   709
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   710
                    /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   711
                     * store the corresponding dither colorId
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   712
                     */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   713
                    *--dstP = idP[idx];
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   714
                    usedIdP[idx] = 1;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   715
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   716
                    /*
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   717
                     * the new error:
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   718
                     */
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   719
                    __eR = __wantR - (iR * 256 / __fR);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   720
                    __eG = __wantG - (iG * 256 / __fG);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   721
                    __eB = __wantB - (iB * 256 / __fB);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   722
                }
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   723
                srcP += (__w*3);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   724
                dstP += __w;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   725
                leftToRight = 1;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   726
            }
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   727
        }
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   728
    }
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   729
%}.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   730
    failed ifTrue:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   731
        self primitiveFailed.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   732
        ^ nil
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   733
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   734
"/ for non-C programmers:
1218
2d7c79e5965f oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   735
"/     the above code is (roughly) equivalent to:
2d7c79e5965f oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   736
"/     (but it is just as ugly looking as the above ;-)
2d7c79e5965f oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   737
"/
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   738
"/    srcIndex := 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   739
"/    dstIndex := 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   740
"/    1 to:h do:[:y |
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   741
"/        eR := eG := eB := 0.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   742
"/        1 to:w do:[:x |
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   743
"/            |pixel "{ Class: SmallInteger }"
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
   744
"/             clr
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   745
"/             idx   "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   746
"/             iR    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   747
"/             iG    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   748
"/             iB    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   749
"/             wR    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   750
"/             wG    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   751
"/             wB    "{ Class: SmallInteger }" |
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   752
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   753
"/            wantR := ((bytes at:srcIndex) + eR). srcIndex := srcIndex + 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   754
"/            wantG := ((bytes at:srcIndex) + eG). srcIndex := srcIndex + 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   755
"/            wantB := ((bytes at:srcIndex) + eB). srcIndex := srcIndex + 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   756
"/            wR := wantR.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   757
"/            wR > 255 ifTrue:[wR := 255] ifFalse:[wR < 0 ifTrue:[wR := 0]].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   758
"/            wG := wantG.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   759
"/            wG > 255 ifTrue:[wG := 255] ifFalse:[wG < 0 ifTrue:[wG := 0]].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   760
"/            wB := wantB.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   761
"/            wB > 255 ifTrue:[wB := 255] ifFalse:[wB < 0 ifTrue:[wB := 0]].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   762
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   763
"/            iR := wR * (fixR-1) // 128.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   764
"/            iR := (iR // 2) + (iR bitAnd:1).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   765
"/            iG := wG * (fixG-1) // 128.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   766
"/            iG := (iG // 2) + (iG bitAnd:1).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   767
"/            iB := wB * (fixB-1) // 128.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   768
"/            iB := (iB // 2) + (iB bitAnd:1).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   769
"/            idx := (iR * fixR + iG) * fixB + iB + 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   770
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   771
"/            clr := fixColors at:idx.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   772
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   773
"/            eR := wantR - (clr red * 2) asInteger.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   774
"/            eG := wantG - (clr green * 2) asInteger.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   775
"/            eB := wantB - (clr blue * 2) asInteger.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   776
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   777
"/            pixel := clr colorId.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   778
"/            pseudoBits at:dstIndex put:pixel.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   779
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   780
"/            dstIndex := dstIndex + 1
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   781
"/        ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   782
    ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   783
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   784
    "/ not all colors may be really in use ...
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   785
    usedColors := fixColors copy.
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   786
    idsUsed keysAndValuesDo:[:idx :flag |
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   787
        flag == 0 ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   788
            usedColors at:idx put:nil
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   789
        ]
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   790
    ].
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   791
7495
c62bd4c05a4d #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7278
diff changeset
   792
    f := Form imageForm width:width height:height depth:aDevice depth onDevice:aDevice.
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   793
    f isNil ifTrue:[^ nil].
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   794
    f colorMap:usedColors.
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
   795
    aDevice
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   796
        drawBits:pseudoBits
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   797
        bitsPerPixel:8
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   798
        depth:aDevice depth
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   799
        padding:8
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   800
        width:width height:height
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   801
        x:0 y:0
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   802
        into:(f id)
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   803
        x:0 y:0
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   804
        width:width height:height
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   805
        with:(f initGC).
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   806
    ^ f
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   807
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   808
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   809
rgbImageAsPseudoFormOn:aDevice
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   810
    "return a pseudocolor form from the rgb-picture.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   811
     If a colorCube is used, pass the work on to the cube-dither
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   812
     code. Otherwise, allocate as many colors as possible, then
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
   813
     use those for dithering.
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   814
     Could be improved, by searching for (& allocating)
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   815
     heavily used colors and/or min-max colors first."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   816
304f026e10cd Initial revision
claus
parents:
diff changeset
   817
    |pseudoBits f
304f026e10cd Initial revision
claus
parents:
diff changeset
   818
     r        "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   819
     g        "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   820
     b        "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   821
     srcIndex "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   822
     dstIndex "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   823
     rMask    "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   824
     gMask    "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   825
     bMask    "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   826
     redArray greenArray blueArray
304f026e10cd Initial revision
claus
parents:
diff changeset
   827
     dataSize "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   828
     nColors  "{ Class: SmallInteger }"
4778
799620f24088 Change senders of obsolete messages Form>>...on: to ...onDevice:
Stefan Vogel <sv@exept.de>
parents: 4760
diff changeset
   829
     fit fitMap colors color fast
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   830
     colorIndex "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   831
     depth nColorCells deep nColorsNeeded bytes|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   832
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   833
    aDevice fixColors notNil ifTrue:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   834
        "/ no need to look for used colors - dithering anyway ...
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   835
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   836
        f := self rgbImageAsDitheredPseudoFormOn:aDevice.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   837
        f notNil ifTrue:[^ f].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   838
    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   839
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   840
    bytes := self bits.
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
   841
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   842
    "find used colors; build color-tree"
304f026e10cd Initial revision
claus
parents:
diff changeset
   843
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
   844
    fit := false.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   845
    fitMap := false.
304f026e10cd Initial revision
claus
parents:
diff changeset
   846
    depth := aDevice depth.
304f026e10cd Initial revision
claus
parents:
diff changeset
   847
    nColorCells := aDevice ncells.
304f026e10cd Initial revision
claus
parents:
diff changeset
   848
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   849
    deep := (depth > 8).
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   850
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   851
    rMask := 2r11111111.
304f026e10cd Initial revision
claus
parents:
diff changeset
   852
    gMask := 2r11111111.
304f026e10cd Initial revision
claus
parents:
diff changeset
   853
    bMask := 2r11111111.
304f026e10cd Initial revision
claus
parents:
diff changeset
   854
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
   855
    'Depth24Image [info]: allocating colors ...' infoPrintCR.
66
398cf6bfb241 *** empty log message ***
claus
parents: 54
diff changeset
   856
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   857
    [fit] whileFalse:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   858
        [fitMap] whileFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   859
            srcIndex := 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   860
            redArray := Array new:256.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   861
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   862
            "
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   863
             find used colors, build [r][g][b] 3-dimensional array
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   864
             containing true for used colors
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   865
            "
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   866
            nColors := 0.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   867
            srcIndex := 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   868
            dataSize := bytes size.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   869
            [(srcIndex < dataSize)
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   870
             and:[nColors <= nColorCells]] whileTrue:[
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   871
%{
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   872
                if (__isByteArrayLike(bytes)) {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   873
                    int sI = __intVal(srcIndex);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   874
                    unsigned char *cp = __ByteArrayInstPtr(bytes)->ba_element;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   875
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   876
                    r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   877
                    g = __MKSMALLINT((cp[sI]     & __intVal(gMask)) + 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   878
                    b = __MKSMALLINT((cp[sI + 1] & __intVal(bMask)) + 1);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   879
                    srcIndex = __MKSMALLINT(sI + 3);
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   880
                    fast = true;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   881
                } else {
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   882
                    fast = false;
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   883
                }
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   884
%}
304f026e10cd Initial revision
claus
parents:
diff changeset
   885
.
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   886
                fast ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   887
                    r := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   888
                    r := (r bitAnd:rMask) + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   889
                    srcIndex := srcIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   890
                    g := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   891
                    g := (g bitAnd:gMask) + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   892
                    srcIndex := srcIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   893
                    b := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   894
                    b := (b bitAnd:bMask) + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   895
                    srcIndex := srcIndex + 1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   896
                ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   897
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   898
                greenArray := redArray at:r.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   899
                greenArray isNil ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   900
                    greenArray := Array new:256.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   901
                    redArray at:r put:greenArray
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   902
                ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   903
                blueArray := greenArray at:g.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   904
                blueArray isNil ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   905
                    deep ifTrue:[blueArray := Array new:256]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   906
                    ifFalse:[blueArray := ByteArray new:256].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   907
                    greenArray at:g put:blueArray
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   908
                ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   909
                (blueArray at:b) == 0 ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   910
                    blueArray at:b put:1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   911
                    nColors := nColors + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   912
                    (nColors > nColorCells) ifTrue:[
1923
cdd2c4e199df if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
   913
"/                        'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR.
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   914
                        srcIndex := dataSize + 1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   915
                    ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   916
                ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   917
            ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   918
            nColorsNeeded isNil ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   919
                nColorsNeeded := nColors
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   920
            ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   921
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   922
            "again with less color bits if it does not fit colormap"
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   923
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   924
            (nColors <= nColorCells) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   925
                fitMap := true
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   926
            ] ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   927
                "/ must try again - cutting off some bits
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   928
                "/ blue bits are snipped off faster.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   929
                (bMask == 2r11111111) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   930
                    bMask := 2r11111100
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   931
                ] ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   932
                    (bMask == 2r11111100) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   933
                        bMask := 2r11110000
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   934
                    ] ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   935
                        (rMask == 2r11111111) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   936
                            rMask := 2r11111100.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   937
                            gMask := 2r11111100.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   938
                        ] ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   939
                            rMask := (rMask bitShift:1) bitAnd:2r11111111.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   940
                            gMask := (gMask bitShift:1) bitAnd:2r11111111.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   941
                            bMask := (bMask bitShift:1) bitAnd:2r11111111
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   942
                        ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   943
                    ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   944
                ].
1923
cdd2c4e199df if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
   945
"/                'Depth24Image [info]: too many colors; retry with less color resolution' infoPrintCR.
38
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
   946
"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   947
    'masks:' print. rMask print. ' ' print. gMask print. ' ' print.
304f026e10cd Initial revision
claus
parents:
diff changeset
   948
    bMask printNewline
38
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
   949
"
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   950
            ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   951
        ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   952
1923
cdd2c4e199df if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
   953
"/        'Depth24Image [info]: ' infoPrint. nColors infoPrint. ' colors used' infoPrintCR.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   954
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   955
        colors := Array new:nColors.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   956
        colorIndex := 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   957
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   958
        "
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   959
         now, we have reduced things to the number of colors
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   960
         which are theoretically supported by the devices colormap.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   961
         allocate all used colors in walking over true entries in
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   962
         the [r][g][b] table - this may still fail,
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   963
         if we run out of device colors.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   964
        "
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   965
        fit := true.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   966
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   967
        r := 0.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   968
        redArray do:[:greenArray |
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   969
            (fit and:[greenArray notNil]) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   970
                g := 0.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   971
                greenArray do:[:blueArray |
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   972
                    (fit and:[blueArray notNil]) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   973
                        b := 0.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   974
                        blueArray do:[:present |
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   975
                            |id|
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   976
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   977
                            (fit and:[present ~~ 0]) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   978
                                color := Color redByte:r
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   979
                                             greenByte:g
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   980
                                              blueByte:b.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   981
                                color := color onDevice:aDevice.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   982
                                (id := color colorId) isNil ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   983
                                    fit := false
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   984
                                ] ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   985
                                    colors at:colorIndex put:color.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   986
                                    colorIndex := colorIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   987
                                    blueArray at:(b + 1) put:id
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   988
                                ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   989
                            ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   990
                            b := b + 1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   991
                        ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   992
                    ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   993
                    g := g + 1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   994
                ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   995
            ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   996
            r := r + 1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   997
        ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   998
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
   999
        "again with less color bits if we did not get all colors"
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1000
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1001
        fit ifFalse:[
1923
cdd2c4e199df if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
  1002
"/            'Depth24Image [info]: could not allocate color(s)' infoPrintCR.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1003
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1004
            "free the allocated colors"
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1005
            colors atAllPut:nil.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1006
            "a kludge - force immediate freeing of colors"
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1007
            ObjectMemory scavenge; finalize.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1008
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1009
            "cut off one more color-bit - cut off blue first"
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1010
            (bMask == 2r11111111) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1011
                bMask := 2r11111100
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1012
            ] ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1013
                (bMask == 2r11111100) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1014
                    bMask := 2r11110000
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1015
                ] ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1016
                    (rMask == 2r11111111) ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1017
                        rMask := 2r11111100.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1018
                        gMask := 2r11111100.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1019
                    ] ifFalse:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1020
                        rMask := (rMask bitShift:1) bitAnd:2r11111111.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1021
                        gMask := (gMask bitShift:1) bitAnd:2r11111111.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1022
                        bMask := (bMask bitShift:1) bitAnd:2r11111111
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1023
                    ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1024
                ]
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1025
            ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1026
            fitMap := false.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1027
            redArray := nil
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1028
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1029
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
  1030
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
  1031
    (nColors ~~ nColorsNeeded) ifTrue:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1032
        "/ mhmh - did not get all colors ...
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1033
        "/ add existing colors and dither.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1034
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1035
        'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1036
        nColorsNeeded infoPrint. ' image colors.' infoPrintCR.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1037
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1038
        "/
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1039
        "/ dither using those we got ...
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1040
        "/
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1041
        DitherAlgorithm == #floydSteinberg ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1042
            colors := colors asNewSet.
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
  1043
"/            ditherColors := aDevice availableDitherColors.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
  1044
"/            ditherColors notNil ifTrue:[
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
  1045
"/                colors addAll:ditherColors.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
  1046
"/            ].
1923
cdd2c4e199df if device is running out of allocatable colors,
Claus Gittinger <cg@exept.de>
parents: 1818
diff changeset
  1047
"/            colors addAll:aDevice deviceColors.
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1048
            colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]).
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1049
            colors := (colors select:[:c | c colorId notNil]) asOrderedCollection.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1050
            colors size > 256 ifTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1051
                colors := colors copyTo:256
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1052
            ].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1053
            f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1054
            f notNil ifTrue:[^ f].
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1055
        ].
2535
c4a408209eda checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
  1056
    ].
c4a408209eda checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
  1057
c4a408209eda checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
  1058
    "/ the device ought to support 8-bit images ...
c4a408209eda checkin from browser
Claus Gittinger <cg@exept.de>
parents: 2529
diff changeset
  1059
    (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1060
        "/ cannot draw directly
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1061
        ^ nil
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
  1062
    ].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
  1063
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1064
    "create pseudocolor bits and translate"
304f026e10cd Initial revision
claus
parents:
diff changeset
  1065
304f026e10cd Initial revision
claus
parents:
diff changeset
  1066
    pseudoBits := ByteArray uninitializedNew:(width * height).
304f026e10cd Initial revision
claus
parents:
diff changeset
  1067
304f026e10cd Initial revision
claus
parents:
diff changeset
  1068
    srcIndex := 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
  1069
    dstIndex := 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
  1070
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
  1071
    (rMask == 2r11111111
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
  1072
     and:[gMask == 2r11111111
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
  1073
     and:[bMask == 2r11111111]]) ifTrue:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1074
        [srcIndex < dataSize] whileTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1075
            r := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1076
            srcIndex := srcIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1077
            g := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1078
            srcIndex := srcIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1079
            b := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1080
            srcIndex := srcIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1081
            greenArray := redArray at:(r + 1).
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1082
            blueArray := greenArray at:(g + 1).
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1083
            pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1084
            dstIndex := dstIndex + 1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1085
        ]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
  1086
    ] ifFalse:[
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1087
        [srcIndex < dataSize] whileTrue:[
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1088
            r := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1089
            r := r bitAnd:rMask.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1090
            srcIndex := srcIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1091
            g := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1092
            g := g bitAnd:gMask.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1093
            srcIndex := srcIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1094
            b := bytes at:srcIndex.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1095
            b := b bitAnd:bMask.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1096
            srcIndex := srcIndex + 1.
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1097
            greenArray := redArray at:(r + 1).
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1098
            blueArray := greenArray at:(g + 1).
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1099
            pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1100
            dstIndex := dstIndex + 1
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1101
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1102
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
  1103
7495
c62bd4c05a4d #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7278
diff changeset
  1104
    f := Form imageForm width:width height:height depth:depth onDevice:aDevice.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1105
    f isNil ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
  1106
    f colorMap:colors.
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  1107
    aDevice
7753
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1108
        drawBits:pseudoBits
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1109
        bitsPerPixel:8
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1110
        depth:depth
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1111
        padding:8
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1112
        width:width height:height
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1113
        x:0 y:0
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1114
        into:(f id)
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1115
        x:0 y:0
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1116
        width:width height:height
c025b6129ba7 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 7550
diff changeset
  1117
        with:(f initGC).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1118
    ^ f
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1119
!
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1120
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1121
rgbImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1122
    "return a truecolor form from the rgb-picture."
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1123
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1124
    | bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding form imageBits|
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1125
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1126
    bestFormat := self bestSupportedImageFormatFor:aDevice.
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1127
    usedDeviceDepth := bestFormat at:#depth.
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1128
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1129
    usedDevicePadding := bestFormat at:#padding.
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1130
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1131
    imageBits := self
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1132
		    rgbImageBitsOn:aDevice
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1133
		    bestFormat: bestFormat
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1134
		    returnUsedDevicePattingIn:[:arg | usedDevicePadding := arg].
4813
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1135
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1136
    imageBits isNil ifTrue:[
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1137
	^ self asMonochromeFormOn:aDevice
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1138
    ].
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1139
7495
c62bd4c05a4d #OTHER by stefan
Stefan Vogel <sv@exept.de>
parents: 7278
diff changeset
  1140
    form := Form imageForm width:width height:height depth:usedDeviceDepth onDevice:aDevice.
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1141
    form isNil ifTrue:[
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1142
	'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1143
	^ nil
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1144
    ].
5836
877ff039d6f6 changed: #rgbImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5480
diff changeset
  1145
    form id isNil ifTrue:[
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1146
	"/ usually happens if the image is too big (out of memory)
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1147
	'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1148
	^ nil
5836
877ff039d6f6 changed: #rgbImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5480
diff changeset
  1149
    ].
877ff039d6f6 changed: #rgbImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5480
diff changeset
  1150
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1151
    form initGC.
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1152
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1153
    form
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1154
	copyBitsFrom:imageBits
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1155
	bitsPerPixel:usedDeviceBitsPerPixel
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1156
	depth:usedDeviceDepth
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1157
	padding:usedDevicePadding
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1158
	width:width height:height
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  1159
	x:0 y:0 toX:0 y:0.
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1160
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1161
    ^ form
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1162
5836
877ff039d6f6 changed: #rgbImageAsTrueColorFormOn:
Claus Gittinger <cg@exept.de>
parents: 5480
diff changeset
  1163
    "Modified (format): / 30-12-2011 / 12:54:26 / cg"
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1164
!
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1165
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1166
rgbImageBitsOn:aDevice bestFormat: bestFormat
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1167
    "return rgb bits from the rgb-picture."
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1168
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1169
    ^ self
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1170
	rgbImageBitsOn:aDevice
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1171
	bestFormat:bestFormat
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1172
	returnUsedDevicePattingIn:[:usedPadding | ]
4813
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1173
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1174
    "Modified: / 30-10-2007 / 20:56:45 / cg"
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1175
!
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1176
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1177
rgbImageBitsOn:aDevice bestFormat:bestFormat returnUsedDevicePattingIn:aValueHolder
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1178
    "return rgb bits from the rgb-picture.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1179
     Sorry (sigh) - this might decide to use a different padding;
4813
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1180
     this information is returned in aValueHolder"
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1181
4805
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1182
    |bytes usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding
c67a676c439b #rgbImageAsTrueColorFormOn: refactoring
fm
parents: 4778
diff changeset
  1183
     myDepth imageBits padd
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1184
     rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue|
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1185
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1186
    bytes := self bits.
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  1187
236
Claus Gittinger <cg@exept.de>
parents: 235
diff changeset
  1188
    usedDeviceDepth := bestFormat at:#depth.
Claus Gittinger <cg@exept.de>
parents: 235
diff changeset
  1189
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
2064
eece7560f78f md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1190
    usedDevicePadding := bestFormat at:#padding.
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1191
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1192
    rightShiftR := (8 - aDevice bitsRed).
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1193
    rightShiftG := (8 - aDevice bitsGreen).
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1194
    rightShiftB := (8 - aDevice bitsBlue).
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1195
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1196
    shiftRed := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1197
    shiftGreen := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1198
    shiftBlue := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1199
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1200
    "/
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1201
    "/ for now, only a few formats are supported
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1202
    "/
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1203
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1204
    myDepth == usedDeviceBitsPerPixel ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1205
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1206
	"/ first, the trivial case, where the depths match
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1207
	"/ 24 bit/pixel
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1208
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1209
	imageBits := bytes.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1210
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1211
	"/ however, the rgb-order could still be different
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1212
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1213
	((shiftBlue == 0) and:[(shiftGreen == 8) and:[shiftRed == 16]]) ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1214
	    imageBits := ByteArray uninitializedNew:(width * height * 3).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1215
	    usedDevicePadding := 8.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1216
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1217
	    "/ now, walk over the image and compose 24bit values from the r/g/b triples
2064
eece7560f78f md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1218
%{
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1219
	    unsigned char *srcPtr = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1220
	    unsigned char *dstPtr = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1221
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1222
	    if (__isByteArrayLike(bytes)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1223
		srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1224
	    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1225
		if (__isExternalBytesLike(bytes)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1226
		    srcPtr = __externalBytesAddress(bytes);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1227
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1228
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1229
	    if (__isByteArray(imageBits)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1230
		dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1231
	    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1232
		if (__isExternalBytesLike(imageBits)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1233
		    dstPtr = __externalBytesAddress(imageBits);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1234
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1235
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1236
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1237
	    if (__bothSmallInteger(__INST(height), __INST(width))
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1238
	     && __bothSmallInteger(rightShiftR, shiftRed)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1239
	     && __bothSmallInteger(rightShiftG, shiftGreen)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1240
	     && __bothSmallInteger(rightShiftB, shiftBlue)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1241
	     && srcPtr
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1242
	     && dstPtr) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1243
		int rShRed = __intVal(rightShiftR),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1244
		    rShGreen = __intVal(rightShiftG),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1245
		    rShBlue = __intVal(rightShiftB),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1246
		    lShRed = __intVal(shiftRed),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1247
		    lShGreen = __intVal(shiftGreen),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1248
		    lShBlue = __intVal(shiftBlue);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1249
		int x, y, w;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1250
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1251
		w = __intVal(__INST(width));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1252
		if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1253
		    for (y=__intVal(__INST(height)); y > 0; y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1254
			for (x=w; x > 0; x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1255
			    unsigned v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1256
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1257
			    v = srcPtr[0] << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1258
			    v |= (srcPtr[1] << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1259
			    v |= (srcPtr[2] << lShBlue);
2401
025c115d121a mips (MSBFIRST) fixes
Claus Gittinger <cg@exept.de>
parents: 2346
diff changeset
  1260
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1261
			    dstPtr[0] = (v) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1262
			    dstPtr[1] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1263
			    dstPtr[2] = (v>>16) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1264
# else /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1265
			    dstPtr[0] = (v>>16) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1266
			    dstPtr[1] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1267
			    dstPtr[2] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1268
# endif /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1269
			    dstPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1270
			    srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1271
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1272
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1273
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1274
		    for (y=__intVal(__INST(height)); y > 0; y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1275
			for (x=w; x > 0; x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1276
			    unsigned r, g, b, v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1277
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1278
			    r = srcPtr[0] >> rShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1279
			    g = srcPtr[1] >> rShGreen;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1280
			    b = srcPtr[2] >> rShBlue;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1281
			    v = r << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1282
			    v |= (g << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1283
			    v |= (b << lShBlue);
2401
025c115d121a mips (MSBFIRST) fixes
Claus Gittinger <cg@exept.de>
parents: 2346
diff changeset
  1284
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1285
			    dstPtr[0] = (v) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1286
			    dstPtr[1] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1287
			    dstPtr[2] = (v>>16) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1288
# else /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1289
			    dstPtr[0] = (v>>16) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1290
			    dstPtr[1] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1291
			    dstPtr[2] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1292
# endif /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1293
			    dstPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1294
			    srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1295
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1296
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1297
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1298
	    }
2064
eece7560f78f md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  1299
%}.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1300
	]
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1301
    ] ifFalse:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1302
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1303
	"/ 16 bit/pixel ...
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1304
	"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1305
	(usedDeviceBitsPerPixel == 16) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1306
	    padd := width \\ (usedDevicePadding // 16).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1307
	    imageBits := ByteArray uninitializedNew:((width + padd) * height * 2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1308
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1309
	    "/ now, walk over the image and compose 16bit values from the r/g/b triples
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1310
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1311
%{
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1312
	    unsigned char *srcPtr = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1313
	    unsigned char *dstPtr = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1314
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1315
	    if (__isByteArrayLike(bytes)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1316
		srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1317
	    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1318
		if (__isExternalBytesLike(bytes)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1319
		    srcPtr = __externalBytesAddress(bytes);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1320
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1321
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1322
	    if (__isByteArray(imageBits)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1323
		dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1324
	    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1325
		if (__isExternalBytesLike(imageBits)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1326
		    dstPtr = __externalBytesAddress(imageBits);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1327
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1328
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1329
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1330
	    if (__bothSmallInteger(__INST(height),__INST(width))
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1331
	     && __bothSmallInteger(rightShiftR, shiftRed)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1332
	     && __bothSmallInteger(rightShiftG, shiftGreen)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1333
	     && __bothSmallInteger(rightShiftB, shiftBlue)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1334
	     && srcPtr
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1335
	     && dstPtr) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1336
		int rShRed = __intVal(rightShiftR),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1337
		    rShGreen = __intVal(rightShiftG),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1338
		    rShBlue = __intVal(rightShiftB),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1339
		    lShRed = __intVal(shiftRed),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1340
		    lShGreen = __intVal(shiftGreen),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1341
		    lShBlue = __intVal(shiftBlue);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1342
		int x, y, w;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1343
		int p;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1344
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1345
		w = __intVal(__INST(width));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1346
		p = __intVal(padd) * 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1347
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1348
		if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1349
		    for (y=__intVal(__INST(height)); y > 0; y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1350
			for (x=w; x > 0; x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1351
			    unsigned v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1352
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1353
			    v = srcPtr[0] << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1354
			    v |= (srcPtr[1] << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1355
			    v |= (srcPtr[2] << lShBlue);
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1356
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1357
			    ((short *)dstPtr)[0] = v;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1358
# else /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1359
			    dstPtr[0] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1360
			    dstPtr[1] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1361
# endif /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1362
			    dstPtr += 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1363
			    srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1364
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1365
			dstPtr += p;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1366
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1367
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1368
		    if (p == 0) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1369
			int n = __intVal(__INST(height)) * w;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1370
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1371
			while (n >= 2) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1372
			    unsigned w, r, g, b, v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1373
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1374
			    n -= 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1375
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1376
			    r = srcPtr[0];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1377
			    g = srcPtr[1];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1378
			    b = srcPtr[2];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1379
			    v = (r >> rShRed) << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1380
			    v |= ((g >> rShGreen) << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1381
			    v |= ((b >> rShBlue) << lShBlue);
2401
025c115d121a mips (MSBFIRST) fixes
Claus Gittinger <cg@exept.de>
parents: 2346
diff changeset
  1382
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1383
			    ((short *)dstPtr)[0] = v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1384
# else
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1385
			    dstPtr[0] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1386
			    dstPtr[1] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1387
# endif /* not MSB */
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1388
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1389
			    r = srcPtr[3];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1390
			    g = srcPtr[4];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1391
			    b = srcPtr[5];
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1392
			    v = (r >> rShRed) << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1393
			    v |= ((g >> rShGreen) << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1394
			    v |= ((b >> rShBlue) << lShBlue);
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1395
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1396
			    ((short *)dstPtr)[1] = v;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1397
# else
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1398
			    dstPtr[2] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1399
			    dstPtr[3] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1400
# endif /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1401
			    dstPtr += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1402
			    srcPtr += 6;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1403
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1404
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1405
			while (n--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1406
			    unsigned r, g, b, v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1407
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1408
			    r = srcPtr[0] >> rShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1409
			    g = srcPtr[1] >> rShGreen;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1410
			    b = srcPtr[2] >> rShBlue;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1411
			    v = r << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1412
			    v |= (g << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1413
			    v |= (b << lShBlue);
2401
025c115d121a mips (MSBFIRST) fixes
Claus Gittinger <cg@exept.de>
parents: 2346
diff changeset
  1414
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1415
			    ((short *)dstPtr)[0] = v;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1416
# else /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1417
			    dstPtr[0] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1418
			    dstPtr[1] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1419
# endif /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1420
			    dstPtr += 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1421
			    srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1422
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1423
		    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1424
			for (y=__intVal(__INST(height)); y > 0; y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1425
			    for (x=w; x > 0; x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1426
				unsigned r, g, b, v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1427
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1428
				r = srcPtr[0] >> rShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1429
				g = srcPtr[1] >> rShGreen;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1430
				b = srcPtr[2] >> rShBlue;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1431
				v = r << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1432
				v |= (g << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1433
				v |= (b << lShBlue);
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1434
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1435
				((short *)dstPtr)[0] = v;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1436
# else /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1437
				dstPtr[0] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1438
				dstPtr[1] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1439
# endif /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1440
				dstPtr += 2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1441
				srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1442
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1443
			    dstPtr += p;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1444
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1445
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1446
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1447
	    }
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1448
%}.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1449
	] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1450
	    "/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1451
	    "/ 32 bits/pixel ...
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1452
	    "/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1453
	    (usedDeviceBitsPerPixel == 32) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1454
		usedDevicePadding := 8.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1455
		imageBits := ByteArray uninitializedNew:(width * height * 4).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1456
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1457
		"/ now, walk over the image and compose 32bit values from the r/g/b triples
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  1458
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  1459
%{
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1460
		unsigned char *srcPtr = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1461
		unsigned char *dstPtr = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1462
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1463
		if (__isByteArrayLike(bytes)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1464
		    srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1465
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1466
		    if (__isExternalBytesLike(bytes)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1467
			srcPtr = __externalBytesAddress(bytes);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1468
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1469
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1470
		if (__isByteArray(imageBits)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1471
		    dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1472
		} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1473
		    if (__isExternalBytesLike(imageBits)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1474
			dstPtr = __externalBytesAddress(imageBits);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1475
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1476
		}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1477
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1478
		if (__bothSmallInteger(__INST(height), __INST(width))
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1479
		 && __bothSmallInteger(rightShiftR, shiftRed)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1480
		 && __bothSmallInteger(rightShiftG, shiftGreen)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1481
		 && __bothSmallInteger(rightShiftB, shiftBlue)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1482
		 && srcPtr
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1483
		 && dstPtr) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1484
		    int rShRed = __intVal(rightShiftR),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1485
			rShGreen = __intVal(rightShiftG),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1486
			rShBlue = __intVal(rightShiftB),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1487
			lShRed = __intVal(shiftRed),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1488
			lShGreen = __intVal(shiftGreen),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1489
			lShBlue = __intVal(shiftBlue);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1490
		    int x, y, w;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1491
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1492
		    w = __intVal(__INST(width));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1493
		    if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1494
			for (y=__intVal(__INST(height)); y > 0; y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1495
			    for (x=w; x > 0; x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1496
				unsigned v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1497
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1498
				v = srcPtr[0] << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1499
				v |= (srcPtr[1] << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1500
				v |= (srcPtr[2] << lShBlue);
2401
025c115d121a mips (MSBFIRST) fixes
Claus Gittinger <cg@exept.de>
parents: 2346
diff changeset
  1501
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1502
				((int *)dstPtr)[0] = v;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1503
# else /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1504
				dstPtr[0] = (v>>24) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1505
				dstPtr[1] = (v>>16) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1506
				dstPtr[2] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1507
				dstPtr[3] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1508
# endif /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1509
				dstPtr += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1510
				srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1511
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1512
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1513
		    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1514
			for (y=__intVal(__INST(height)); y > 0; y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1515
			    for (x=w; x > 0; x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1516
				unsigned r, g, b, v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1517
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1518
				r = srcPtr[0] >> rShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1519
				g = srcPtr[1] >> rShGreen;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1520
				b = srcPtr[2] >> rShBlue;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1521
				v = r << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1522
				v |= (g << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1523
				v |= (b << lShBlue);
2401
025c115d121a mips (MSBFIRST) fixes
Claus Gittinger <cg@exept.de>
parents: 2346
diff changeset
  1524
# ifdef __MSBFIRST
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1525
				((int *)dstPtr)[0] = v;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1526
# else /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1527
				dstPtr[0] = (v>>24) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1528
				dstPtr[1] = (v>>16) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1529
				dstPtr[2] = (v>>8) & 0xFF;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1530
				dstPtr[3] = (v) & 0xFF;
3357
9234d6f55d5a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3263
diff changeset
  1531
# endif /* not MSB */
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1532
				dstPtr += 4;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1533
				srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1534
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1535
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1536
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1537
		}
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1538
%}.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1539
	    ] ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1540
		"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1541
		"/ 8 bits/pixel ...
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1542
		"/
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1543
		(usedDeviceBitsPerPixel == 8) ifTrue:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1544
		    usedDevicePadding := 8.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1545
		    imageBits := ByteArray uninitializedNew:(width * height).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1546
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1547
		    "/ now, walk over the image and compose 8bit values from the r/g/b triples
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  1548
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  1549
%{
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1550
		    unsigned char *srcPtr = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1551
		    unsigned char *dstPtr = 0;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1552
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1553
		    if (__isByteArrayLike(bytes)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1554
			srcPtr = __ByteArrayInstPtr(bytes)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1555
		    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1556
			if (__isExternalBytesLike(bytes)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1557
			    srcPtr = __externalBytesAddress(bytes);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1558
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1559
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1560
		    if (__isByteArray(imageBits)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1561
			dstPtr = __ByteArrayInstPtr(imageBits)->ba_element;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1562
		    } else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1563
			if (__isExternalBytesLike(imageBits)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1564
			    dstPtr = __externalBytesAddress(imageBits);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1565
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1566
		    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1567
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1568
		    if (__bothSmallInteger(__INST(height), __INST(width))
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1569
		     && __bothSmallInteger(rightShiftR, shiftRed)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1570
		     && __bothSmallInteger(rightShiftG, shiftGreen)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1571
		     && __bothSmallInteger(rightShiftB, shiftBlue)
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1572
		     && srcPtr
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1573
		     && dstPtr) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1574
			int rShRed = __intVal(rightShiftR),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1575
			    rShGreen = __intVal(rightShiftG),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1576
			    rShBlue = __intVal(rightShiftB),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1577
			    lShRed = __intVal(shiftRed),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1578
			    lShGreen = __intVal(shiftGreen),
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1579
			    lShBlue = __intVal(shiftBlue);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1580
			int x, y, w;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1581
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1582
			w = __intVal(__INST(width));
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1583
			if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1584
			    for (y=__intVal(__INST(height)); y > 0; y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1585
				for (x=w; x > 0; x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1586
				    unsigned v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1587
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1588
				    v = srcPtr[0] << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1589
				    v |= (srcPtr[1] << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1590
				    v |= (srcPtr[2] << lShBlue);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1591
				    dstPtr[0] = v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1592
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1593
				    dstPtr += 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1594
				    srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1595
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1596
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1597
			} else {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1598
			    for (y=__intVal(__INST(height)); y > 0; y--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1599
				for (x=w; x > 0; x--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1600
				    unsigned r, g, b, v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1601
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1602
				    r = srcPtr[0] >> rShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1603
				    g = srcPtr[1] >> rShGreen;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1604
				    b = srcPtr[2] >> rShBlue;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1605
				    v = r << lShRed;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1606
				    v |= (g << lShGreen);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1607
				    v |= (b << lShBlue);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1608
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1609
				    dstPtr[0] = v;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1610
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1611
				    dstPtr += 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1612
				    srcPtr += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1613
				}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1614
			    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1615
			}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1616
		    }
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1617
%}.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1618
		]
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1619
	    ].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1620
	]
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1621
    ].
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1622
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  1623
    imageBits isNil ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1624
	'IMAGE: unimplemented trueColor depth in #rgbImageBitsOn: ' errorPrint.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1625
	usedDeviceBitsPerPixel errorPrintCR.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  1626
	^ nil
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1627
    ].
4813
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1628
    aValueHolder value:usedDevicePadding.
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1629
    ^ imageBits
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1630
f03cd0880bd9 oops - rgbImageBits did not update the real padding used
Claus Gittinger <cg@exept.de>
parents: 4805
diff changeset
  1631
    "Created: / 30-10-2007 / 20:54:53 / cg"
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  1632
! !
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1633
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1634
!Depth24Image methodsFor:'dither helpers'!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1635
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1636
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1637
    "return a floyd-steinberg dithered bitmap from the receiver picture,
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  1638
     which must be a depth-24 image.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1639
     This method expects an array of colors to be used for dithering
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1640
     (which need not be a colorCubes colors)."
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1641
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  1642
    |pseudoBits
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1643
     ditherRGBBytes ditherColors
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1644
     w       "{Class: SmallInteger }"
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1645
     h       "{Class: SmallInteger }"
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1646
     index   "{Class: SmallInteger }"
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1647
     ditherIds failed lastColor qScramble
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1648
     clrLookup lookupPos
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1649
     error clr|
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1650
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1651
    self depth ~~ 24 ifTrue:[^ nil].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1652
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1653
    "/ collect valid ditherColors ...
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1654
    aMapOrNil isNil ifTrue:[
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1655
        ditherColors := colors select:[:clr | clr notNil].
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1656
    ] ifFalse:[
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1657
        ditherColors := colors
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1658
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1659
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1660
    "/ ... and sort by manhatten distance from black
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1661
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1662
    qScramble := #(
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1663
                "/  2rX00X00X00X00
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1664
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1665
                    2r000000000000    "/ 0
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1666
                    2r000000000100    "/ 1
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1667
                    2r000000100000    "/ 2
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1668
                    2r000000100100    "/ 3
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1669
                    2r000100000000    "/ 4
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1670
                    2r000100000100    "/ 5
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1671
                    2r000100100000    "/ 6
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1672
                    2r000100100100    "/ 7
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1673
                    2r100000000000    "/ 8
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1674
                    2r100000000100    "/ 9
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1675
                    2r100000100000    "/ a
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1676
                    2r100000100100    "/ b
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1677
                    2r100100000000    "/ c
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1678
                    2r100100000100    "/ d
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1679
                    2r100100100000    "/ e
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1680
                    2r100100100100    "/ f
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1681
                  ).
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1682
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1683
    ditherColors := ditherColors sort:[:a :b |
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1684
                                |cr "{Class: SmallInteger }"
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1685
                                 cg "{Class: SmallInteger }"
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1686
                                 cb "{Class: SmallInteger }"
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1687
                                 i1 "{Class: SmallInteger }"
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1688
                                 i2 "{Class: SmallInteger }"|
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1689
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1690
                                cr := a redByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1691
                                cg := a greenByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1692
                                cb := a blueByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1693
                                i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1694
                                i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1695
                                i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1696
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1697
                                cr := b redByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1698
                                cg := b greenByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1699
                                cb := b blueByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1700
                                i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1701
                                i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1702
                                i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1703
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1704
                                i1 < i2
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1705
                    ].
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1706
    aMapOrNil isNil ifTrue:[
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1707
        ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1708
    ] ifFalse:[
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1709
        ditherIds := aMapOrNil asByteArray
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1710
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1711
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1712
    "/ 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: 3872
diff changeset
  1713
    "/ to the position in the colorList
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1714
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1715
    clrLookup := ByteArray new:(4096).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1716
    index := 0.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1717
    ditherColors keysAndValuesDo:[:clrPosition :clr |
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1718
        |r g b i|
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1719
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1720
        r := clr redByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1721
        g := clr greenByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1722
        b := clr blueByte.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1723
        i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1724
        i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1725
        i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1726
        lookupPos := i.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1727
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1728
        index+1 to:lookupPos do:[:idx|
8967
0a8df312e486 #BUGFIX by exept
Claus Gittinger <cg@exept.de>
parents: 8743
diff changeset
  1729
            clrLookup at:idx put:(clrPosition-1).
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1730
        ].
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1731
        index := lookupPos.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1732
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1733
    clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1734
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1735
"/    [index <= (4095)] whileTrue:[
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1736
"/        clrLookup at:(index+1) put:(ditherColors size - 1).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1737
"/        index := index + 1.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1738
"/    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1739
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1740
    "/ collect ditherColor components
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1741
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1742
    lastColor := ditherColors size.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1743
    ditherIds := ByteArray uninitializedNew:lastColor.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1744
    ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1745
    index := 1.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1746
    1 to:lastColor do:[:pix |
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1747
        clr := ditherColors at:pix.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1748
        ditherRGBBytes at:index put:(clr redByte).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1749
        ditherRGBBytes at:index+1 put:(clr greenByte).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1750
        ditherRGBBytes at:index+2 put:(clr blueByte).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1751
        aMapOrNil isNil ifTrue:[
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1752
            ditherIds at:pix put:clr colorId.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1753
        ] ifFalse:[
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1754
            ditherIds at:pix put:(aMapOrNil at:pix).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1755
        ].
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1756
        index := index + 3.
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1757
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1758
    pseudoBits := ByteArray uninitializedNew:(width * height).
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1759
3907
31dd3278b835 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1760
    error := ByteArray uninitializedNew:(width + 2) * (3*2).
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1761
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1762
    w := width.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1763
    h := height.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1764
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1765
    failed := true.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1766
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1767
%{
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1768
    int __x, __y;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1769
    unsigned char *srcP, *dstP;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1770
    unsigned char *idP;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1771
    unsigned char *__clrLookup;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1772
    short *errP, *eP;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1773
    int __w = __intVal(w);
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1774
    int __h = __intVal(h);
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1775
    int __nColors = __intVal(lastColor);
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1776
    int __wR = -1, __wG, __wB;
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1777
    static int __qScramble[16] = {
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1778
                    0x000 /* 2r000000000000    0 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1779
                    0x004 /* 2r000000000100    1 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1780
                    0x020 /* 2r000000100000    2 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1781
                    0x024 /* 2r000000100100    3 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1782
                    0x100 /* 2r000100000000    4 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1783
                    0x104 /* 2r000100000100    5 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1784
                    0x120 /* 2r000100100000    6 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1785
                    0x124 /* 2r000100100100    7 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1786
                    0x800 /* 2r100000000000    8 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1787
                    0x804 /* 2r100000000100    9 */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1788
                    0x820 /* 2r100000100000    a */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1789
                    0x824 /* 2r100000100100    b */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1790
                    0x900 /* 2r100100000000    c */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1791
                    0x904 /* 2r100100000100    d */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1792
                    0x920 /* 2r100100100000    e */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1793
                    0x924 /* 2r100100100100    f */,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1794
                  };
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1795
5480
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  1796
    if (__isByteArrayLike(__INST(bytes))
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1797
     && __isByteArray(pseudoBits)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1798
     && __isByteArray(ditherRGBBytes)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1799
     && __isByteArray(ditherIds)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1800
     && __isByteArray(clrLookup)
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1801
     && __isByteArray(error)) {
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1802
        failed = false;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1803
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1804
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1805
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1806
        idP = __ByteArrayInstPtr(ditherIds)->ba_element;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1807
        __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1808
        errP = (short *) __ByteArrayInstPtr(error)->ba_element;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1809
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1810
        /*
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1811
         * clear error accumulator
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1812
         */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1813
        eP = errP;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1814
        bzero(eP, (__w+2) * 2 * 3);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1815
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1816
        for (__y=__h; __y>0; __y--) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1817
            unsigned char *dp;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1818
            int __eR, __eG, __eB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1819
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1820
            __eR = __eG = __eB = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1821
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1822
            eP = &(errP[3]);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1823
            __eR = eP[0];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1824
            __eG = eP[1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1825
            __eB = eP[2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1826
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1827
            for (__x=__w; __x>0; __x--) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1828
                int __want;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1829
                int pix;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1830
                int __wantR, __wantG, __wantB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1831
                int idx;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1832
                int tR, tG, tB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1833
                int nR, nG, nB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1834
                int dR, dG, dB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1835
                int minDelta, bestIdx;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1836
                int cnt;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1837
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1838
                __wantR = srcP[0];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1839
                __wantG = srcP[1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1840
                __wantB = srcP[2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1841
                srcP += 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1842
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1843
                /*
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1844
                 * wI are the wanted r/g/b values;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1845
                 * eI are the error values;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1846
                 */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1847
                __wantR = __wantR + __eR;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1848
                __wantG = __wantG + __eG;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1849
                __wantB = __wantB + __eB;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1850
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1851
#define RED_SCALE 30
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1852
#define GREEN_SCALE 59
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1853
#define BLUE_SCALE 11
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1854
#define GOOD_DELTA 30
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1855
3907
31dd3278b835 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 3906
diff changeset
  1856
#define FAST_LOOKUP  /* */
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1857
/* #define ONE_SHOT */
5343
d62fcca557b8 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 5142
diff changeset
  1858
#define NPROBE 16
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1859
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1860
#ifndef FAST_LOOKUP
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1861
                if ((__wantR == __wR)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1862
                 && (__wantG == __wG)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1863
                 && (__wantB == __wB)) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1864
                    /*
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1865
                     * same color again - reuse last bestMatch
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1866
                     */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1867
                } else
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1868
#endif
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1869
                {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1870
                    __wR = __wantR;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1871
                    __wG = __wantG;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1872
                    __wB = __wantB;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1873
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1874
#ifdef FAST_LOOKUP
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1875
                    if(__wR > 255) __wR = 255;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1876
                    else if (__wR < 0) __wR = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1877
                    if(__wG > 255) __wG = 255;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1878
                    else if (__wG < 0) __wG = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1879
                    if(__wB > 255) __wB = 255;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1880
                    else if (__wB < 0) __wB = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1881
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1882
                    {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1883
                        int lookupIndex;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1884
                        int idx, idx0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1885
                        int d, delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1886
                        unsigned char *dp0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1887
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1888
                        dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1889
                        lookupIndex =    __qScramble[((__wR & 0xF0)>>4)];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1890
                        lookupIndex |=   __qScramble[((__wG & 0xF0)>>4)] >> 1;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1891
                        lookupIndex |=   __qScramble[((__wB & 0xF0)>>4)] >> 2;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1892
                        idx = bestIdx =__clrLookup[lookupIndex];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1893
                        dp += (idx+idx+idx);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1894
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1895
                        /* try color at lookupIndex */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1896
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1897
                        d = dp[0];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1898
                        delta = (__wR - d) * RED_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1899
                        if (delta < 0) delta = -delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1900
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1901
                        d = dp[1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1902
                        if (__wG > d)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1903
                            delta += (__wG - d) * GREEN_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1904
                        else
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1905
                            delta += (d - __wG) * GREEN_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1906
                        d = dp[2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1907
                        if (__wB > d)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1908
                            delta += (__wB - d) * BLUE_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1909
                        else
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1910
                            delta += (d - __wB) * BLUE_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1911
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1912
                        if (delta <= GOOD_DELTA) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1913
                            goto foundBest;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1914
                        }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1915
                        minDelta = delta;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1916
# ifndef ONE_SHOT
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1917
                        idx0 = idx; dp0 = dp;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1918
                        cnt = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1919
                        while ((++cnt <= NPROBE) && (idx > 0)) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1920
                            /* try previous color(s) */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1921
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1922
                            idx--; dp -= 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1923
                            d = dp[0];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1924
                            delta = (__wR - d) * RED_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1925
                            if (delta < 0) delta = -delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1926
                            d = dp[1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1927
                            if (__wG > d)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1928
                                delta += (__wG - d) * GREEN_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1929
                            else
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1930
                                delta += (d - __wG) * GREEN_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1931
                            d = dp[2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1932
                            if (__wB > d)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1933
                                delta += (__wB - d) * BLUE_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1934
                            else
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1935
                                delta += (d - __wB) * BLUE_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1936
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1937
                            if (delta < minDelta) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1938
                                bestIdx = idx;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1939
                                if (delta <= GOOD_DELTA) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1940
                                    goto foundBest;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1941
                                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1942
                                minDelta = delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1943
                            }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1944
                        }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1945
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1946
                        idx = idx0; dp = dp0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1947
                        cnt = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1948
                        while ((++cnt <= NPROBE) && (++idx < __nColors)) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1949
                            /* try next color */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1950
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1951
                            dp += 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1952
                            d = dp[0];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1953
                            delta = (__wR - d) * RED_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1954
                            if (delta < 0) delta = -delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1955
                            d = dp[1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1956
                            if (__wG > d)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1957
                                delta += (__wG - d) * GREEN_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1958
                            else
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1959
                                delta += (d - __wG) * GREEN_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1960
                            d = dp[2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1961
                            if (__wB > d)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1962
                                delta += (__wB - d) * BLUE_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1963
                            else
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1964
                                delta += (d - __wB) * BLUE_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1965
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1966
                            if (delta < minDelta) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1967
                                bestIdx = idx;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1968
                                if (delta <= GOOD_DELTA) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1969
                                    goto foundBest;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1970
                                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1971
                                minDelta = delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1972
                            }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1973
                        }
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1974
# endif
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1975
                    }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1976
        foundBest: ;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1977
#else
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1978
/*
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1979
                    if(__wR > 255) __wR = 255;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1980
                    else if (__wR < 0) __wR = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1981
                    if(__wG > 255) __wG = 255;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1982
                    else if (__wG < 0) __wG = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1983
                    if(__wB > 255) __wB = 255;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1984
                    else if (__wB < 0) __wB = 0;
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1985
*/
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  1986
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1987
                    /* find the best matching color */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1988
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1989
                    minDelta = 99999;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1990
                    bestIdx = -1;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1991
                    dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1992
                    for (idx = 0; idx<__nColors; idx++) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1993
                        int d, delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1994
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1995
                        d = dp[0];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1996
                        delta = (__wR - d) * RED_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1997
                        if (delta < 0) delta = -delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1998
                        if (delta < minDelta) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  1999
                            d = dp[1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2000
                            if (__wG > d)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2001
                                delta += (__wG - d) * GREEN_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2002
                            else
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2003
                                delta += (d - __wG) * GREEN_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2004
                            if (delta < minDelta) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2005
                                d = dp[2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2006
                                if (__wB > d)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2007
                                    delta += (__wB - d) * BLUE_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2008
                                else
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2009
                                    delta += (d - __wB) * BLUE_SCALE;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2010
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2011
                                if (delta < minDelta) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2012
                                    bestIdx = idx;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2013
                                    if (delta <= GOOD_DELTA) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2014
                                        break;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2015
                                    }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2016
                                    minDelta = delta;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2017
                                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2018
                            }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2019
                        }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2020
                        dp += 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2021
                    }
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2022
#endif
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2023
                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2024
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2025
                dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2026
                dp += bestIdx * 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2027
                dR = dp[0];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2028
                dG = dp[1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2029
                dB = dp[2];
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2030
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2031
/*
4721
ece6b3ce6b99 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4719
diff changeset
  2032
console_fprintf(stderr, "want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2033
                __wantR, __wantG, __wantB,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2034
                __wR, __wG, __wB,
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2035
                dR, dG, dB);
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2036
*/
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2037
                /*
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2038
                 * store the corresponding dither colors colorId
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2039
                 */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2040
                *dstP++ = idP[bestIdx];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2041
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2042
                /*
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2043
                 * the new error & distribute the error
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2044
                 */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2045
                __eR = __wantR - dR;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2046
                if (__eR) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2047
                    tR = __eR >> 4;  /* 16th of error */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2048
                    nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2049
                    eP[0] = tR*5;         /* 5/16th for (x / y+1) */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2050
                    eP[-3] = tR*3;        /* 3/16th for (x-1 / y+1) */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2051
                    eP[3] = __eR - (tR*15);  /* 1/16th for (x+1 / y+1) */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2052
                    __eR = nR;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2053
                } else {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2054
                    __eR = eP[3];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2055
                    eP[0] = eP[-3] = eP[3] = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2056
                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2057
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2058
                __eG = __wantG - dG;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2059
                if (__eG) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2060
                    tG = __eG >> 4;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2061
                    nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2062
                    eP[1] = tG*5;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2063
                    eP[-2] = tG*3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2064
                    eP[4] = __eG - (tG*15);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2065
                    __eG = nG;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2066
                } else {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2067
                    __eG = eP[4];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2068
                    eP[1] = eP[-2] = eP[4] = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2069
                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2070
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2071
                __eB = __wantB - dB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2072
                if (__eB) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2073
                    tB = __eB >> 4;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2074
                    nB = eP[5] + (tB * 7);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2075
                    eP[2] = tB*5;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2076
                    eP[-1] = tB*3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2077
                    eP[5] = __eB - (tB*15);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2078
                    __eB = nB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2079
                } else {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2080
                    __eB = eP[5];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2081
                    eP[2] = eP[-1] = eP[5] = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2082
                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2083
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2084
                eP += 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2085
            }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2086
        }
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2087
    }
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2088
%}.
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2089
    failed ifTrue:[
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2090
        self primitiveFailed.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2091
        ^ nil
3906
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2092
    ].
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2093
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2094
    ^ pseudoBits
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2095
!
f77d3b42614a dither support 24->8bit image
Claus Gittinger <cg@exept.de>
parents: 3872
diff changeset
  2096
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1767
diff changeset
  2097
floydSteinbergDitheredGrayBitsDepth:depth
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1767
diff changeset
  2098
    "return the bits for dithering a depth gray bitmap from the image.
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2099
     Redefined to make use of knowing that pixels are 24 bit r/g/b"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2100
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2101
    |dstIndex        "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2102
     nextDst         "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2103
     bytesPerRow     "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2104
     bytesPerOutRow  "{Class: SmallInteger }"
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2105
     outBits greyMap1 greyMap2 greyLevels
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2106
     errorArray
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2107
     errorArray1
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2108
     e t v
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2109
     w               "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2110
     h               "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2111
     bitCnt          "{Class: SmallInteger }"
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2112
     byte            "{Class: SmallInteger }"
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2113
     grey dT
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2114
     eR eRB eB eLB bytes|
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2115
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2116
    (samplesPerPixel ~~ 3
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2117
     or:[(#[8 8 8] isSameSequenceAs:bitsPerSample) not
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2118
     or:[depth > 8]]) ifTrue:[
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2119
        ^ super floydSteinbergDitheredGrayBitsDepth:depth
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2120
    ].
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2121
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2122
    bytes := self bits.
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2123
    bytes isNil ifTrue:[ self error. ^ nil].
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2124
    w := width.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2125
    h := height.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2126
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2127
    bytesPerRow := self bytesPerRow.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2128
    bytesPerOutRow := ((w * depth) + 7) // 8.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2129
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2130
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1923
diff changeset
  2131
    depth ~~ 8 ifTrue:[
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2132
        greyLevels := (1 bitShift:depth) - 1.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2133
        greyMap1 := Array new:256.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2134
        greyMap2 := Array new:256.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2135
        1 to:256 do:[:i |
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2136
            v := (greyLevels / 255 * (i-1)).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2137
            greyMap1 at:i put:v.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2138
            greyMap2 at:i put:v.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2139
        ].
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2140
        greyMap1 := (greyMap1 collect:[:b | b truncated]) asByteArray.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2141
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2142
        greyMap2 := (greyMap2 collect:[:el |
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2143
                                            ((el - el truncated)  "/ the error (0..1)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2144
                                                * 255) rounded]) asByteArray.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2145
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2146
        errorArray := ByteArray new:(w + 2) * 2.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2147
        errorArray1 := ByteArray new:(w + 2) * 2.
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2148
    ].
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2149
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2150
%{
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2151
    int __byte;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2152
    int __dT, __err, __e16, __eR, __eB, __eRB, __eLB;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2153
    int __depth = __intVal(depth);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2154
    int __dstIdx = 0;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2155
    int __srcIdx = 0;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2156
    int __bitCnt;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2157
    int __grey;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2158
    int __w = __intVal(w);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2159
    int __h = __intVal(h);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2160
    int __x;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2161
    int __y;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2162
    int __nextDst;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2163
    int __nextSrc;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2164
    int __bytesPerRow = __intVal(bytesPerRow);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2165
    int __bytesPerOutRow = __intVal(bytesPerOutRow);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2166
    int __pixel;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2167
    int __greyLevels = __intVal(greyLevels);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2168
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2169
    unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2170
    unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element;
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2171
    unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2172
    unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2173
    short *__errorArray = (short *)(__ByteArrayInstPtr(errorArray)->ba_element);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2174
    short *__errorArray1 = (short *)(__ByteArrayInstPtr(errorArray1)->ba_element);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2175
    short *__t;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2176
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1923
diff changeset
  2177
    if (__depth == 8) {
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2178
        /*
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2179
         * special code for destination depth 8
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2180
         */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2181
        for (__y=0; __y<__h; __y++) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2182
            __nextDst = __dstIdx + __bytesPerOutRow;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2183
            __nextSrc = __srcIdx + __bytesPerRow;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2184
            for (__x=0; __x<__w; __x++) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2185
                __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2186
                         + (__bytes[__srcIdx+1] * 6)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2187
                         + __bytes[__srcIdx+2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2188
                __pixel = __grey / 10;                      /* 0 .. 255 */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2189
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2190
                __srcIdx += 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2191
                __outBits[__dstIdx] = __pixel;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2192
               __dstIdx++;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2193
            }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2194
            __srcIdx = __nextSrc;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2195
            __dstIdx = __nextDst;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2196
        }
1932
6afe07d9c88c *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1923
diff changeset
  2197
    } else {
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2198
        bzero(errorArray1, (__w+2) * 2);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2199
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2200
        __bitCnt = 8;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2201
        for (__y=0; __y<__h; __y++) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2202
            __nextDst = __dstIdx + __bytesPerOutRow;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2203
            __nextSrc = __srcIdx + __bytesPerRow;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2204
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2205
            __byte = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2206
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2207
            __t = __errorArray;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2208
            __errorArray = __errorArray1;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2209
            __errorArray1 = __t;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2210
            bzero(errorArray1, (__w+2) * 2);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2211
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2212
            for (__x=0; __x<__w; __x++) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2213
                __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2214
                         + (__bytes[__srcIdx+1] * 6)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2215
                         + __bytes[__srcIdx+2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2216
                __grey = __grey / 10;                      /* 0 .. 255 */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2217
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2218
                __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2219
                __err = __greyMap2[__grey];              /* 0.. 255 - error) */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2220
                __err += __errorArray[__x+1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2221
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2222
                if (__err > 127) {                        /* dither says: next pixel */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2223
                   if ( __pixel != __greyLevels)
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2224
                        __pixel++;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2225
                    __err = __err - 255;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2226
                } else {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2227
                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2228
                if (__err) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2229
                    __e16 = __err >> 4;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2230
                    __eR = __e16 * 7;                    /* 7/16 -> right pixel */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2231
                    __eRB = __e16 * 1;                   /* 1/16 -> right below */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2232
                    __eB = __e16 * 5;                    /* 5/16 -> below */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2233
                    __eLB = __err - __eR - __eRB - __eB; /* 3/16 -> left below */
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2234
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2235
                    __errorArray [__x+1+1] += __eR;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2236
                    __errorArray1[__x+1+1] += __eRB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2237
                    __errorArray1[__x+1  ] += __eB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2238
                    __errorArray1[__x+1-1] += __eLB;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2239
                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2240
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2241
                __srcIdx += 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2242
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2243
                __byte = (__byte << __depth) | __pixel;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2244
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2245
                __bitCnt = __bitCnt - __depth;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2246
                if (__bitCnt == 0) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2247
                    __outBits[__dstIdx] = __byte;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2248
                    __dstIdx++;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2249
                    __byte = 0;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2250
                    __bitCnt = 8;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2251
                }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2252
            }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2253
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2254
            if (__bitCnt != 8) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2255
                __byte = __byte << __bitCnt;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2256
                __outBits[__dstIdx] = __byte;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2257
                __bitCnt = 8;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2258
            }
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2259
            __srcIdx = __nextSrc;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2260
            __dstIdx = __nextDst;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2261
        }
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2262
    }
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2263
%}.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2264
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2265
    ^ outBits
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2266
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2267
    "Created: / 10-06-1996 / 13:28:22 / cg"
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2268
    "Modified: / 10-06-1996 / 15:09:07 / cg"
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  2269
    "Modified: / 31-01-2017 / 12:39:31 / stefan"
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2270
!
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2271
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2272
floydSteinbergDitheredMonochromeBits
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2273
    "return the bitmap for a dithered monochrome bitmap from the image.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2274
     Redefined to make use of knowing that pixels are 24 bit r/g/b"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2275
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2276
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1767
diff changeset
  2277
    ^ self floydSteinbergDitheredGrayBitsDepth:1
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2278
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2279
    "Created: 10.6.1996 / 22:55:59 / cg"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2280
!
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  2281
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
  2282
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2283
    "return the bitmap for a dithered depth-bitmap from the image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2284
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2285
     Redefined to make use of knowing that pixels are 24-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2286
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2287
    |dH nDither v range bytes
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2288
     greyMap1 greyMap2 greyLevels outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2289
     bytesPerOutRow  "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2290
     bytesPerRow     "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2291
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2292
     h               "{Class: SmallInteger }"|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2293
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2294
    photometric ~~ #rgb ifTrue:[
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2295
	self error:'invalid format'.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2296
	^ nil
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2297
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2298
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2299
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2300
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2301
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2302
    bytes := self bits.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2303
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2304
    h := height.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2305
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2306
    greyLevels := 1 bitShift:depth.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2307
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2308
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2309
    bytesPerOutRow := (w * depth + 7) // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2310
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2311
    (outBits isNil or:[bytes isNil]) ifTrue:[ self error. ^ nil].
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2312
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2313
    greyMap1 := Array new:256.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2314
    greyMap2 := Array new:256.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2315
    range := greyLevels-1.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2316
    1 to:256 do:[:i |
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2317
	v := (range / 255 * (i-1)).
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2318
	greyMap1 at:i put:v.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2319
	greyMap2 at:i put:v.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2320
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2321
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2322
    greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2323
					    0
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2324
					] ifFalse:[
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2325
					    b truncated
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2326
					]
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2327
				  ]) asByteArray.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2328
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2329
    greyMap2 := (greyMap2 collect:[:el |
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2330
					el isNil ifTrue:[
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2331
					    0
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2332
					] ifFalse:[
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2333
					    ((el - el truncated)  "/ the error (0..1)
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2334
					    * nDither) rounded
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2335
					]]) asByteArray.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2336
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2337
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2338
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2339
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2340
    int __nDither = __intVal(nDither);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2341
    int __dT, __dO;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2342
    int __depth = __intVal(depth);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2343
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2344
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2345
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2346
    int __grey;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2347
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2348
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2349
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2350
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2351
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2352
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2353
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2354
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2355
    int __bytesPerOutRow = __intVal(bytesPerOutRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2356
    int __pixel;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2357
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2358
    unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2359
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2360
    unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2361
    unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2362
    unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2363
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2364
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2365
    for (__y=0; __y<__h; __y++) {
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2366
	__nextDst = __dstIdx + __bytesPerOutRow;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2367
	__nextSrc = __srcIdx + __bytesPerRow;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2368
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2369
	__byte = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2370
	__bitCnt = 8;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2371
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2372
	__oX = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2373
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2374
	for (__x=0; __x<__w; __x++) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2375
	    __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2376
		     + (__bytes[__srcIdx+1] * 6)
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2377
		     + __bytes[__srcIdx+2];
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2378
	    __grey = __grey / 10;                      /* 0 .. 255 */
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2379
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2380
	    __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2381
	    __dO    = __greyMap2[__grey];            /* 0.. nDither-1) */
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2382
	    __dT = __ditherMatrix[__dY + __oX];
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2383
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2384
	    if (__dO > __dT)                         /* dither says: next pixel */
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2385
		__pixel++;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2386
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2387
	    __srcIdx += 3;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2388
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2389
	    __oX++;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2390
	    if (__oX == __dW) __oX = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2391
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2392
	    __byte = (__byte << __depth) | __pixel;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2393
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2394
	    __bitCnt = __bitCnt - __depth;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2395
	    if (__bitCnt == 0) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2396
		__outBits[__dstIdx] = __byte;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2397
		__dstIdx++;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2398
		__byte = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2399
		__bitCnt = 8;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2400
	    }
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2401
	}
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2402
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2403
	if (__bitCnt != 8) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2404
	    __byte = __byte << __bitCnt;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2405
	    __outBits[__dstIdx] = __byte;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2406
	}
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2407
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2408
	__oY++; __dY += __dW;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2409
	if (__oY == __dH) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2410
	    __oY = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2411
	    __dY = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2412
	}
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2413
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2414
	__srcIdx = __nextSrc;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2415
	__dstIdx = __nextDst;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2416
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2417
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2418
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2419
    ^ outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2420
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2421
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2422
     |i|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2423
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2424
     i := Image fromFile:'bitmaps/granite.tiff'.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2425
     i asOrderedDitheredMonochromeImage inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2426
     i asOrderedDitheredDepth2GrayImage inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2427
     i asOrderedDitheredDepth4GrayImage inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2428
     i asOrderedDitheredDepth8GrayImage inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2429
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2430
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2431
    "Created: 7.6.1996 / 10:48:06 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2432
    "Modified: 7.6.1996 / 11:08:50 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2433
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2434
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2435
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2436
    "return the dithered monochrome bits for the receiver image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2437
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2438
     Redefined to make use of knowing that pixels are 24-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2439
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2440
    |dH nDither bytes
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2441
     monoBits
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2442
     bytesPerMonoRow "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2443
     bytesPerRow     "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2444
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2445
     h               "{Class: SmallInteger }"|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2446
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2447
    photometric ~~ #rgb ifTrue:[
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2448
	self error:'invalid format'.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2449
	^ nil
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2450
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2451
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2452
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2453
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2454
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2455
    bytes := self bits.
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2456
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2457
    h := height.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2458
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2459
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2460
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2461
    bytesPerMonoRow := w + 7 // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2462
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2463
    (monoBits isNil or:[bytes isNil]) ifTrue:[ self error. ^ nil].
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2464
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2465
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2466
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2467
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2468
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2469
    int __nDither = __intVal(nDither);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2470
    int __dT;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2471
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2472
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2473
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2474
    int __grey;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2475
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2476
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2477
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2478
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2479
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2480
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2481
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2482
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2483
    int __bytesPerMonoRow = __intVal(bytesPerMonoRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2484
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  2485
    unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2486
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2487
    unsigned char *__bytes = __ByteArrayInstPtr(bytes)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2488
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2489
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2490
    for (__y=0; __y<__h; __y++) {
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2491
	__nextDst = __dstIdx + __bytesPerMonoRow;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2492
	__nextSrc = __srcIdx + __bytesPerRow;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2493
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2494
	__byte = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2495
	__bitCnt = 8;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2496
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2497
	__oX = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2498
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2499
	for (__x=0; __x<__w; __x++) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2500
	    __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2501
		     + (__bytes[__srcIdx+1] * 6)
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2502
		     + __bytes[__srcIdx+2];
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2503
	    __grey = __grey * (__nDither+1) / 2550;    /* 0 .. nDither+1 */
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2504
	    __srcIdx += 3;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2505
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2506
	    __dT = __ditherMatrix[__dY + __oX];
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2507
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2508
	    __oX++;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2509
	    if (__oX == __dW) __oX = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2510
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2511
	    __byte = __byte << 1;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2512
	    if (__grey > __dT) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2513
		__byte = __byte | 1;                   /* white */
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2514
	    }
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2515
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2516
	    __bitCnt--;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2517
	    if (__bitCnt == 0) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2518
		__monoBits[__dstIdx] = __byte;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2519
		__dstIdx++;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2520
		__byte = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2521
		__bitCnt = 8;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2522
	    }
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2523
	}
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2524
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2525
	if (__bitCnt != 8) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2526
	    __byte = __byte << __bitCnt;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2527
	    __monoBits[__dstIdx] = __byte;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2528
	}
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2529
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2530
	__oY++; __dY += __dW;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2531
	if (__oY == __dH) {
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2532
	    __oY = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2533
	    __dY = 0;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2534
	}
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2535
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2536
	__srcIdx = __nextSrc;
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2537
	__dstIdx = __nextDst;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2538
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2539
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2540
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2541
    ^ monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2542
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2543
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2544
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2545
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2546
     i := Image fromFile:'bitmaps/granite.tiff'.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2547
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2548
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2549
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2550
    "Created: 7.6.1996 / 10:48:06 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2551
    "Modified: 7.6.1996 / 11:08:50 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2552
!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2553
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  2554
threshold8BitGrayBits
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2555
    "return the bits for an 8-bit grey image from the receiver.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2556
     Special code, since this is a common case."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2557
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2558
    |greyBits
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2559
     srcIndex "{ Class: SmallInteger }"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2560
     dstIndex "{ Class: SmallInteger }"|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2561
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2562
    greyBits := ByteArray uninitializedNew:(width * height).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2563
%{
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2564
    if ((__Class(__INST(bytes)) == ByteArray)
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2565
     && (__Class(greyBits) == ByteArray)) {
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2566
	unsigned char *srcPtr, *dstPtr;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2567
	int i;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2568
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2569
	srcPtr = __ByteArrayInstPtr(__INST(bytes))->ba_element;
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2570
	dstPtr = __ByteArrayInstPtr(greyBits)->ba_element;
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2571
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2572
	i = __intVal(__INST(height)) * __intVal(__INST(width));
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2573
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2574
	for (; i > 0; i--) {
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2575
	    int __v;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2576
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2577
	    __v = (srcPtr[0] * 3);     /* 3*r + 6*g + b ; 0 .. 2550 */
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2578
	    __v += (srcPtr[1] * 6);
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2579
	    __v += srcPtr[2];
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2580
	    srcPtr += 3;
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2581
	    __v /= 10;                 /* 0..255 */
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2582
	    *dstPtr++ = __v ;
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  2583
	}
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2584
    }
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2585
%}.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2586
    ^ greyBits
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  2587
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2588
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
  2589
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2590
!Depth24Image methodsFor:'enumerating'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2591
5142
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2592
colorsAtX:x from:yLow to:yHigh do:aBlock
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2593
    "perform aBlock for each pixel from y1 to y2 in col x.
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2594
     The block is passed the color at each pixel.
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2595
     This method allows slighly faster processing of an
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2596
     image than using atX:y:, since some processing can be
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2597
     avoided when going from pixel to pixel. However, for
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2598
     real image processing, specialized methods should be written."
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2599
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2600
    |srcIndex "{ Class: SmallInteger }"
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2601
     y1       "{ Class: SmallInteger }"
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2602
     y2       "{ Class: SmallInteger }"
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2603
     rVal     "{ Class: SmallInteger }"
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2604
     gVal     "{ Class: SmallInteger }"
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2605
     bVal     "{ Class: SmallInteger }"
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2606
     lastR lastG lastB lastColor bytes|
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2607
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2608
    photometric ~~ #rgb ifTrue:[
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2609
	^ super colorsAtX:x from:yLow to:yHigh do:aBlock.
5142
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2610
    ].
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2611
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2612
    bytes := self bits.
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2613
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2614
    y1 := yLow.
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2615
    y2 := yHigh.
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2616
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2617
    srcIndex := 1 + (((width * yLow) + x) * 3).
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2618
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2619
    y1 to:y2 do:[:y |
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2620
	rVal := bytes at:(srcIndex).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2621
	gVal := bytes at:(srcIndex + 1).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2622
	bVal := bytes at:(srcIndex + 2).
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2623
	srcIndex := srcIndex + width.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2624
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2625
	(rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2626
	    lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2627
	    lastR := rVal.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2628
	    lastG := gVal.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2629
	    lastB := bVal.
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2630
	].
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  2631
	aBlock value:y value:lastColor
5142
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2632
    ]
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2633
!
f6804072871f +colorsAtX:from:to:do:
Claus Gittinger <cg@exept.de>
parents: 4813
diff changeset
  2634
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  2635
colorsAtY:y from:xLow to:xHigh do:aBlock
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2636
    "perform aBlock for each pixel from x1 to x2 in row y.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2637
     The block is passed the color at each pixel.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2638
     This method allows slighly faster processing of an
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2639
     image than using atX:y:, since some processing can be
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2640
     avoided when going from pixel to pixel. However, for
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2641
     real image processing, specialized methods should be written."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2642
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2643
    |srcIndex "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2644
     x1       "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2645
     x2       "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2646
     rVal     "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2647
     gVal     "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2648
     bVal     "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2649
     lastR lastG lastB lastColor bytes|
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2650
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2651
    photometric ~~ #rgb ifTrue:[
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2652
	^ super colorsAtY:y from:xLow to:xHigh do:aBlock.
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2653
    ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2654
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2655
    bytes := self bits.
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2656
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2657
    x1 := xLow.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2658
    x2 := xHigh.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2659
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2660
    srcIndex := 1 + (((width * y) + x1) * 3).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2661
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2662
    x1 to:x2 do:[:x |
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2663
	rVal := bytes at:(srcIndex).
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2664
	gVal := bytes at:(srcIndex + 1).
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2665
	bVal := bytes at:(srcIndex + 2).
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2666
	srcIndex := srcIndex + 3.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2667
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2668
	(rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2669
	    lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2670
	    lastR := rVal.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2671
	    lastG := gVal.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2672
	    lastB := bVal.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2673
	].
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2674
	aBlock value:x value:lastColor
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2675
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  2676
2190
ac8e972bb813 oops - bad color used in enumerator.
Claus Gittinger <cg@exept.de>
parents: 2067
diff changeset
  2677
    "Created: / 7.6.1996 / 19:12:28 / cg"
ac8e972bb813 oops - bad color used in enumerator.
Claus Gittinger <cg@exept.de>
parents: 2067
diff changeset
  2678
    "Modified: / 27.7.1998 / 20:03:02 / cg"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2679
!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2680
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  2681
valuesAtY:y from:xLow to:xHigh do:aBlock
8121
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2682
    "WARNING: this enumerates pixel values which need photometric interpretation
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2683
     Do not confuse with #rgbValuesAtY:from:to:do:
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2684
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2685
     Perform aBlock for each pixelValue from x1 to x2 in row y.
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2686
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2687
     Notice the difference between rgbValue and pixelValue: rgbValues are always
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2688
     the rgb bytes; pixelvalues depend on the photometric interpretation, and may be
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2689
     indices into a colormap or be non-byte-sized rgb values.
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2690
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2691
     The block is passed the pixelValue at each pixel.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2692
     This method allows slighly faster processing of an
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2693
     image than using valueAtX:y:, since some processing can be
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2694
     avoided when going from pixel to pixel. However, for
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2695
     real image processing, specialized methods should be written.
7278
52a81602e12c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7273
diff changeset
  2696
     Notice that the pixelValue is the r/g/b value packed into an MSB integer
52a81602e12c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7273
diff changeset
  2697
     (r bitShift:16) bitOr:(g bitSHift:8) bitOr:b
52a81602e12c #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7273
diff changeset
  2698
     i.e. r is the first byte, but high in the passed pixel value."
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2699
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2700
    |srcIndex "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2701
     x1       "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2702
     x2       "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2703
     r        "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2704
     g        "{ Class: SmallInteger }"
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2705
     b        "{ Class: SmallInteger }"
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2706
     bytes|
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2707
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2708
    bytes := self bits.
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2709
    x1 := xLow.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2710
    x2 := xHigh.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2711
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2712
    srcIndex := 1 + (((width * y) + x1) * 3).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2713
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2714
    x1 to:x2 do:[:x |
8121
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2715
        r := bytes at:(srcIndex).
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2716
        g := bytes at:(srcIndex + 1).
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2717
        b := bytes at:(srcIndex + 2).
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2718
        srcIndex := srcIndex + 3.
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2719
        aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b)
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2720
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  2721
8121
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2722
    "Created: / 07-06-1996 / 19:09:40 / cg"
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2723
    "Modified (comment): / 29-08-2017 / 14:53:14 / cg"
7527
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2724
!
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2725
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2726
valuesFromX:xStart y:yStart toX:xEnd y:yEnd do:aBlock
8121
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2727
    "WARNING: this enumerates pixel values which need photometric interpretation
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2728
     Do not confuse with #rgbValuesAtY:from:to:do:
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2729
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2730
     Perform aBlock for each pixelValue in a rectangular area of the image.
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2731
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2732
     Notice the difference between rgbValue and pixelValue: rgbValues are always
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2733
     the rgb bytes; pixelvalues depend on the photometric interpretation, and may be
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2734
     indices into a colormap or be non-byte-sized rgb values.
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2735
7527
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2736
     The block is passed the pixelValue at each pixel.
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2737
     This method allows slighly faster processing of an
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2738
     image than using individual valueAtX:y: accesses,
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2739
     since some processing can be avoided when going from pixel to pixel..
7530
5c500f48ef49 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7528
diff changeset
  2740
     However, for real high performance image  processing, specialized methods
7527
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2741
     should be written which know how to deal with specific photometric interpretations."
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2742
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2743
    |srcIndex    "{ Class: SmallInteger }"
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2744
     srcNext     "{ Class: SmallInteger }"
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2745
     bytesPerRow "{ Class: SmallInteger }"
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2746
     value    "{ Class: SmallInteger }"
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2747
     x1       "{ Class: SmallInteger }"
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2748
     x2       "{ Class: SmallInteger }"
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2749
     y1       "{ Class: SmallInteger }"
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2750
     y2       "{ Class: SmallInteger }"
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2751
     bytes|
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2752
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2753
    x1 := xStart.
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2754
    x2 := xEnd.
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2755
    y1 := yStart.
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2756
    y2 := yEnd.
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2757
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2758
    srcIndex := (width * 3 * y1) + (x1 * 3) + 1 .
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2759
    bytesPerRow := self bytesPerRow.
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2760
    bytes := self bits.
7528
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2761
%{
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2762
    OBJFUNC codeVal;
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2763
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2764
    if (__bothSmallInteger(x1, x2)
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2765
     && __bothSmallInteger(y1, y2)
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2766
     && __bothSmallInteger(srcIndex, bytesPerRow)
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2767
     && __isByteArrayLike(bytes)
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2768
     && __isBlockLike(aBlock)
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2769
     && (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(3))
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2770
     && ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil)
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2771
    ) {
7549
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2772
        int c_x1 = __intVal(x1);
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2773
        int c_x2 = __intVal(x2);
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2774
        int c_y1 = __intVal(y1);
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2775
        int c_y2 = __intVal(y2);
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2776
        int c_w = __intVal(__INST(width));
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2777
        int c_h = __intVal(__INST(height));
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2778
        int c_srcIndex = __intVal(srcIndex)-1;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2779
        int c_bytesPerRow = __intVal(bytesPerRow);
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2780
        int c_y, c_x;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2781
        OBJ c_rHome;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2782
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2783
        c_rHome = __BlockInstPtr(aBlock)->b_home;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2784
        if ((c_rHome == nil) || (__qSpace(c_rHome) >= STACKSPACE)) {
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2785
            if ((((unsigned)c_y1) < c_h)
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2786
             && (((unsigned)c_y2) < c_h)
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2787
             && (((unsigned)c_x1) < c_w)
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2788
             && (((unsigned)c_x2) < c_w)) {
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2789
                unsigned char *c_bytes = (unsigned char*)__ByteArrayInstPtr(bytes)->ba_element;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2790
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2791
                if ((c_srcIndex + (c_bytesPerRow * (c_y2-c_y1))) < __byteArraySize(bytes)) {
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2792
                    c_bytes += c_srcIndex;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2793
                    for (c_y=c_y1; c_y<=c_y2; c_y++) {
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2794
                        unsigned char *c_next = c_bytes + c_bytesPerRow;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2795
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2796
                        for (c_x=c_x1; c_x<=c_x2; c_x++) {
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2797
                            int c_value;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2798
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2799
                            c_value = c_bytes[0];
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2800
                            c_value = (c_value<<8) | c_bytes[1];
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2801
                            c_value = (c_value<<8) | c_bytes[2];
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2802
                            (*(__BlockInstPtr(aBlock)->b_code))(c_rHome, __mkSmallInteger(c_x), __mkSmallInteger(c_y), __mkSmallInteger(c_value));
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2803
                            c_bytes += 3;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2804
                        }
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2805
                        c_bytes = c_next;
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2806
                    }
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2807
                    RETURN(self);
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2808
                }
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2809
            }
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2810
        }
7528
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2811
    }
c48cbbe547e6 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7527
diff changeset
  2812
%}.
7527
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2813
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2814
    y1 to:y2 do:[:y |
7549
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2815
        srcNext := srcIndex + bytesPerRow.
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2816
        x1 to:x2 do:[:x |
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2817
            value := bytes at:srcIndex.
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2818
            value := (value bitShift:8) + (bytes at:srcIndex+1).
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2819
            value := (value bitShift:8) + (bytes at:srcIndex+2).
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2820
            srcIndex := srcIndex + 3.
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2821
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2822
            aBlock value:x value:y value:value
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2823
        ].
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  2824
        srcIndex := srcNext.
7527
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2825
    ].
388a8f3f5c84 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 7512
diff changeset
  2826
8121
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2827
    "Created: / 11-07-1996 / 20:08:11 / cg"
e9b681715859 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 8098
diff changeset
  2828
    "Modified (comment): / 29-08-2017 / 14:45:54 / cg"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2829
! !
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2830
1767
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2831
!Depth24Image methodsFor:'image manipulations'!
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2832
7535
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2833
easyRotateBitsInto:destinationImage angle:degrees
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2834
    "tuned helper for rotation - does the actual pixel shuffling, by degrees clockwise.
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2835
     Here, only 90, 180 and 270 degrees are implemented.
7535
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2836
     Hard angles are done in #hardRotate:.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2837
     The code here a tuned version of the inherited for more performance"
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2838
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2839
    |srcBytesPerRow dstBytesPerRow
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2840
     srcWidth srcHeight
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2841
     dstWidth dstHeight
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2842
     srcBytes dstBytes|
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2843
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2844
    srcBytesPerRow := self bytesPerRow.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2845
    srcBytes := self bits.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2846
    srcWidth := width.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2847
    srcHeight := height.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2848
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2849
    dstBytesPerRow := destinationImage bytesPerRow.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2850
    dstBytes := destinationImage bits.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2851
    dstWidth := destinationImage width.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2852
    dstHeight := destinationImage height.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2853
%{
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2854
    if (__bothSmallInteger(srcWidth, srcHeight)
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2855
     && __bothSmallInteger(dstWidth, dstHeight)
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2856
     && __bothSmallInteger(dstBytesPerRow, srcBytesPerRow)
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2857
     && __isByteArrayLike(srcBytes)
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2858
     && __isByteArrayLike(dstBytes)
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2859
    ) {
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2860
	int c_srcW = __intVal(srcWidth);
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2861
	int c_srcH = __intVal(srcHeight);
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2862
	int c_dstW = __intVal(dstWidth);
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2863
	int c_dstH = __intVal(dstHeight);
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2864
	int c_srcBytesPerRow = __intVal(srcBytesPerRow);
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2865
	int c_dstBytesPerRow = __intVal(dstBytesPerRow);
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2866
	int c_srcW4 = c_srcW-4;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2867
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2868
	// I tried three versions here;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2869
	//   a) compute dstX/y inside the loop,
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2870
	//   b) precompute a transformation matrix and compute inside the loop w.o conditional branches
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2871
	//      (i.e. x*Mx + y*My...)
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2872
	//   c) precompute ptr-delta and use those to step to next destination pixel.
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2873
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2874
	// the funny result:
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2875
	//   all show roughly the same speed on a modern CPU.
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2876
	// So the whole thing is mostly limited by memory-bandwidth,
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2877
	// and there is not much to do, unless we move to a better memory fetch/store
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2878
	// (eg. mmx or similar vector stuff)
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2879
	// However, on slower cpus, algo c shpuld perform better, as it does not need multiplications in the loop.
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2880
	// The version below orecomputes the delta, so it should run fast on older CPUs as well.
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2881
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2882
	{
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2883
	    unsigned char *c_srcBytes = (unsigned char*)__ByteArrayInstPtr(srcBytes)->ba_element;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2884
	    unsigned char *c_dstBytes = (unsigned char*)__ByteArrayInstPtr(dstBytes)->ba_element;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2885
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2886
	    int c_dstNextRowOffset;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2887
	    int c_dstNextColOffset;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2888
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2889
	    if (degrees == __mkSmallInteger(90)) {
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2890
		// destinationImage pixelAtX:(h-row) y:col put:pixel
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2891
		c_dstNextRowOffset = -3;                                // going to previous column
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2892
		c_dstNextColOffset = c_dstBytesPerRow;                  // going to next row
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2893
		c_dstBytes += (c_dstW-1)*3;                             // start in the upper-right of dest
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2894
	    } else if (degrees == __mkSmallInteger(180)) {
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2895
		// destinationImage pixelAtX:(w-col) y:(h-row) put:pixel
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2896
		c_dstNextRowOffset = -c_dstBytesPerRow;                 // going to previous row
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2897
		c_dstNextColOffset = -3;                                // going to prev col
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2898
		c_dstBytes += (c_dstH-1)*c_dstBytesPerRow+(c_dstW-1)*3; // start in the lower-right of dest
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2899
	    } else {
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2900
		// destinationImage pixelAtX:row y:(w-col) put:pixel
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2901
		c_dstNextRowOffset = 3;                                 // going to next col
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2902
		c_dstNextColOffset = -c_dstBytesPerRow;                 // going to prev row
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2903
		c_dstBytes += (c_dstH-1)*c_dstBytesPerRow;              // start in the lower-left of dest
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2904
	    }
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2905
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2906
	    if ((c_srcBytesPerRow * c_srcH) <= __byteArraySize(srcBytes)) {
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2907
		int c_y;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2908
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2909
		for (c_y=0; c_y<c_srcH; c_y++) {
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2910
		    unsigned char *c_srcNext = c_srcBytes + c_srcBytesPerRow;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2911
		    unsigned char *c_dstNext = c_dstBytes + c_dstNextRowOffset;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2912
		    int c_x;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2913
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2914
		    c_x = 0;
7535
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2915
#if 1
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2916
		    if (sizeof(int) == 4) {
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2917
			for (c_x = 0; c_x < c_srcW4; c_x += 4) {
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2918
			    int c_value1, c_value2, c_value3;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2919
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2920
			    c_value1 = ((int *)c_srcBytes)[0];
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2921
			    c_value2 = ((int *)c_srcBytes)[1];
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2922
			    c_value3 = ((int *)c_srcBytes)[2];
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2923
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2924
			    c_dstBytes[0] = (c_value1) & 0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2925
			    c_dstBytes[1] = (c_value1>>8) & 0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2926
			    c_dstBytes[2] = (c_value1>>16) &0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2927
			    c_dstBytes += c_dstNextColOffset;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2928
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2929
			    c_dstBytes[0] = (c_value1>>24) & 0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2930
			    c_dstBytes[1] = (c_value2) & 0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2931
			    c_dstBytes[2] = (c_value2>>8) &0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2932
			    c_dstBytes += c_dstNextColOffset;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2933
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2934
			    c_dstBytes[0] = (c_value2>>16) & 0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2935
			    c_dstBytes[1] = (c_value2>>24) & 0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2936
			    c_dstBytes[2] = (c_value3) &0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2937
			    c_dstBytes += c_dstNextColOffset;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2938
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2939
			    c_dstBytes[0] = (c_value3>>8) & 0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2940
			    c_dstBytes[1] = (c_value3>>16) & 0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2941
			    c_dstBytes[2] = (c_value3>>24) &0xFF;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2942
			    c_dstBytes += c_dstNextColOffset;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2943
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2944
			    c_srcBytes += (3*4);
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2945
			}
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2946
		    }
7535
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2947
#endif
7538
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2948
		    for (; c_x < c_srcW; c_x++) {
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2949
			int c_rValue, c_gValue, c_bValue;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2950
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2951
			c_rValue = c_srcBytes[0];
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2952
			c_gValue = c_srcBytes[1];
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2953
			c_bValue = c_srcBytes[2];
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2954
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2955
			c_dstBytes[0] = c_rValue;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2956
			c_dstBytes[1] = c_gValue;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2957
			c_dstBytes[2] = c_bValue;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2958
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2959
			c_srcBytes += 3;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2960
			c_dstBytes += c_dstNextColOffset;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2961
		    }
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2962
		    c_srcBytes = c_srcNext;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2963
		    c_dstBytes = c_dstNext;
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2964
		}
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2965
		RETURN(self);
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2966
	    }
3dfe4653bbd0 warning
Claus Gittinger <cg@exept.de>
parents: 7535
diff changeset
  2967
	}
7535
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2968
    }
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2969
%}.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2970
    self breakPoint:#cg.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2971
    super easyRotateBitsInto:destinationImage angle:degrees
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2972
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2973
    "
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2974
     |i|
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2975
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2976
     i := Image fromFile:'../../goodies/bitmaps/gifImages/claus.gif'.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2977
     i := Depth24Image fromImage:i.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2978
     i inspect.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2979
     (i rotated:45) inspect.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2980
     (i rotated:90) inspect.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2981
     (i rotated:180) inspect.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2982
     (i rotated:270) inspect.
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2983
    "
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2984
!
d8d9480fdec2 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 7531
diff changeset
  2985
1767
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2986
negative
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2987
    |bytes index newImage newBytes nBytes r g b|
1767
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2988
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2989
    photometric ~~ #rgb ifTrue:[
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2990
	^ super negative.
1767
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2991
    ].
3866
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2992
    bytes := self bits.
c01473a90934 eliminated most references to bytes
Claus Gittinger <cg@exept.de>
parents: 3851
diff changeset
  2993
1767
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2994
    newImage := self copy.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2995
    nBytes := bytes size.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2996
    newImage bits:(newBytes := ByteArray new:nBytes).
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2997
    index := 1.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  2998
    [index < nBytes] whileTrue:[
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  2999
	r := bytes at:index.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3000
	newBytes at:index put:(255-r).
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3001
	index := index + 1.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3002
	g := bytes at:index.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3003
	newBytes at:index put:(255-g).
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3004
	index := index + 1.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3005
	b := bytes at:index.
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3006
	newBytes at:index put:(255-b).
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3007
	index := index + 1.
1767
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  3008
    ].
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  3009
    ^ newImage
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  3010
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  3011
    "Modified: 23.6.1997 / 09:57:19 / cg"
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  3012
! !
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  3013
4760
075322ae4864 defaultPhotometric
Claus Gittinger <cg@exept.de>
parents: 4721
diff changeset
  3014
!Depth24Image methodsFor:'initialization'!
075322ae4864 defaultPhotometric
Claus Gittinger <cg@exept.de>
parents: 4721
diff changeset
  3015
075322ae4864 defaultPhotometric
Claus Gittinger <cg@exept.de>
parents: 4721
diff changeset
  3016
initialize
075322ae4864 defaultPhotometric
Claus Gittinger <cg@exept.de>
parents: 4721
diff changeset
  3017
    super initialize.
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3018
    samplesPerPixel := 3.
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3019
    bitsPerSample := #[8 8 8].
4760
075322ae4864 defaultPhotometric
Claus Gittinger <cg@exept.de>
parents: 4721
diff changeset
  3020
075322ae4864 defaultPhotometric
Claus Gittinger <cg@exept.de>
parents: 4721
diff changeset
  3021
    "Created: / 27-05-2007 / 14:09:34 / cg"
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3022
    "Modified: / 30-01-2017 / 18:29:01 / stefan"
4760
075322ae4864 defaultPhotometric
Claus Gittinger <cg@exept.de>
parents: 4721
diff changeset
  3023
! !
075322ae4864 defaultPhotometric
Claus Gittinger <cg@exept.de>
parents: 4721
diff changeset
  3024
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3025
!Depth24Image methodsFor:'magnification'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3026
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3027
hardAntiAliasedMagnifiedBy:scaleArg
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3028
    "return a new image magnified by scalePoint, aPoint.
6795
f945a03cf2ac class: Depth24Image
Claus Gittinger <cg@exept.de>
parents: 6301
diff changeset
  3029
     This interpolates pixels and is therefore much slower,
f945a03cf2ac class: Depth24Image
Claus Gittinger <cg@exept.de>
parents: 6301
diff changeset
  3030
     but generates nicer looking magnifications."
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3031
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3032
    |scalePoint mX
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3033
     mY
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3034
     newWidth  "{ Class: SmallInteger }"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3035
     newHeight "{ Class: SmallInteger }"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3036
     w         "{ Class: SmallInteger }"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3037
     h         "{ Class: SmallInteger }"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3038
     newImage newBits bitsPerPixel newBytesPerRow newMask
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3039
     value
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3040
     srcRow pixelArray|
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3041
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3042
    scalePoint := scaleArg asPoint. 
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3043
    mX := scalePoint x.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3044
    mY := scalePoint y.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3045
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3046
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3047
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3048
    newWidth := (width * mX) truncated.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3049
    newHeight := (height * mY) truncated.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3050
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3051
    bitsPerPixel := self depth.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3052
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3053
    newBits := ByteArray new: "uninitializedNew:" (newBytesPerRow * newHeight).
2064
eece7560f78f md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3054
    newBits isNil ifTrue:[
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3055
        'Depth24Image [warning]: failed to allocate byteArray for image bits' errorPrintCR.
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3056
        ^ nil
2064
eece7560f78f md's WIN32 changes
Claus Gittinger <cg@exept.de>
parents: 2044
diff changeset
  3057
    ].
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3058
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3059
    mask notNil ifTrue:[
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3060
        newMask := (mask magnifiedBy:scalePoint)
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3061
    ].
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3062
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3063
    newImage := self species new.
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3064
    newImage
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3065
        width:newWidth
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3066
        height:newHeight
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3067
        photometric:photometric
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3068
        samplesPerPixel:samplesPerPixel
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3069
        bitsPerSample:bitsPerSample
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3070
        colorMap:nil
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3071
        bits:newBits
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3072
        mask:newMask.
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3073
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3074
    mY := mY asFloat.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3075
    mX := mX asFloat.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3076
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3077
%{
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3078
    REGISTER unsigned char *_dstP = __ByteArrayInstPtr(newBits)->ba_element;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3079
    unsigned char *_srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3080
    unsigned char *_srcRowP, *sP;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3081
    int _width3 = __intVal(__INST(width)) * 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3082
    int _oldW = __intVal(__INST(width)) - 1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3083
    int _oldH = __intVal(__INST(height)) - 1;
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3084
    int _w = __intVal(newWidth) - 1;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3085
    int _h = __intVal(newHeight) - 1;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3086
    int _row, _col;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3087
    double _mX = __floatVal(mX);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3088
    double _mY = __floatVal(mY);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3089
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3090
    for (_row = 0; _row <= _h; _row++) {
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3091
        double _srcY;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3092
        double _dY;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3093
        int _sR;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3094
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3095
        _srcY = ((double)_row / _mY);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3096
        _sR = (int)_srcY;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3097
        _dY = _srcY - ((double)_sR);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3098
        _srcRowP = _srcP + (_width3 * _sR);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3099
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3100
        for (_col = 0; _col <= _w; _col++) {
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3101
            unsigned int rHere, gHere, bHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3102
            unsigned int rRight, gRight, bRight;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3103
            unsigned int rRightBelow, gRightBelow, bRightBelow;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3104
            unsigned int rBelow, gBelow, bBelow;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3105
            unsigned int _r, _g, _b;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3106
            double wHere, wRight, wRightBelow, wBelow, sumW;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3107
            double _srcX;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3108
            double _dX;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3109
            int _sC;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3110
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3111
            _srcX = ((double)_col / _mX);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3112
            _sC = (int)_srcX;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3113
            _dX = _srcX - ((double)_sC);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3114
            sP = _srcRowP + (_sC * 3);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3115
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3116
            rHere = sP[0];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3117
            gHere = sP[1];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3118
            bHere = sP[2];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3119
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3120
            if (_sC < _oldW) {
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3121
                rRight = sP[3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3122
                gRight = sP[4];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3123
                bRight = sP[5];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3124
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3125
                if (_sR < _oldH) {
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3126
                    rBelow = sP[0+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3127
                    gBelow = sP[1+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3128
                    bBelow = sP[2+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3129
                    rRightBelow = sP[3+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3130
                    gRightBelow = sP[4+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3131
                    bRightBelow = sP[5+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3132
                } else {
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3133
                    rRightBelow = rHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3134
                    gRightBelow = gHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3135
                    bRightBelow = bHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3136
                    rBelow = rHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3137
                    gBelow = gHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3138
                    bBelow = bHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3139
                }
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3140
            } else {
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3141
                rRight = rRightBelow = rHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3142
                gRight = gRightBelow = gHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3143
                bRight = bRightBelow = bHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3144
                if (_sR < _oldH) {
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3145
                    rBelow = sP[0+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3146
                    gBelow = sP[1+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3147
                    bBelow = sP[2+_width3];
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3148
                } else {
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3149
                    rBelow = rHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3150
                    gBelow = gHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3151
                    bBelow = bHere;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3152
                }
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3153
            }
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3154
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3155
            wHere = (1.0 - _dX) * (1.0 - _dY);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3156
            wRight = _dX * (1.0 - _dY);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3157
            wBelow = _dY * (1.0 - _dX);
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3158
            wRightBelow = _dX * _dY;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3159
            sumW = wHere + wRight + wBelow + wRightBelow;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3160
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3161
            _r = ((rHere * wHere) + (rRight * wRight) + (rBelow * wBelow) + (rRightBelow * wRightBelow)) / sumW;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3162
            _g = ((gHere * wHere) + (gRight * wRight) + (gBelow * wBelow) + (gRightBelow * wRightBelow)) / sumW;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3163
            _b = ((bHere * wHere) + (bRight * wRight) + (bBelow * wBelow) + (bRightBelow * wRightBelow)) / sumW;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3164
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3165
            _dstP[0] = _r;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3166
            _dstP[1] = _g;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3167
            _dstP[2] = _b;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3168
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3169
            _dstP += 3;
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3170
        }
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3171
    }
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3172
%}.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3173
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3174
    ^ newImage
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3175
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3176
    "
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3177
     |i|
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3178
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3179
     i hardAntiAliasedMagnifiedBy:2@2
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3180
    "
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3181
    "
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3182
     |i|
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3183
     i := Depth24Image width:3 height:3 fromArray:#[ 0 0 0  0 0 0  0 0 0
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3184
                                                     0 0 0  255 255 255  0 0 0
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3185
                                                     0 0 0  0 0 0  0 0 0].
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3186
     i hardAntiAliasedMagnifiedBy:8@8
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3187
    "
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3188
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3189
    "Created: / 02-06-1997 / 13:18:53 / cg"
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3190
    "Modified: / 30-08-2017 / 13:35:20 / cg"
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3191
!
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  3192
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3193
hardMagnifiedBy:scaleArg
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  3194
    "return a new image magnified by scalePoint, aPoint.
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3195
     This is the general magnification method, handling non-integral values.
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3196
     It is slower than the integral magnification method.
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3197
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3198
     Notice: this is a naive algorithm, which simply samples the pixel value
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3199
     at the corresponding original pixel's point, without taking neighbors into
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3200
     consideration (i.e. it does not compute an average of those pixels).
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3201
     As a consequence, this will generate bad shrunk images when the original contains
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3202
     sharp lines."
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3203
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3204
    |scalePoint mX mY
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3205
     newWidth  "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  3206
     newHeight "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  3207
     w         "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  3208
     h         "{ Class: SmallInteger }"
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3209
     newImage newBytes newMask
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3210
     value     "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  3211
     srcRowIdx "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  3212
     srcIndex  "{ Class: SmallInteger }"
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3213
     dstIndex  "{ Class: SmallInteger }"|
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3214
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3215
    scalePoint := scaleArg asPoint. 
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  3216
    mX := scalePoint x.
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  3217
    mY := scalePoint y.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3218
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
  3219
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
304f026e10cd Initial revision
claus
parents:
diff changeset
  3220
304f026e10cd Initial revision
claus
parents:
diff changeset
  3221
    newWidth := (width * mX) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
  3222
    newHeight := (height * mY) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
  3223
    newBytes := ByteArray uninitializedNew:(newWidth * 3 * newHeight).
304f026e10cd Initial revision
claus
parents:
diff changeset
  3224
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  3225
    mask notNil ifTrue:[
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3226
        newMask := (mask magnifiedBy:scalePoint)
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  3227
    ].
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  3228
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3229
    newImage := self species new.
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3230
    newImage
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3231
        width:newWidth height:newHeight photometric:photometric
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3232
        samplesPerPixel:samplesPerPixel bitsPerSample:#[8 8 8]
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3233
        colorMap:nil 
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3234
        bits:newBytes mask:newMask.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3235
304f026e10cd Initial revision
claus
parents:
diff changeset
  3236
    "walk over destination image fetching pixels from source image"
304f026e10cd Initial revision
claus
parents:
diff changeset
  3237
304f026e10cd Initial revision
claus
parents:
diff changeset
  3238
    mY := mY asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
  3239
    mX := mX asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
  3240
%{
2042
58c0228331bb single underscore-macros -> double underscores
Claus Gittinger <cg@exept.de>
parents: 1999
diff changeset
  3241
    REGISTER unsigned char *_dstP = __ByteArrayInstPtr(newBytes)->ba_element;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3242
    unsigned char *_srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3243
    unsigned char *_srcRowP, *sP;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3244
    int _width3 = __intVal(__INST(width)) * 3;
2044
9ea84b4ba249 more single-underline macros
Claus Gittinger <cg@exept.de>
parents: 2042
diff changeset
  3245
    int _w = __intVal(newWidth) - 1;
9ea84b4ba249 more single-underline macros
Claus Gittinger <cg@exept.de>
parents: 2042
diff changeset
  3246
    int _h = __intVal(newHeight) - 1;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3247
    int _row, _col;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3248
    double _mX = __floatVal(mX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3249
    double _mY = __floatVal(mY);
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3250
304f026e10cd Initial revision
claus
parents:
diff changeset
  3251
    for (_row = 0; _row <= _h; _row++) {
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3252
        _srcRowP = _srcP + (_width3 * (int)((double)_row / _mY));
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3253
        for (_col = 0; _col <= _w; _col++) {
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3254
            sP = _srcRowP + (((int)((double)_col / _mX)) * 3);
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3255
            _dstP[0] = sP[0];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3256
            _dstP[1] = sP[1];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3257
            _dstP[2] = sP[2];
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3258
            _dstP += 3;
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3259
        }
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3260
    }
304f026e10cd Initial revision
claus
parents:
diff changeset
  3261
%}
304f026e10cd Initial revision
claus
parents:
diff changeset
  3262
.
81
4ba554473294 *** empty log message ***
claus
parents: 66
diff changeset
  3263
"   the above C-code is equivalent to:
4ba554473294 *** empty log message ***
claus
parents: 66
diff changeset
  3264
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3265
    dstIndex := 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
  3266
    w := newWidth - 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
  3267
    h := newHeight - 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
  3268
    0 to:h do:[:row |
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3269
        srcRowIdx := (width * 3 * (row // mY)) + 1.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3270
        0 to:w do:[:col |
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3271
            srcIndex := srcRowIdx + ((col // mX) * 3).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3272
            value := bytes at:srcIndex.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3273
            newBytes at:dstIndex put:value.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3274
            value := bytes at:(srcIndex + 1).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3275
            newBytes at:(dstIndex + 1) put:value.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3276
            value := bytes at:(srcIndex + 2).
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3277
            newBytes at:(dstIndex + 2) put:value.
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3278
            dstIndex := dstIndex + 3
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3279
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3280
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
  3281
"
304f026e10cd Initial revision
claus
parents:
diff changeset
  3282
    ^ newImage
7923
ed0d51bc2352 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 7817
diff changeset
  3283
8133
436102c3dabc #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 8127
diff changeset
  3284
    "Modified: / 30-08-2017 / 13:33:30 / cg"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3285
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3286
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3287
magnifyRowFrom:srcBytes offset:srcStart
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3288
	  into:dstBytes offset:dstStart factor:mX
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3289
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3290
    "magnify a single pixel row - can only magnify by integer factors"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3291
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3292
%{
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3293
    unsigned char *srcP, *dstP;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3294
    int _mag;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3295
    REGISTER int i;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3296
    REGISTER unsigned char byte1, byte2, byte3;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3297
    int _pixels;
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3298
    OBJ w = __INST(width);
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3299
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3300
    if (__bothSmallInteger(srcStart, dstStart)
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3301
     && __bothSmallInteger(w, mX)
5480
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  3302
     && __isByteArrayLike(srcBytes) && __isByteArray(dstBytes)) {
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3303
	_mag = __intVal(mX);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3304
	srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3305
	dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3306
	_pixels = __intVal(w);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3307
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3308
	while (_pixels--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3309
	    byte1 = *srcP;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3310
	    byte2 = *(srcP+1);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3311
	    byte3 = *(srcP+2);
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3312
	    srcP += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3313
	    for (i=_mag; i>0; i--) {
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3314
		*dstP = byte1;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3315
		*(dstP+1) = byte2;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3316
		*(dstP+2) = byte3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3317
		dstP += 3;
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3318
	    }
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3319
	}
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3320
	RETURN (self);
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3321
    }
3842
e97ae6061e75 code cleanup
Claus Gittinger <cg@exept.de>
parents: 3490
diff changeset
  3322
%}.
4719
b645e2f1a76a *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 4118
diff changeset
  3323
    super
6066
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3324
	magnifyRowFrom:srcBytes offset:srcStart
62426e8110ae stx macros with 2 underlines
Claus Gittinger <cg@exept.de>
parents: 6038
diff changeset
  3325
	into:dstBytes offset:dstStart factor:mX
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  3326
! !
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3327
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3328
!Depth24Image methodsFor:'queries'!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3329
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3330
bitsPerPixel
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3331
    "return the number of bits per pixel"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3332
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3333
    ^ 24
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3334
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3335
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3336
bitsPerRow
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3337
    "return the number of bits in one scanline of the image"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3338
3868
e47cf114c824 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3866
diff changeset
  3339
    ^ width * 24
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3340
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3341
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3342
bitsPerSample
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3343
    "return the number of bits per sample.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3344
     The return value is an array of bits-per-plane."
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3345
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  3346
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
7817
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3347
    ^ #[8 8 8]
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3348
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3349
    "Modified: / 10-06-1996 / 18:02:33 / cg"
b6348d4d7f7f #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 7753
diff changeset
  3350
    "Modified: / 30-01-2017 / 18:27:45 / stefan"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3351
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3352
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3353
blueBitsOf:pixel
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3354
    "given a pixel-value, return the blue component as byteValue (0..255)"
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3355
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3356
    photometric == #rgb ifTrue:[
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3357
        ^ pixel bitAnd:16rFF.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3358
    ].
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3359
    ^ super blueBitsOf:pixel.
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3360
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3361
    "Created: 8.6.1996 / 09:56:20 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3362
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3363
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3364
blueComponentOf:pixel
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3365
    "given a pixel-value, return the blue component in percent (0..100)"
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3366
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3367
    ^ (100.0 / 255.0) * (pixel bitAnd:16rFF)
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3368
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3369
    "Created: 8.6.1996 / 08:42:44 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3370
    "Modified: 8.6.1996 / 09:57:41 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3371
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3372
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3373
blueMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3374
    "return the mask used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3375
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3376
    ^ 16rFF
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3377
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3378
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3379
blueShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3380
    "return the shift amount used with translation from pixelValues to blueBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3381
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3382
    ^ 0
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3383
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3384
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3385
bytesPerRow
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3386
    "return the number of bytes in one scanline of the image"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3387
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3388
    ^ width * 3
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3389
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3390
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3391
greenBitsOf:pixel
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3392
    "given a pixel-value, return the green component as byteValue (0..255)"
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3393
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3394
    photometric == #rgb ifTrue:[
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3395
        ^ (pixel bitShift:-8) bitAnd:16rFF.
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3396
    ].
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3397
    ^ super greenBitsOf:pixel.
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3398
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3399
    "Modified: 8.6.1996 / 08:56:28 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3400
    "Created: 8.6.1996 / 09:56:30 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3401
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3402
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3403
greenComponentOf:pixel
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3404
    "given a pixel-value, return the green component in percent (0..100)"
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3405
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3406
    ^ (100.0 / 255.0) * ((pixel bitShift:-8) bitAnd:16rFF).
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3407
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3408
    "Created: 8.6.1996 / 08:42:37 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3409
    "Modified: 8.6.1996 / 09:57:32 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3410
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3411
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3412
greenMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3413
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3414
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3415
    ^ 16rFF
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3416
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3417
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3418
greenShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3419
    "return the shift amount used with translation from pixelValues to greenBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3420
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3421
    ^ -8
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3422
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3423
8083
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3424
numAlphaBits
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3425
    ^ 0
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3426
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3427
    "Created: / 22-08-2017 / 17:41:07 / cg"
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3428
!
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3429
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3430
numBlueBits
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3431
    ^ 8
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3432
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3433
    "Created: / 22-08-2017 / 17:41:19 / cg"
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3434
!
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3435
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3436
numGreenBits
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3437
    ^ 8
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3438
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3439
    "Created: / 22-08-2017 / 17:41:15 / cg"
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3440
!
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3441
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3442
numRedBits
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3443
    ^ 8
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3444
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3445
    "Created: / 22-08-2017 / 17:41:12 / cg"
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3446
!
681440310b59 #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7923
diff changeset
  3447
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3448
redBitsOf:pixel
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3449
    "given a pixel-value, return the red component as byteValue (0..255)"
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3450
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3451
    photometric == #rgb ifTrue:[
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3452
        ^ ((pixel>>16) bitAnd:16rFF).
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3453
    ].
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3454
    ^ super redBitsOf:pixel.
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3455
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3456
    "Modified: 8.6.1996 / 08:56:31 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3457
    "Created: 8.6.1996 / 09:56:39 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3458
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3459
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3460
redComponentOf:pixel
2301
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3461
    "given a pixel-value, return the red component in percent (0..100)"
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3462
60f9cf7dd066 comments; fixed #red/green/blueComponentOfPixel.
Claus Gittinger <cg@exept.de>
parents: 2190
diff changeset
  3463
    ^ (100.0 / 255.0) * ((pixel bitShift:-16) bitAnd:16rFF).
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3464
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3465
    "Created: 8.6.1996 / 08:42:25 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3466
    "Modified: 8.6.1996 / 09:57:23 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3467
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  3468
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3469
redMaskForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3470
    "return the mask used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3471
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3472
    ^ 16rFF
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3473
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3474
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3475
redShiftForPixelValue
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3476
    "return the shift amount used with translation from pixelValues to redBits"
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3477
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3478
    ^ -16
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3479
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3480
4118
Claus Gittinger <cg@exept.de>
parents: 3907
diff changeset
  3481
rgbFromValue:pixelValue
8325
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3482
    "given a pixel value, return the corresponding 24bit rgbValue 
4b86cb61f568 #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 8197
diff changeset
  3483
     (rrggbb, red is MSB)."
4118
Claus Gittinger <cg@exept.de>
parents: 3907
diff changeset
  3484
8090
c475e87d7578 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8083
diff changeset
  3485
    (photometric == #rgb) ifTrue:[
c475e87d7578 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8083
diff changeset
  3486
        ^ pixelValue
c475e87d7578 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8083
diff changeset
  3487
    ].
c475e87d7578 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8083
diff changeset
  3488
    ^ super rgbFromValue:pixelValue.
c475e87d7578 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8083
diff changeset
  3489
c475e87d7578 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8083
diff changeset
  3490
    "Modified: / 22-08-2017 / 18:32:42 / cg"
4118
Claus Gittinger <cg@exept.de>
parents: 3907
diff changeset
  3491
!
Claus Gittinger <cg@exept.de>
parents: 3907
diff changeset
  3492
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3493
samplesPerPixel
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3494
    "return the number of samples per pixel in the image."
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3495
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  3496
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3497
    ^ 3
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  3498
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  3499
    "Modified: 10.6.1996 / 18:03:09 / cg"
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3500
!
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3501
8743
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3502
valueFromColor:aColor
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3503
    "get a color's pixel value."
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3504
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3505
    |r g b|
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3506
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3507
    photometric == #rgb ifTrue:[
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3508
        r := aColor redByte.
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3509
        g := aColor greenByte.
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3510
        b := aColor blueByte.
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3511
        ^ (((r bitShift:8) bitOr:g) bitShift:8) bitOr:b
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3512
    ].
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3513
    ^ super valueFromColor:aColor.
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3514
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3515
    "Created: / 22-07-2019 / 13:50:11 / Claus Gittinger"
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3516
!
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3517
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3518
valueFromRGB:anRGBValue
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3519
    "get the pixel value corresponding to an RGB value."
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3520
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3521
    photometric == #rgb ifTrue:[
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3522
        ^ anRGBValue
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3523
    ].
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3524
    ^ super valueFromRGB:anRGBValue.
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3525
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3526
    "Created: / 22-07-2019 / 13:48:56 / Claus Gittinger"
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3527
!
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3528
3490
7a560c566b72 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 3357
diff changeset
  3529
valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
8743
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3530
    "given the rgb bits, each in 0..maxXXXValue (i.e. according to
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3531
     r/g/b channels number of bits, return the corresponding pixel value.
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3532
     For now, only useful with RGB images"
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3533
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3534
     (photometric == #rgb) ifTrue:[
8440
44692625c8ab #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8325
diff changeset
  3535
        ^ (((redBits bitShift:8) bitOr:greenBits) bitShift:8) bitOr:blueBits
44692625c8ab #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8325
diff changeset
  3536
    ].
8743
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3537
    ^ super valueFromRedBits:redBits greenBits:greenBits blueBits:blueBits
8090
c475e87d7578 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8083
diff changeset
  3538
c475e87d7578 #BUGFIX by cg
Claus Gittinger <cg@exept.de>
parents: 8083
diff changeset
  3539
    "Modified: / 22-08-2017 / 18:34:07 / cg"
8743
140d90ad0ec1 #TUNING by cg
Claus Gittinger <cg@exept.de>
parents: 8440
diff changeset
  3540
    "Modified (comment): / 22-07-2019 / 13:51:18 / Claus Gittinger"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3541
! !
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3542
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  3543
!Depth24Image class methodsFor:'documentation'!
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3544
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3545
version
7125
f37b7e5d26df #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
  3546
    ^ '$Header$'
5480
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  3547
!
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  3548
08d2c4b656bc __isByteArray() to __isByteArrayLike() in primitive code
Stefan Vogel <sv@exept.de>
parents: 5343
diff changeset
  3549
version_CVS
7125
f37b7e5d26df #FEATURE
Claus Gittinger <cg@exept.de>
parents: 6795
diff changeset
  3550
    ^ '$Header$'
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  3551
! !
7549
feafeb92feda #FEATURE by cg
Claus Gittinger <cg@exept.de>
parents: 7538
diff changeset
  3552