Depth24Image.st
author Claus Gittinger <cg@exept.de>
Tue, 22 Jul 1997 12:09:50 +0200
changeset 1818 fd245b7ae2f9
parent 1817 2f71142cb24d
child 1923 cdd2c4e199df
permissions -rw-r--r--
checkin from browser
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
"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    12
304f026e10cd Initial revision
claus
parents:
diff changeset
    13
Image subclass:#Depth24Image
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    14
	instanceVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    15
	classVariableNames:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    16
	poolDictionaries:''
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    17
	category:'Graphics-Images'
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    18
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    19
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
    20
!Depth24Image class methodsFor:'documentation'!
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    21
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    22
copyright
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    23
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    24
 COPYRIGHT (c) 1993 by Claus Gittinger
81
4ba554473294 *** empty log message ***
claus
parents: 66
diff changeset
    25
	      All Rights Reserved
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    26
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    27
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    28
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    29
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    30
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    31
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    32
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    33
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    34
!
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    35
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    36
documentation
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    37
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    38
    this class represents true-color (24 bit / pixel) images.
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    39
    It mainly consists of methods already implemented in Image,
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    40
    reimplemented here for more performance.
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    41
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
    42
    Only the #rgb format is supported here.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
    43
611
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    44
    [author:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    45
        Claus Gittinger
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    46
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    47
    [see also:]
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    48
        Depth1Image Depth2Image Depth4Image Depth8Image Depth16Image
e0442439a3c6 documentation
Claus Gittinger <cg@exept.de>
parents: 579
diff changeset
    49
        ImageReader
46
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    50
"
7b331e9012fd *** empty log message ***
claus
parents: 38
diff changeset
    51
! !
3
c0aaded4ef28 *** empty log message ***
claus
parents: 1
diff changeset
    52
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
    53
!Depth24Image class methodsFor:'queries'!
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    54
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    55
defaultPhotometric
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    56
    "return the default photometric pixel interpretation"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    57
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    58
    ^ #rgb
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    59
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    60
    "Created: 10.6.1996 / 18:08:25 / cg"
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    61
!
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
    62
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    63
imageDepth
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    64
    "return the depth of images represented by instances of
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    65
     this class - here we return 24"
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    66
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    67
    ^ 24
579
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    68
e381761190c4 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 345
diff changeset
    69
    "Modified: 20.4.1996 / 23:39:50 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    70
! !
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    71
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
    72
!Depth24Image methodsFor:'accessing - pixels'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    73
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
    74
colorAtX:x y:y
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    75
    "retrieve a pixel at x/y; return a color.
304f026e10cd Initial revision
claus
parents:
diff changeset
    76
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
    77
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
    78
38
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
    79
    |index "{ Class: SmallInteger }"
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
    80
     rVal gVal bVal|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    81
304f026e10cd Initial revision
claus
parents:
diff changeset
    82
    index := 1 + (((width * y) + x) * 3).
304f026e10cd Initial revision
claus
parents:
diff changeset
    83
    rVal := bytes at:(index).
304f026e10cd Initial revision
claus
parents:
diff changeset
    84
    gVal := bytes at:(index + 1).
304f026e10cd Initial revision
claus
parents:
diff changeset
    85
    bVal := bytes at:(index + 2).
304f026e10cd Initial revision
claus
parents:
diff changeset
    86
304f026e10cd Initial revision
claus
parents:
diff changeset
    87
    photometric ~~ #rgb ifTrue:[
1666
c3db5aafbe32 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
    88
        ^ super colorAtX:x y:y
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    89
    ].
1350
3fced8a1576c *** empty log message ***
ca
parents: 1237
diff changeset
    90
    ^ Color redByte:rVal greenByte:gVal blueByte:bVal
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
    91
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
    92
    "Created: 24.4.1997 / 17:32:47 / cg"
1666
c3db5aafbe32 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1657
diff changeset
    93
    "Modified: 24.4.1997 / 21:32:37 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
    94
!
304f026e10cd Initial revision
claus
parents:
diff changeset
    95
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
    96
colorAtX:x y:y put:aColor
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    97
    "set the pixel at x/y to aColor.
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    98
     Pixels start at x=0 , y=0 for upper left pixel, end at
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
    99
     x = width-1, y=height-1 for lower right pixel."
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   100
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   101
    |index "{ Class: SmallInteger }"|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   102
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   103
    index := 1 + (((width * y) + x) * 3).
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   104
    bytes at:(index) put:(aColor redByte).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   105
    bytes at:(index + 1) put:(aColor greenByte).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   106
    bytes at:(index + 2) put:(aColor blueByte).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   107
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   108
    "Created: 24.4.1997 / 17:32:59 / cg"
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   109
!
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   110
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   111
pixelAtX:x y:y
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   112
    "retrieve a pixel at x/y; return a color.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   113
     Pixels start at x=0 , y=0 for upper left pixel, end at
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   114
     x = width-1, y=height-1 for lower right pixel"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   115
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   116
    |index "{ Class: SmallInteger }"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   117
     rVal  "{ Class: SmallInteger }"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   118
     gVal  "{ Class: SmallInteger }"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   119
     bVal  "{ Class: SmallInteger }"|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   120
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   121
    index := 1 + (((width * y) + x) * 3).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   122
    rVal := bytes at:(index).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   123
    gVal := bytes at:(index + 1).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   124
    bVal := bytes at:(index + 2).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   125
    ^ (((rVal bitShift:8) bitOr:gVal) bitShift:8) bitOr:bVal
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   126
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   127
    "Created: 24.4.1997 / 16:06:34 / cg"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   128
!
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   129
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   130
pixelAtX:x y:y put:aPixelValue
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   131
    "set a pixel at x/y to aPixelValue, which is 24 bits RGB.
304f026e10cd Initial revision
claus
parents:
diff changeset
   132
     Pixels start at x=0 , y=0 for upper left pixel, end at
304f026e10cd Initial revision
claus
parents:
diff changeset
   133
     x = width-1, y=height-1 for lower right pixel"
304f026e10cd Initial revision
claus
parents:
diff changeset
   134
304f026e10cd Initial revision
claus
parents:
diff changeset
   135
    |index "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   136
     val   "{ Class: SmallInteger }" |
304f026e10cd Initial revision
claus
parents:
diff changeset
   137
304f026e10cd Initial revision
claus
parents:
diff changeset
   138
    index := 1 + (((width * y) + x) * 3).
304f026e10cd Initial revision
claus
parents:
diff changeset
   139
    val := aPixelValue.
304f026e10cd Initial revision
claus
parents:
diff changeset
   140
    bytes at:(index + 2) put:(val bitAnd:16rFF).
304f026e10cd Initial revision
claus
parents:
diff changeset
   141
    val := val bitShift:-8.
304f026e10cd Initial revision
claus
parents:
diff changeset
   142
    bytes at:(index + 1) put:(val bitAnd:16rFF).
304f026e10cd Initial revision
claus
parents:
diff changeset
   143
    val := val bitShift:-8.
304f026e10cd Initial revision
claus
parents:
diff changeset
   144
    bytes at:(index) put:val.
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   145
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   146
    "Created: 24.4.1997 / 17:06:33 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   147
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   148
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   149
rowAt:rowIndex putAll:pixelArray
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   150
    "replace a single rows bits from bits in the pixelArray argument;
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   151
     Notice: row indexing starts at 0."
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
    |dstIdx pixel|
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   154
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   155
    dstIdx := (rowIndex * self bytesPerRow) + 1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   156
    1 to:width do:[:col |
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   157
        pixel := pixelArray at:col.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   158
        bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   159
        bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   160
        bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   161
        dstIdx := dstIdx + 3.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   162
    ].
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   163
    ^ pixelArray
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   164
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   165
    "Created: 24.4.1997 / 15:43:08 / cg"
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   166
!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   167
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   168
rowAt:rowIndex putAll:pixelArray startingAt:startIndex
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   169
    "store a single rows bits from bits in the pixelArray argument;
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   170
     Return the pixelArray.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   171
     Notice: row indexing starts at 0."
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   172
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   173
    |dstIdx pixel|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   174
1657
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   175
    dstIdx := (rowIndex * self bytesPerRow) + 1.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   176
    1 to:width do:[:col |
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   177
        pixel := pixelArray at:(startIndex + col).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   178
        bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   179
        bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   180
        bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   181
        dstIdx := dstIdx + 3.
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   182
    ].
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   183
    ^ pixelArray
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   184
f3d8ceac748a pixel accessing methods cleaned up
Claus Gittinger <cg@exept.de>
parents: 1629
diff changeset
   185
    "Created: 24.4.1997 / 15:50:27 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   186
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
   187
304f026e10cd Initial revision
claus
parents:
diff changeset
   188
!Depth24Image methodsFor:'converting rgb images'!
304f026e10cd Initial revision
claus
parents:
diff changeset
   189
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   190
asGrayFormOn:aDevice
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   191
    "return a grey form from the receiver.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   192
     Redefined to use special code when converting to 8-bit
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   193
     greyScale displays."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   194
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   195
    (aDevice visualType == #StaticGray) ifTrue:[
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   196
        aDevice depth == 8 ifTrue:[
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   197
            ^ self makeDeviceGrayPixmapOn:aDevice depth:aDevice depth fromArray:(self threshold8BitGrayBits)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   198
        ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   199
    ].
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   200
    ^ super asGrayFormOn:aDevice
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   201
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   202
    "Created: 10.6.1996 / 19:00:45 / cg"
816
6576c8242e5d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 813
diff changeset
   203
    "Modified: 10.6.1996 / 20:10:19 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   204
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   205
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   206
asThresholdGrayImageDepth:depth
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   207
    "return an 8-bit grey image from the rgb picture.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   208
     Pixel values are reduced to a 0..255 grey level."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   209
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   210
    depth == 8 ifTrue:[
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   211
        photometric == #rgb ifTrue:[
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   212
            ^ Depth8Image
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   213
                width:width
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   214
                height:height
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   215
                fromArray:(self threshold8BitGrayBits)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   216
        ]
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   217
    ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   218
    ^ super asThresholdGrayImageDepth:depth
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   219
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   220
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   221
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   222
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   223
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   224
     (i asThresholdGrayImageDepth:8) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   225
     (i asThresholdGrayImageDepth:4) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   226
     (i asThresholdGrayImageDepth:2) inspect.
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   227
     (i asThresholdGrayImageDepth:1) inspect.
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   228
    "
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   229
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   230
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   231
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   232
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   233
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   234
     ((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:2) inspect
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   235
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   236
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   237
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   238
     |i|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   239
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   240
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   241
     ((i asThresholdGrayImageDepth:8) asOrderedDitheredGrayImageDepth:4) inspect
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   242
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   243
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   244
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   245
     |i|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   246
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   247
     i := Image fromFile:'bitmaps/granite.tiff'.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   248
     (i asThresholdGrayImageDepth:8) asOrderedDitheredMonochromeImage inspect
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   249
    "
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   250
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
   251
    "Created: 8.6.1996 / 13:58:46 / cg"
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
   252
    "Modified: 10.6.1996 / 19:11:18 / cg"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   253
!
304f026e10cd Initial revision
claus
parents:
diff changeset
   254
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   255
rgbImageAsDitheredPseudoFormOn:aDevice
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   256
    "return a dithered pseudocolor form from the rgb-picture.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   257
     This method depends on fixColors being allocated (see Color>>getColors*)"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   258
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   259
    |ditherColors|
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   260
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   261
    (ditherColors := aDevice fixColors) notNil ifTrue:[
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   262
        ^ self 
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   263
                rgbImageAsDitheredPseudoFormOn:aDevice
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   264
                colors:ditherColors
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   265
                nRed:aDevice numFixRed
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   266
                nGreen:aDevice numFixGreen
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   267
                nBlue:aDevice numFixBlue
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   268
    ].
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   269
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   270
    ditherColors := Set new.
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   271
    ditherColors addAll:(aDevice ditherColors).
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   272
    ditherColors addAll:(aDevice deviceColors).
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   273
    ditherColors := ditherColors asArray.
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   274
    ^ self 
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   275
        rgbImageAsDitheredPseudoFormOn:aDevice 
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   276
        colors:ditherColors.
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   277
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   278
    "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
   279
!
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   280
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   281
rgbImageAsDitheredPseudoFormOn:aDevice colors:fixColors
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   282
    "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
   283
     arbitrary fix colors in fixColors."
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   284
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   285
    |pseudoBits f
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   286
     h        "{ Class: SmallInteger }"
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   287
     w        "{ Class: SmallInteger }"
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   288
     numFix   "{Class: SmallInteger }"
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   289
     srcIndex "{ Class: SmallInteger }"
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   290
     dstIndex "{ Class: SmallInteger }"
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   291
     deviceDepth has8BitImage 
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   292
     fixIds fixRed fixGreen fixBlue failed cache idsUsed usedColors|
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   293
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   294
    numFix := fixColors size.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   295
    numFix == 256 ifTrue:[
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   296
        "/ algorithm below only handles 255 colors.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   297
        numFix := 255.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   298
    ].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   299
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   300
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   301
    fixRed := (fixColors asArray collect:[:clr | clr redByte]) asByteArray.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   302
    fixGreen := (fixColors asArray collect:[:clr | clr greenByte]) asByteArray.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   303
    fixBlue := (fixColors asArray collect:[:clr | clr blueByte]) asByteArray.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   304
    cache := ByteArray new:(1 bitShift:14).
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   305
    cache atAllPut:16rFF.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   306
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   307
    deviceDepth := aDevice depth.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   308
    deviceDepth == 8 ifTrue:[
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   309
        has8BitImage := true.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   310
    ] ifFalse:[
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   311
        has8BitImage := false.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   312
        aDevice supportedImageFormats do:[:fmt |
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   313
            (fmt at:#bitsPerPixel) == 8 ifTrue:[
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   314
                has8BitImage := true.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   315
            ]
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   316
        ]
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   317
    ].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   318
    has8BitImage ifFalse:[^ nil].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   319
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   320
    idsUsed := ByteArray new:(fixIds size).
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   321
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   322
    'Depth24Image [info]: dithering ...' infoPrintCR.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   323
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   324
    pseudoBits := ByteArray uninitializedNew:(width * height).
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   325
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   326
    h := height.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   327
    w := width.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   328
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   329
%{
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   330
    int __x, __y, __numFix;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   331
    int __eR, __eG, __eB;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   332
    unsigned char *srcP, *dstP;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   333
    int pix;
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   334
    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
   335
    int __w = __intVal(w);
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   336
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   337
    if (__isByteArray(__INST(bytes))
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   338
     && __isSmallInteger(numFix)
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   339
     && __isByteArray(pseudoBits)
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   340
     && __isByteArray(cache)
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   341
     && __isByteArray(fixIds)
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   342
     && __isByteArray(idsUsed)
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   343
     && __isByteArray(fixRed)
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   344
     && __isByteArray(fixGreen)
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   345
     && __isByteArray(fixBlue) ) {
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   346
        failed = false;
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
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   349
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   350
        idP = __ByteArrayInstPtr(fixIds)->ba_element;
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   351
        usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   352
        redP = __ByteArrayInstPtr(fixRed)->ba_element;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   353
        greenP = __ByteArrayInstPtr(fixGreen)->ba_element;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   354
        blueP = __ByteArrayInstPtr(fixBlue)->ba_element;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   355
        cacheP = __ByteArrayInstPtr(cache)->ba_element;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   356
        __numFix = __intVal(numFix);
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   357
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   358
        for (__y=__intVal(h); __y>0; __y--) {
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   359
            __eR = __eG = __eB = 0;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   360
            for (__x=__w; __x>0; __x--) {
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   361
                int cacheIdx, clrIdx;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   362
                int __wantR, __wantG, __wantB;
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   363
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   364
                __wantR = srcP[0] + __eR;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   365
                if (__wantR > 255) __wantR = 255;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   366
                else if (__wantR < 0) __wantR = 0;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   367
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   368
                __wantG = srcP[1] + __eG;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   369
                if (__wantG > 255) __wantG = 255;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   370
                else if (__wantG < 0) __wantG = 0;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   371
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   372
                __wantB = srcP[2] + __eB;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   373
                if (__wantB > 255) __wantB = 255;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   374
                else if (__wantB < 0) __wantB = 0;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   375
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   376
                /*
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   377
                 * compute cache index
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   378
                 */
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   379
                cacheIdx = ((__wantR & 0xF8) >> 3);
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   380
                cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3);
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   381
                cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4);
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   382
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   383
                clrIdx = cacheP[cacheIdx];
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   384
                if (clrIdx == 0xFF) {   /* invalid slot */
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   385
                    unsigned minErr, minIdx;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   386
                    int i;
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
                    /*
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   389
                     * must search ...
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
                    minErr = 0x7FFFFFF; minIdx = 0;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   392
                    for (i=0; i<__numFix; i++) {
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   393
                        unsigned cR, cG, cB, e;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   394
                        int eR, eG, eB;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   395
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   396
                        cR = redP[i]; cG = greenP[i]; cB = blueP[i];
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   397
                        eR = cR - __wantR;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   398
                        if (eR < 0) eR = -eR;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   399
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   400
                        eG = cG - __wantG;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   401
                        if (eG < 0) eG = -eG;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   402
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   403
                        eB = cB - __wantB;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   404
                        if (eB < 0) eB = -eB;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   405
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   406
                        e = eR + eG + eB;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   407
                        if (e < minErr) {
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   408
                            minErr = e;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   409
                            minIdx = i;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   410
                            if (e < 7) {
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   411
                                break;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   412
                            }
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   413
                        }
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   414
                    }
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   415
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   416
                    /*
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   417
                     * minIdx is now index into fixColors
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   418
                     */
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   419
                    cacheP[cacheIdx] = clrIdx = minIdx;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   420
/*
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   421
printf("want %d/%d/%d best: %d [%d/%d/%d]\n", __wantR, __wantG, __wantB, clrIdx, redP[clrIdx], greenP[clrIdx], blueP[clrIdx]);
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   422
*/
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   423
                }
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   424
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   425
                /*
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   426
                 * store the corresponding dither colorId
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   427
                 */
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   428
                *dstP++ = idP[clrIdx];
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   429
                usedIdP[clrIdx] = 1;
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   430
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   431
                srcP += 3;
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   432
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   433
                /*
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   434
                 * the new error:
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   435
                 */
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   436
                __eR = __wantR - redP[clrIdx]; 
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   437
                __eG = __wantG - greenP[clrIdx]; 
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   438
                __eB = __wantB - blueP[clrIdx]; 
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   439
            }
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   440
        }
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   441
    }
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   442
%}.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   443
    failed ifTrue:[
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   444
        self primitiveFailed.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   445
        ^ nil
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   446
    ].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   447
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   448
    "/ not all colors may be really in use ...
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   449
    usedColors := fixColors copy.
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   450
    idsUsed keysAndValuesDo:[:idx :flag |
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   451
        flag == 0 ifTrue:[
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   452
            usedColors at:idx put:nil
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   453
        ]
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   454
    ].
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   455
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   456
    f := Form width:width height:height depth:aDevice depth on:aDevice.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   457
    f isNil ifTrue:[^ nil].
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   458
    f colorMap:usedColors.
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   459
    f initGC.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   460
    aDevice drawBits:pseudoBits bitsPerPixel:8 depth:aDevice depth
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   461
               width:width height:height
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   462
                   x:0 y:0
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   463
                into:(f id) x:0 y:0 width:width height:height with:(f gcId).
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   464
    ^ f
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   465
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   466
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   467
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
   468
    "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
   469
     using colors from a colorCube for dithering."
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   470
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   471
    |pseudoBits f
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   472
     h        "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   473
     w        "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   474
"/     eR    "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   475
"/     eG    "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   476
"/     eB    "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   477
"/     wantR "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   478
"/     wantG "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   479
"/     wantB "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   480
     fixR  "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   481
     fixG  "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   482
     fixB  "{Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   483
     srcIndex "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   484
     dstIndex "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   485
     deviceDepth has8BitImage 
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   486
     fixIds idsUsed failed usedColors|
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   487
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   488
    fixR := nRed.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   489
    fixR == 0 ifTrue:[ ^ nil].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   490
    fixG := nGreen.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   491
    fixG == 0 ifTrue:[ ^ nil].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   492
    fixB := nBlue.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   493
    fixB == 0 ifTrue:[ ^ nil].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   494
    "/ simple check
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   495
    (fixR * fixG * fixB) ~~ fixColors size ifTrue:[
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   496
        self error:'invalid color array passed'.
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   497
        ^ nil
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   498
    ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   499
    fixIds := (fixColors asArray collect:[:clr | clr colorId]) asByteArray.
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   500
    idsUsed := ByteArray new:(fixIds size).
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   501
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   502
    deviceDepth := aDevice depth.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   503
    deviceDepth == 8 ifTrue:[
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   504
        has8BitImage := true.
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   505
    ] ifFalse:[
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   506
        has8BitImage := false.
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   507
        aDevice supportedImageFormats do:[:fmt |
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   508
            (fmt at:#bitsPerPixel) == 8 ifTrue:[
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   509
                has8BitImage := true.
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   510
            ]
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   511
        ]
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   512
    ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   513
    has8BitImage ifFalse:[^ nil].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   514
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
   515
    'Depth24Image [info]: dithering ...' infoPrintCR.
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   516
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   517
    pseudoBits := ByteArray uninitializedNew:(width * height).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   518
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   519
    h := height.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   520
    w := width.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   521
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   522
%{
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   523
    int __x, __y;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   524
    int __eR, __eG, __eB;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   525
    int __wantR, __wantG, __wantB;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   526
    unsigned char *srcP, *dstP;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   527
    unsigned char *redP, *greenP, *blueP;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   528
    int pix;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   529
    unsigned char *idP;
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   530
    unsigned char *usedIdP;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   531
    int __fR, __fG, __fB;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   532
    int iR, iG, iB;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   533
    int idx;
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   534
    int __w = __intVal(w);
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   535
    int leftToRight;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   536
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   537
    if (__isByteArray(__INST(bytes))
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   538
     && __isByteArray(pseudoBits)
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   539
     && __isByteArray(fixIds)
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   540
     && __isByteArray(idsUsed)
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   541
     && __bothSmallInteger(fixR, fixG)
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   542
     && __isSmallInteger(fixB)) {
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   543
        failed = false;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   544
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   545
        srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   546
        dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   547
        idP = __ByteArrayInstPtr(fixIds)->ba_element;
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   548
        usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   549
        __fR = __intVal(fixR)-1;
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   550
        __fG = __intVal(fixG)-1;
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   551
        __fB = __intVal(fixB)-1;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   552
1818
fd245b7ae2f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1817
diff changeset
   553
        __eR = __eG = __eB = 0;
fd245b7ae2f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1817
diff changeset
   554
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   555
        leftToRight = 1;
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   556
        for (__y=__intVal(h); __y>0; __y--) {
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   557
            if (leftToRight) {
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   558
                for (__x=__w; __x>0; __x--) {
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   559
                    int __want;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   560
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   561
                    /*
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   562
                     * wR, wG and wB is the wanted r/g/b value;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   563
                     * compute the index into the dId table ..
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   564
                     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   565
                     *
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   566
                     * bad kludge: knows how to index into FixColor table
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   567
                     */
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   568
                    __wantR = __want = srcP[0] + __eR;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   569
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   570
                    if (__want > 255) __want = 255;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   571
                    else if (__want < 0) __want = 0;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   572
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   573
                    iR = __want * __fR / 128;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   574
                    iR = (iR / 2) + (iR & 1);
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   575
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   576
                    __wantG = __want = srcP[1] + __eG;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   577
                    if (__want > 255) __want = 255;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   578
                    else if (__want < 0) __want = 0;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   579
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   580
                    iG = __want * __fG / 128;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   581
                    iG = (iG / 2) + (iG & 1);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   582
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   583
                    __wantB = __want = srcP[2] + __eB;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   584
                    if (__want > 255) __want = 255;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   585
                    else if (__want < 0) __want = 0;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   586
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   587
                    iB = __want * __fB / 128;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   588
                    iB = (iB / 2) + (iB & 1);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   589
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   590
                    idx = iR * (__fG+1);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   591
                    idx = (idx + iG) * (__fB+1);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   592
                    idx = idx + iB;
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   593
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   594
                    /*
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   595
                     * store the corresponding dither colorId
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   596
                     */
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   597
                    *dstP++ = idP[idx];
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   598
                    usedIdP[idx] = 1;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   599
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   600
                    srcP += 3;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   601
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   602
                    /*
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   603
                     * the new error:
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   604
                     */
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   605
                    __eR = __wantR - (iR * 256 / __fR); 
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   606
                    __eG = __wantG - (iG * 256 / __fG); 
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   607
                    __eB = __wantB - (iB * 256 / __fB);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   608
                }
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   609
                leftToRight = 0;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   610
            } else {
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   611
                srcP += (__w*3);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   612
                dstP += __w;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   613
                for (__x=__w; __x>0; __x--) {
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   614
                    int __want;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   615
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   616
                    /*
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   617
                     * wR, wG and wB is the wanted r/g/b value;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   618
                     * compute the index into the dId table ..
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   619
                     * values: 0..255; scale to 0..fR-1, 0..fG-1, 0..fB-1
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   620
                     *
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   621
                     * bad kludge: knows how to index into FixColor table
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   622
                     */
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   623
                    srcP -= 3;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   624
                    __wantR = __want = srcP[0] + __eR;
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   625
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   626
                    if (__want > 255) __want = 255;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   627
                    else if (__want < 0) __want = 0;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   628
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   629
                    iR = __want * __fR / 128;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   630
                    iR = (iR / 2) + (iR & 1);
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   631
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   632
                    __wantG = __want = srcP[1] + __eG;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   633
                    if (__want > 255) __want = 255;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   634
                    else if (__want < 0) __want = 0;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   635
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   636
                    iG = __want * __fG / 128;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   637
                    iG = (iG / 2) + (iG & 1);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   638
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   639
                    __wantB = __want = srcP[2] + __eB;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   640
                    if (__want > 255) __want = 255;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   641
                    else if (__want < 0) __want = 0;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   642
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   643
                    iB = __want * __fB / 128;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   644
                    iB = (iB / 2) + (iB & 1);
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   645
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   646
                    idx = iR * (__fG+1);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   647
                    idx = (idx + iG) * (__fB+1);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   648
                    idx = idx + iB;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   649
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   650
                    /*
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   651
                     * store the corresponding dither colorId
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   652
                     */
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   653
                    *--dstP = idP[idx];
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   654
                    usedIdP[idx] = 1;
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   655
1817
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   656
                    /*
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   657
                     * the new error:
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   658
                     */
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   659
                    __eR = __wantR - (iR * 256 / __fR); 
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   660
                    __eG = __wantG - (iG * 256 / __fG); 
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   661
                    __eB = __wantB - (iB * 256 / __fB); 
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   662
                }
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   663
                srcP += (__w*3);
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   664
                dstP += __w;
2f71142cb24d checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1812
diff changeset
   665
                leftToRight = 1;
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   666
            }
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   667
        }
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   668
    }
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   669
%}.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   670
    failed ifTrue:[
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   671
        self primitiveFailed.
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   672
        ^ nil
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   673
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   674
"/ for non-C programmers:
1218
2d7c79e5965f oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   675
"/     the above code is (roughly) equivalent to:
2d7c79e5965f oops - dont limit myself on Display
Claus Gittinger <cg@exept.de>
parents: 1177
diff changeset
   676
"/     (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
   677
"/
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   678
"/    srcIndex := 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   679
"/    dstIndex := 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   680
"/    1 to:h do:[:y |
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   681
"/        eR := eG := eB := 0.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   682
"/        1 to:w do:[:x |
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   683
"/            |pixel "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   684
"/             clr 
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   685
"/             idx   "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   686
"/             iR    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   687
"/             iG    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   688
"/             iB    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   689
"/             wR    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   690
"/             wG    "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   691
"/             wB    "{ Class: SmallInteger }" |
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   692
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   693
"/            wantR := ((bytes at:srcIndex) + eR). srcIndex := srcIndex + 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   694
"/            wantG := ((bytes at:srcIndex) + eG). srcIndex := srcIndex + 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   695
"/            wantB := ((bytes at:srcIndex) + eB). srcIndex := srcIndex + 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   696
"/            wR := wantR.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   697
"/            wR > 255 ifTrue:[wR := 255] ifFalse:[wR < 0 ifTrue:[wR := 0]].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   698
"/            wG := wantG.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   699
"/            wG > 255 ifTrue:[wG := 255] ifFalse:[wG < 0 ifTrue:[wG := 0]].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   700
"/            wB := wantB.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   701
"/            wB > 255 ifTrue:[wB := 255] ifFalse:[wB < 0 ifTrue:[wB := 0]].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   702
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   703
"/            iR := wR * (fixR-1) // 128.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   704
"/            iR := (iR // 2) + (iR bitAnd:1).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   705
"/            iG := wG * (fixG-1) // 128.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   706
"/            iG := (iG // 2) + (iG bitAnd:1).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   707
"/            iB := wB * (fixB-1) // 128.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   708
"/            iB := (iB // 2) + (iB bitAnd:1).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   709
"/            idx := (iR * fixR + iG) * fixB + iB + 1.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   710
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   711
"/            clr := fixColors at:idx.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   712
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   713
"/            eR := wantR - (clr red * 2) asInteger.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   714
"/            eG := wantG - (clr green * 2) asInteger.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   715
"/            eB := wantB - (clr blue * 2) asInteger.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   716
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   717
"/            pixel := clr colorId.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   718
"/            pseudoBits at:dstIndex put:pixel.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   719
"/
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   720
"/            dstIndex := dstIndex + 1
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   721
"/        ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   722
    ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   723
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   724
    "/ not all colors may be really in use ...
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   725
    usedColors := fixColors copy.
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   726
    idsUsed keysAndValuesDo:[:idx :flag |
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   727
        flag == 0 ifTrue:[
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   728
            usedColors at:idx put:nil
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   729
        ]
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   730
    ].
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   731
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   732
    f := Form width:width height:height depth:aDevice depth on:aDevice.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   733
    f isNil ifTrue:[^ nil].
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   734
    f colorMap:usedColors.
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   735
    f initGC.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   736
    aDevice drawBits:pseudoBits bitsPerPixel:8 depth:aDevice depth
858
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   737
               width:width height:height
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   738
                   x:0 y:0
5eb598185858 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 856
diff changeset
   739
                into:(f id) x:0 y:0 width:width height:height with:(f gcId).
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   740
    ^ f
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   741
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
   742
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   743
rgbImageAsPseudoFormOn:aDevice
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   744
    "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
   745
     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
   746
     code. Otherwise, allocate as many colors as possible, then
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   747
     use those for dithering. 
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   748
     Could be improved, by searching for (& allocating)
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   749
     heavily used colors and/or min-max colors first."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   750
304f026e10cd Initial revision
claus
parents:
diff changeset
   751
    |pseudoBits f
304f026e10cd Initial revision
claus
parents:
diff changeset
   752
     r        "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   753
     g        "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   754
     b        "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   755
     srcIndex "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   756
     dstIndex "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   757
     rMask    "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   758
     gMask    "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   759
     bMask    "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   760
     redArray greenArray blueArray
304f026e10cd Initial revision
claus
parents:
diff changeset
   761
     dataSize "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
   762
     nColors  "{ Class: SmallInteger }"
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   763
     fit fitMap colors color ditherColors
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   764
     fast
304f026e10cd Initial revision
claus
parents:
diff changeset
   765
     colorIndex "{ Class: SmallInteger }"
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   766
     depth nColorCells deep nColorsNeeded|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   767
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   768
    aDevice fixColors notNil ifTrue:[
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   769
        "/ no need to look for used colors - dithering anyway ...
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   770
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   771
        f := self rgbImageAsDitheredPseudoFormOn:aDevice.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   772
        f notNil ifTrue:[^ f].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   773
    ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   774
304f026e10cd Initial revision
claus
parents:
diff changeset
   775
    "find used colors; build color-tree"
304f026e10cd Initial revision
claus
parents:
diff changeset
   776
304f026e10cd Initial revision
claus
parents:
diff changeset
   777
    fit := false.                       
304f026e10cd Initial revision
claus
parents:
diff changeset
   778
    fitMap := false.
304f026e10cd Initial revision
claus
parents:
diff changeset
   779
    depth := aDevice depth.
304f026e10cd Initial revision
claus
parents:
diff changeset
   780
    nColorCells := aDevice ncells.
304f026e10cd Initial revision
claus
parents:
diff changeset
   781
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   782
    deep := (depth > 8).
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   783
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   784
    rMask := 2r11111111.
304f026e10cd Initial revision
claus
parents:
diff changeset
   785
    gMask := 2r11111111.
304f026e10cd Initial revision
claus
parents:
diff changeset
   786
    bMask := 2r11111111.
304f026e10cd Initial revision
claus
parents:
diff changeset
   787
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
   788
    'Depth24Image [info]: allocating colors ...' infoPrintCR.
66
398cf6bfb241 *** empty log message ***
claus
parents: 54
diff changeset
   789
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   790
    [fit] whileFalse:[
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   791
        [fitMap] whileFalse:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   792
            srcIndex := 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   793
            redArray := Array new:256.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   794
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   795
            "
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   796
             find used colors, build [r][g][b] 3-dimensional array
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   797
             containing true for used colors
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   798
            "
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   799
            nColors := 0.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   800
            srcIndex := 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   801
            dataSize := bytes size.
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   802
            [(srcIndex < dataSize)
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   803
             and:[nColors <= nColorCells]] whileTrue:[
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   804
%{
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   805
                if (__isByteArray(_INST(bytes))) {
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   806
                    int sI = _intVal(srcIndex);
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   807
                    unsigned char *cp = _ByteArrayInstPtr(_INST(bytes))->ba_element;
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   808
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   809
                    r = __MKSMALLINT((cp[sI - 1] & _intVal(rMask)) + 1);
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   810
                    g = __MKSMALLINT((cp[sI]     & _intVal(gMask)) + 1);
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   811
                    b = __MKSMALLINT((cp[sI + 1] & _intVal(bMask)) + 1);
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   812
                    srcIndex = __MKSMALLINT(sI + 3);
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   813
                    fast = true;
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   814
                } else {
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   815
                    fast = false;
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   816
                }
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   817
%}
304f026e10cd Initial revision
claus
parents:
diff changeset
   818
.
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   819
                fast ifFalse:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   820
                    r := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   821
                    r := (r bitAnd:rMask) + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   822
                    srcIndex := srcIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   823
                    g := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   824
                    g := (g bitAnd:gMask) + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   825
                    srcIndex := srcIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   826
                    b := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   827
                    b := (b bitAnd:bMask) + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   828
                    srcIndex := srcIndex + 1
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   829
                ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   830
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   831
                greenArray := redArray at:r.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   832
                greenArray isNil ifTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   833
                    greenArray := Array new:256.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   834
                    redArray at:r put:greenArray
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   835
                ].
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   836
                blueArray := greenArray at:g.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   837
                blueArray isNil ifTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   838
                    deep ifTrue:[blueArray := Array new:256]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   839
                    ifFalse:[blueArray := ByteArray new:256].
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   840
                    greenArray at:g put:blueArray
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   841
                ].
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   842
                (blueArray at:b) == 0 ifTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   843
                    blueArray at:b put:1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   844
                    nColors := nColors + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   845
                    (nColors > nColorCells) ifTrue:[
1177
e89408c15bb5 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
   846
                        'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR.
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   847
                        srcIndex := dataSize + 1
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   848
                    ]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   849
                ]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   850
            ].
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   851
            nColorsNeeded isNil ifTrue:[
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   852
                nColorsNeeded := nColors
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   853
            ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   854
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   855
            "again with less color bits if it does not fit colormap"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   856
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   857
            (nColors <= nColorCells) ifTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   858
                fitMap := true
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   859
            ] ifFalse:[
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   860
                "/ must try again - cutting off some bits
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   861
                "/ blue bits are snipped off faster.
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   862
                (bMask == 2r11111111) ifTrue:[
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   863
                    bMask := 2r11111100
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   864
                ] ifFalse:[
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   865
                    (bMask == 2r11111100) ifTrue:[
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   866
                        bMask := 2r11110000
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   867
                    ] ifFalse:[
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   868
                        (rMask == 2r11111111) ifTrue:[
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   869
                            rMask := 2r11111100.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   870
                            gMask := 2r11111100.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   871
                        ] ifFalse:[
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   872
                            rMask := (rMask bitShift:1) bitAnd:2r11111111.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   873
                            gMask := (gMask bitShift:1) bitAnd:2r11111111.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   874
                            bMask := (bMask bitShift:1) bitAnd:2r11111111
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   875
                        ]
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   876
                    ]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   877
                ].
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
   878
                'Depth24Image [info]: too many colors; retry with less color resolution' infoPrintCR.
38
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
   879
"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   880
    'masks:' print. rMask print. ' ' print. gMask print. ' ' print.
304f026e10cd Initial revision
claus
parents:
diff changeset
   881
    bMask printNewline
38
2652fc96e660 *** empty log message ***
claus
parents: 35
diff changeset
   882
"
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   883
            ]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   884
        ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   885
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
   886
        'Depth24Image [info]: ' infoPrint. nColors infoPrint. ' colors used' infoPrintCR.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   887
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   888
        colors := Array new:nColors.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   889
        colorIndex := 1.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   890
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   891
        "
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   892
         now, we have reduced things to the number of colors
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   893
         which are theoretically supported by the devices colormap.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   894
         allocate all used colors in walking over true entries in
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   895
         the [r][g][b] table - this may still fail,
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   896
         if we run out of device colors.
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   897
        "
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   898
        fit := true.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   899
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   900
        r := 0.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   901
        redArray do:[:greenArray |
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   902
            (fit and:[greenArray notNil]) ifTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   903
                g := 0.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   904
                greenArray do:[:blueArray |
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   905
                    (fit and:[blueArray notNil]) ifTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   906
                        b := 0.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   907
                        blueArray do:[:present |
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   908
                            |id|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   909
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   910
                            (fit and:[present ~~ 0]) ifTrue:[
1237
15848ece8b95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
   911
                                color := Color redByte:r
15848ece8b95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
   912
                                             greenByte:g
15848ece8b95 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1218
diff changeset
   913
                                              blueByte:b.
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   914
                                color := color on:aDevice.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   915
                                (id := color colorId) isNil ifTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   916
                                    fit := false
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   917
                                ] ifFalse:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   918
                                    colors at:colorIndex put:color.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   919
                                    colorIndex := colorIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   920
                                    blueArray at:(b + 1) put:id
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   921
                                ]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   922
                            ].
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   923
                            b := b + 1
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   924
                        ]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   925
                    ].
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   926
                    g := g + 1
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   927
                ]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   928
            ].
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   929
            r := r + 1
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   930
        ].
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   931
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   932
        "again with less color bits if we did not get all colors"
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   933
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   934
        fit ifFalse:[
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
   935
            'Depth24Image [info]: could not allocate color(s)' infoPrintCR.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   936
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   937
            "free the allocated colors"
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   938
            colors atAllPut:nil.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   939
            "a kludge - force immediate freeing of colors"
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   940
            ObjectMemory scavenge; finalize.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   941
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   942
            "cut off one more color-bit - cut off blue first"
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   943
            (bMask == 2r11111111) ifTrue:[
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   944
                bMask := 2r11111100
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   945
            ] ifFalse:[
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   946
                (bMask == 2r11111100) ifTrue:[
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   947
                    bMask := 2r11110000
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   948
                ] ifFalse:[
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   949
                    (rMask == 2r11111111) ifTrue:[
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   950
                        rMask := 2r11111100.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   951
                        gMask := 2r11111100.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   952
                    ] ifFalse:[
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   953
                        rMask := (rMask bitShift:1) bitAnd:2r11111111.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   954
                        gMask := (gMask bitShift:1) bitAnd:2r11111111.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   955
                        bMask := (bMask bitShift:1) bitAnd:2r11111111
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   956
                    ]
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   957
                ]
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   958
            ].
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   959
            fitMap := false.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   960
            redArray := nil
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   961
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   962
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
   963
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   964
    (nColors ~~ nColorsNeeded) ifTrue:[
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   965
        "/ mhmh - did not get all colors ...
1607
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   966
        "/ add existing colors and dither.
4eb60ce558db when dithering rgb images:
Claus Gittinger <cg@exept.de>
parents: 1598
diff changeset
   967
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   968
        'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   969
        nColorsNeeded infoPrint. ' image colors.' infoPrintCR.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   970
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   971
        "/
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   972
        "/ dither using those we got ...
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   973
        "/
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   974
        DitherAlgorithm == #floydSteinberg ifTrue:[
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   975
            colors := colors asSet.
1629
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   976
"/            ditherColors := aDevice availableDitherColors.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   977
"/            ditherColors notNil ifTrue:[
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   978
"/                colors addAll:ditherColors.
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   979
"/            ].
7735e52e84f0 earlier break out of color allocation loop
Claus Gittinger <cg@exept.de>
parents: 1607
diff changeset
   980
            colors addAll:aDevice deviceColors.
1597
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   981
            colors := colors asArray.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   982
            f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors.
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   983
            f notNil ifTrue:[^ f].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   984
        ].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   985
    ].
019f40ecbe64 added dither code for no-colorCube case.
Claus Gittinger <cg@exept.de>
parents: 1577
diff changeset
   986
1
304f026e10cd Initial revision
claus
parents:
diff changeset
   987
    "create pseudocolor bits and translate"
304f026e10cd Initial revision
claus
parents:
diff changeset
   988
304f026e10cd Initial revision
claus
parents:
diff changeset
   989
    pseudoBits := ByteArray uninitializedNew:(width * height).
304f026e10cd Initial revision
claus
parents:
diff changeset
   990
304f026e10cd Initial revision
claus
parents:
diff changeset
   991
    srcIndex := 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
   992
    dstIndex := 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
   993
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   994
    (rMask == 2r11111111
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   995
     and:[gMask == 2r11111111
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
   996
     and:[bMask == 2r11111111]]) ifTrue:[
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   997
        [srcIndex < dataSize] whileTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   998
            r := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
   999
            srcIndex := srcIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1000
            g := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1001
            srcIndex := srcIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1002
            b := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1003
            srcIndex := srcIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1004
            greenArray := redArray at:(r + 1).
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1005
            blueArray := greenArray at:(g + 1).
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1006
            pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1007
            dstIndex := dstIndex + 1
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1008
        ]
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
  1009
    ] ifFalse:[
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1010
        [srcIndex < dataSize] whileTrue:[
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1011
            r := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1012
            r := r bitAnd:rMask.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1013
            srcIndex := srcIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1014
            g := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1015
            g := g bitAnd:gMask.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1016
            srcIndex := srcIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1017
            b := bytes at:srcIndex.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1018
            b := b bitAnd:bMask.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1019
            srcIndex := srcIndex + 1.
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1020
            greenArray := redArray at:(r + 1).
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1021
            blueArray := greenArray at:(g + 1).
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1022
            pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1023
            dstIndex := dstIndex + 1
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1024
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1025
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
  1026
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
  1027
    f := Form width:width height:height depth:depth on:aDevice.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1028
    f isNil ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
  1029
    f colorMap:colors.
304f026e10cd Initial revision
claus
parents:
diff changeset
  1030
    f initGC.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 81
diff changeset
  1031
    aDevice drawBits:pseudoBits bitsPerPixel:8 depth:depth
938
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1032
               width:width height:height
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1033
                   x:0 y:0
1926ecac24b5 fixColor and ditherColor stuff moved from Color
Claus Gittinger <cg@exept.de>
parents: 886
diff changeset
  1034
                into:(f id) x:0 y:0 width:width height:height with:(f gcId).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1035
    ^ f
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1036
!
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1037
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1038
rgbImageAsTrueColorFormOn:aDevice
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1039
    "return a truecolor form from the rgb-picture."
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1040
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1041
    |bestFormat usedDeviceDepth usedDeviceBitsPerPixel depth
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1042
     myDepth form imageBits destIndex srcIndex 
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1043
     rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue|
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1044
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1045
    bestFormat := self bestSupportedImageFormatFor:aDevice.
236
Claus Gittinger <cg@exept.de>
parents: 235
diff changeset
  1046
    usedDeviceDepth := bestFormat at:#depth.
Claus Gittinger <cg@exept.de>
parents: 235
diff changeset
  1047
    usedDeviceBitsPerPixel := bestFormat at:#bitsPerPixel.
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1048
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1049
    rightShiftR := (8 - aDevice bitsRed).
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1050
    rightShiftG := (8 - aDevice bitsGreen).
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1051
    rightShiftB := (8 - aDevice bitsBlue).
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1052
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1053
    shiftRed := aDevice shiftRed.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1054
    shiftGreen := aDevice shiftGreen.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1055
    shiftBlue := aDevice shiftBlue.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1056
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1057
    "/
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1058
    "/ for now, only a few formats are supported
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1059
    "/
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1060
    myDepth := self bitsPerPixel.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1061
    myDepth == usedDeviceBitsPerPixel ifTrue:[
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1062
        "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1063
        "/ first, the trivial case, where the depths match
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1064
        "/ 24 bit/pixel
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1065
        "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1066
        imageBits := bytes.
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1067
    ] ifFalse:[
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1068
        "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1069
        "/ 16 bit/pixel ...
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1070
        "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1071
        (usedDeviceBitsPerPixel == 16) ifTrue:[
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1072
            imageBits := ByteArray uninitializedNew:(width * height * 2).
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1073
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1074
            "/ 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
  1075
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1076
%{
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1077
            if (__bothSmallInteger(_INST(height),_INST(width))
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1078
             && __bothSmallInteger(rightShiftR, shiftRed)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1079
             && __bothSmallInteger(rightShiftG, shiftGreen)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1080
             && __bothSmallInteger(rightShiftB, shiftBlue)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1081
             && __isByteArray(_INST(bytes))
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1082
             && __isByteArray(imageBits)) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1083
                int rShRed = __intVal(rightShiftR),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1084
                    rShGreen = __intVal(rightShiftG),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1085
                    rShBlue = __intVal(rightShiftB),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1086
                    lShRed = __intVal(shiftRed),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1087
                    lShGreen = __intVal(shiftGreen),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1088
                    lShBlue = __intVal(shiftBlue);
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1089
                int x, y, w;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1090
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1091
                unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1092
                unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1093
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1094
                w = __intVal(_INST(width));
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1095
                if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1096
                    for (y=__intVal(_INST(height)); y > 0; y--) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1097
                        for (x=w; x > 0; x--) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1098
                            unsigned v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1099
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1100
                            v = srcPtr[0] << lShRed;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1101
                            v |= (srcPtr[1] << lShGreen);
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1102
                            v |= (srcPtr[2] << lShBlue);
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1103
# ifdef MSBFIRST
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1104
                            ((short *)dstPtr)[0] = v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1105
# else
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1106
                            dstPtr[0] = (v>>8) & 0xFF;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1107
                            dstPtr[1] = (v) & 0xFF;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1108
# endif
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1109
                            dstPtr += 2;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1110
                            srcPtr += 3;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1111
                        }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1112
                    }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1113
                } else {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1114
                    for (y=__intVal(_INST(height)); y > 0; y--) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1115
                        for (x=w; x > 0; x--) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1116
                            unsigned r, g, b, v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1117
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1118
                            r = srcPtr[0] >> rShRed;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1119
                            g = srcPtr[1] >> rShGreen;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1120
                            b = srcPtr[2] >> rShBlue;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1121
                            v = r << lShRed;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1122
                            v |= (g << lShGreen);
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1123
                            v |= (b << lShBlue);
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1124
# ifdef MSBFIRST
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1125
                            ((short *)dstPtr)[0] = v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1126
# else
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1127
                            dstPtr[0] = (v>>8) & 0xFF;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1128
                            dstPtr[1] = (v) & 0xFF;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1129
# endif
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1130
                            dstPtr += 2;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1131
                            srcPtr += 3;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1132
                        }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1133
                    }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1134
                }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1135
            }
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1136
%}.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1137
        ] ifFalse:[
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1138
            "/
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1139
            "/ 32 bits/pixel ...
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1140
            "/
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1141
            (usedDeviceBitsPerPixel == 32) ifTrue:[
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1142
                imageBits := ByteArray uninitializedNew:(width * height * 4).
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1143
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1144
                "/ now, walk over the image and compose 32bit values from the r/g/b triples
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1145
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1146
%{       
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1147
                if (__bothSmallInteger(_INST(height), _INST(width))
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1148
                 && __bothSmallInteger(rightShiftR, shiftRed)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1149
                 && __bothSmallInteger(rightShiftG, shiftGreen)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1150
                 && __bothSmallInteger(rightShiftB, shiftBlue)
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1151
                 && __isByteArray(_INST(bytes))
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1152
                 && __isByteArray(imageBits)) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1153
                    int rShRed = __intVal(rightShiftR),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1154
                        rShGreen = __intVal(rightShiftG),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1155
                        rShBlue = __intVal(rightShiftB),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1156
                        lShRed = __intVal(shiftRed),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1157
                        lShGreen = __intVal(shiftGreen),
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1158
                        lShBlue = __intVal(shiftBlue);
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1159
                    int x, y, w;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1160
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1161
                    unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1162
                    unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1163
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1164
                    w = __intVal(_INST(width));
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1165
                    if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1166
                        for (y=__intVal(_INST(height)); y > 0; y--) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1167
                            for (x=w; x > 0; x--) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1168
                                unsigned v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1169
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1170
                                v = srcPtr[0] << lShRed;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1171
                                v |= (srcPtr[1] << lShGreen);
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1172
                                v |= (srcPtr[2] << lShBlue);
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1173
# ifdef MSBFIRST
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1174
                                ((int *)dstPtr)[0] = v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1175
# else
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1176
                                dstPtr[0] = (v>>24) & 0xFF;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1177
                                dstPtr[1] = (v>>16) & 0xFF;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1178
                                dstPtr[2] = (v>>8) & 0xFF;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1179
                                dstPtr[3] = (v) & 0xFF;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1180
# endif
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1181
                                dstPtr += 4;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1182
                                srcPtr += 3;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1183
                            }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1184
                        }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1185
                    } else {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1186
                        for (y=__intVal(_INST(height)); y > 0; y--) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1187
                            for (x=w; x > 0; x--) {
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1188
                                unsigned r, g, b, v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1189
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1190
                                r = srcPtr[0] >> rShRed;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1191
                                g = srcPtr[1] >> rShGreen;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1192
                                b = srcPtr[2] >> rShBlue;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1193
                                v = r << lShRed;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1194
                                v |= (g << lShGreen);
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1195
                                v |= (b << lShBlue);
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1196
# ifdef MSBFIRST
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1197
                                ((int *)dstPtr)[0] = v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1198
# else
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1199
                                dstPtr[0] = (v>>24) & 0xFF;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1200
                                dstPtr[1] = (v>>16) & 0xFF;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1201
                                dstPtr[2] = (v>>8) & 0xFF;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1202
                                dstPtr[3] = (v) & 0xFF;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1203
# endif
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1204
                                dstPtr += 4;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1205
                                srcPtr += 3;
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1206
                            }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1207
                        }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1208
                    }
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1209
                }
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1210
%}.
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1211
            ] ifFalse:[
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1212
                "/
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1213
                "/ 8 bits/pixel ...
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1214
                "/
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1215
                (usedDeviceBitsPerPixel == 8) ifTrue:[
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1216
                    imageBits := ByteArray uninitializedNew:(width * height).
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1217
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1218
                    "/ now, walk over the image and compose 8bit values from the r/g/b triples
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1219
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1220
%{              
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1221
                    if (__bothSmallInteger(_INST(height), _INST(width))
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1222
                     && __bothSmallInteger(rightShiftR, shiftRed)
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1223
                     && __bothSmallInteger(rightShiftG, shiftGreen)
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1224
                     && __bothSmallInteger(rightShiftB, shiftBlue)
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1225
                     && __isByteArray(_INST(bytes))
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1226
                     && __isByteArray(imageBits)) {
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1227
                        int rShRed = __intVal(rightShiftR),
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1228
                            rShGreen = __intVal(rightShiftG),
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1229
                            rShBlue = __intVal(rightShiftB),
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1230
                            lShRed = __intVal(shiftRed),
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1231
                            lShGreen = __intVal(shiftGreen),
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1232
                            lShBlue = __intVal(shiftBlue);
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1233
                        int x, y, w;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1234
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1235
                        unsigned char *srcPtr = _ByteArrayInstPtr(_INST(bytes))->ba_element;
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1236
                        unsigned char *dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1237
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1238
                        w = __intVal(_INST(width));
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1239
                        if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1240
                            for (y=__intVal(_INST(height)); y > 0; y--) {
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1241
                                for (x=w; x > 0; x--) {
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1242
                                    unsigned v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1243
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1244
                                    v = srcPtr[0] << lShRed;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1245
                                    v |= (srcPtr[1] << lShGreen);
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1246
                                    v |= (srcPtr[2] << lShBlue);
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1247
                                    dstPtr[0] = v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1248
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1249
                                    dstPtr += 1;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1250
                                    srcPtr += 3;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1251
                                }
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1252
                            }
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1253
                        } else {
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1254
                            for (y=__intVal(_INST(height)); y > 0; y--) {
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1255
                                for (x=w; x > 0; x--) {
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1256
                                    unsigned r, g, b, v;
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1257
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1258
                                    r = srcPtr[0] >> rShRed;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1259
                                    g = srcPtr[1] >> rShGreen;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1260
                                    b = srcPtr[2] >> rShBlue;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1261
                                    v = r << lShRed;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1262
                                    v |= (g << lShGreen);
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1263
                                    v |= (b << lShBlue);
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1264
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1265
                                    dstPtr[0] = v;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1266
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1267
                                    dstPtr += 1;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1268
                                    srcPtr += 3;
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1269
                                }
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1270
                            }
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1271
                        }
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1272
                    }
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1273
%}.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1274
                ]
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1275
            ].
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1276
        ]
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1277
    ].
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1278
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1279
    imageBits isNil ifTrue:[            
856
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1280
        'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint.
9f802d4d0c1a support 8-bit rgb displays
Claus Gittinger <cg@exept.de>
parents: 842
diff changeset
  1281
        usedDeviceBitsPerPixel errorPrintCR.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1282
        ^ self asMonochromeFormOn:aDevice
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1283
    ].
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1284
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1285
    form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1286
    form isNil ifTrue:[
1177
e89408c15bb5 newStyle info & error messages
Claus Gittinger <cg@exept.de>
parents: 1167
diff changeset
  1287
        'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1288
        ^ nil
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1289
    ].
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1290
    form initGC.
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1291
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1292
    form 
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1293
        copyBitsFrom:imageBits bitsPerPixel:usedDeviceBitsPerPixel depth:usedDeviceDepth 
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1294
               width:width height:height 
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  1295
                   x:0 y:0 toX:0 y:0. 
194
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1296
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1297
    ^ form
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1298
Claus Gittinger <cg@exept.de>
parents: 151
diff changeset
  1299
    "Modified: 21.10.1995 / 19:30:11 / cg"
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1300
! !
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1301
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1302
!Depth24Image methodsFor:'dither helpers'!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1303
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1767
diff changeset
  1304
floydSteinbergDitheredGrayBitsDepth:depth
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1767
diff changeset
  1305
    "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
  1306
     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
  1307
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1308
    |dstIndex        "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1309
     nextDst         "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1310
     bytesPerRow     "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1311
     bytesPerOutRow  "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1312
     outBits greyMap1 greyMap2 greyLevels 
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1313
     errorArray
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1314
     errorArray1
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1315
     e t v
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1316
     w               "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1317
     h               "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1318
     bitCnt          "{Class: SmallInteger }"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1319
     byte            "{Class: SmallInteger }" 
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1320
     grey dT 
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1321
     eR eRB eB eLB |
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1322
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1323
    (samplesPerPixel ~~ 3
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1324
    or:[bitsPerSample ~= #(8 8 8)]) ifTrue:[
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1767
diff changeset
  1325
        ^ super floydSteinbergDitheredGrayBitsDepth:depth
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1326
    ].
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1327
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1328
    w := width.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1329
    h := height.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1330
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1331
    bytesPerRow := self bytesPerRow.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1332
    bytesPerOutRow := ((w * depth) + 7) // 8.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1333
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1334
    (outBits isNil or:[bytes isNil]) ifTrue:[
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1335
        ^ nil
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1336
    ].
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1337
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1338
    greyLevels := (1 bitShift:depth) - 1.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1339
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1340
    greyMap1 := Array new:256.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1341
    greyMap2 := Array new:256.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1342
    1 to:256 do:[:i |
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1343
        v := (greyLevels / 255 * (i-1)).
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1344
        greyMap1 at:i put:v.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1345
        greyMap2 at:i put:v.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1346
    ].
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1347
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1348
    greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1349
                                            0
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1350
                                        ] ifFalse:[
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1351
                                            b truncated
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1352
                                        ]
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1353
                                  ]) asByteArray.      
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1354
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1355
    greyMap2 := (greyMap2 collect:[:el | 
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1356
                                        el isNil ifTrue:[
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1357
                                            0
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1358
                                        ] ifFalse:[
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1359
                                            ((el - el truncated)  "/ the error (0..1)
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1360
                                            * 255) rounded
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1361
                                        ]]) asByteArray.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1362
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1363
    errorArray := ByteArray new:(w + 2) * 2.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1364
    errorArray1 := ByteArray new:(w + 2) * 2.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1365
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1366
%{
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1367
    int __byte;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1368
    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
  1369
    int __depth = __intVal(depth);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1370
    int __dstIdx = 0;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1371
    int __srcIdx = 0;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1372
    int __bitCnt;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1373
    int __grey;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1374
    int __w = __intVal(w);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1375
    int __h = __intVal(h);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1376
    int __x;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1377
    int __y;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1378
    int __nextDst;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1379
    int __nextSrc;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1380
    int __bytesPerRow = __intVal(bytesPerRow);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1381
    int __bytesPerOutRow = __intVal(bytesPerOutRow);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1382
    int __pixel;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1383
    int __greyLevels = __intVal(greyLevels);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1384
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1385
    unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1386
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1387
    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
  1388
    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
  1389
    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
  1390
    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
  1391
    short *__t;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1392
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1393
    bzero(errorArray1, (__w+2) * 2);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1394
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1395
    __bitCnt = 8;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1396
    for (__y=0; __y<__h; __y++) {
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1397
        __nextDst = __dstIdx + __bytesPerOutRow;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1398
        __nextSrc = __srcIdx + __bytesPerRow;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1399
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1400
        __byte = 0;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1401
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1402
        __t = __errorArray;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1403
        __errorArray = __errorArray1;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1404
        __errorArray1 = __t;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1405
        bzero(errorArray1, (__w+2) * 2);
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1406
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1407
        for (__x=0; __x<__w; __x++) {
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1408
            __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1409
                     + (__bytes[__srcIdx+1] * 6)
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1410
                     + __bytes[__srcIdx+2];   
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1411
            __grey = __grey / 10;                      /* 0 .. 255 */
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1412
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1413
            __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1414
            __err = __greyMap2[__grey];              /* 0.. 255 - error) */
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1415
            __err += __errorArray[__x+1];
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1416
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1417
            if (__err > 127) {                        /* dither says: next pixel */
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1418
               if ( __pixel != __greyLevels)
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1419
                    __pixel++;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1420
                __err = __err - 255;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1421
            } else {
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1422
            }
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1423
            if (__err) {
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1424
                __e16 = __err >> 4;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1425
                __eR = __e16 * 7;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1426
                __eRB = __e16 * 1;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1427
                __eB = __e16 * 5;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1428
                __eLB = __err - __eR - __eRB - __eB;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1429
                
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1430
                __errorArray [__x+1+1] += __eR;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1431
                __errorArray1[__x+1+1] += __eRB;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1432
                __errorArray1[__x+1  ] += __eB;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1433
                __errorArray1[__x+1-1] += __eLB;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1434
            }
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1435
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1436
            __srcIdx += 3;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1437
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1438
            __byte = (__byte << __depth) | __pixel;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1439
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1440
            __bitCnt = __bitCnt - __depth;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1441
            if (__bitCnt == 0) {
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1442
                __outBits[__dstIdx] = __byte;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1443
                __dstIdx++;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1444
                __byte = 0;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1445
                __bitCnt = 8;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1446
            }
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1447
        }
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1448
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1449
        if (__bitCnt != 8) {
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1450
            __byte = __byte << __bitCnt;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1451
            __outBits[__dstIdx] = __byte;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1452
            __bitCnt = 8;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1453
        }
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1454
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1455
        __srcIdx = __nextSrc;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1456
        __dstIdx = __nextDst;
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1457
    }
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1458
%}.
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1459
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1460
    ^ outBits
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1461
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1462
    "Created: 10.6.1996 / 13:28:22 / cg"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1463
    "Modified: 10.6.1996 / 15:09:07 / cg"
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1464
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1465
!
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1466
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1467
floydSteinbergDitheredMonochromeBits
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1468
    "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
  1469
     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
  1470
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1471
1779
34f9e24f330e method rename
Claus Gittinger <cg@exept.de>
parents: 1767
diff changeset
  1472
    ^ self floydSteinbergDitheredGrayBitsDepth:1
842
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1473
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1474
    "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
  1475
!
dc8aa9127b49 added conversion for rgb -> greyScale using floyd-steinberg dither
Claus Gittinger <cg@exept.de>
parents: 816
diff changeset
  1476
1782
a1d67a9456ea method rename
Claus Gittinger <cg@exept.de>
parents: 1779
diff changeset
  1477
orderedDitheredGrayBitsWithDitherMatrix:ditherMatrix ditherWidth:dW depth:depth
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1478
    "return the bitmap for a dithered depth-bitmap from the image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1479
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1480
     Redefined to make use of knowing that pixels are 24-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1481
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1482
    |f dH nDither v range  
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1483
     greyMap1 greyMap2 greyLevels outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1484
     bytesPerOutRow  "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1485
     bytesPerRow     "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1486
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1487
     h               "{Class: SmallInteger }"|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1488
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1489
    photometric ~~ #rgb ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1490
        self error:'invalid format'.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1491
        ^ nil
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1492
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1493
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1494
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1495
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1496
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1497
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1498
    h := height.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1499
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1500
    greyLevels := 1 bitShift:depth.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1501
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1502
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1503
    bytesPerOutRow := (w * depth + 7) // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1504
    outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1505
    (outBits isNil or:[bytes isNil]) ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1506
        ^ nil
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1507
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1508
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1509
    greyMap1 := Array new:256.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1510
    greyMap2 := Array new:256.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1511
    range := greyLevels-1.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1512
    1 to:256 do:[:i |
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1513
        v := (range / 255 * (i-1)).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1514
        greyMap1 at:i put:v.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1515
        greyMap2 at:i put:v.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1516
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1517
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1518
    greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1519
                                            0
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1520
                                        ] ifFalse:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1521
                                            b truncated
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1522
                                        ]
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1523
                                  ]) asByteArray.      
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1524
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1525
    greyMap2 := (greyMap2 collect:[:el | 
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1526
                                        el isNil ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1527
                                            0
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1528
                                        ] ifFalse:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1529
                                            ((el - el truncated)  "/ the error (0..1)
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1530
                                            * nDither) rounded
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1531
                                        ]]) asByteArray.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1532
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1533
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1534
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1535
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1536
    int __nDither = __intVal(nDither);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1537
    int __dT, __dO;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1538
    int __depth = __intVal(depth);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1539
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1540
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1541
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1542
    int __grey;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1543
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1544
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1545
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1546
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1547
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1548
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1549
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1550
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1551
    int __bytesPerOutRow = __intVal(bytesPerOutRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1552
    int __pixel;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1553
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1554
    unsigned char *__outBits = __ByteArrayInstPtr(outBits)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1555
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1556
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1557
    unsigned char *__greyMap1 = __ByteArrayInstPtr(greyMap1)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1558
    unsigned char *__greyMap2 = __ByteArrayInstPtr(greyMap2)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1559
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1560
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1561
    for (__y=0; __y<__h; __y++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1562
        __nextDst = __dstIdx + __bytesPerOutRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1563
        __nextSrc = __srcIdx + __bytesPerRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1564
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1565
        __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1566
        __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1567
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1568
        __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1569
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1570
        for (__x=0; __x<__w; __x++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1571
            __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1572
                     + (__bytes[__srcIdx+1] * 6)
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1573
                     + __bytes[__srcIdx+2];   
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1574
            __grey = __grey / 10;                      /* 0 .. 255 */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1575
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1576
            __pixel = __greyMap1[__grey];            /* 0..(greyLevels-1) */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1577
            __dO    = __greyMap2[__grey];            /* 0.. nDither-1) */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1578
            __dT = __ditherMatrix[__dY + __oX];
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1579
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1580
            if (__dO > __dT)                         /* dither says: next pixel */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1581
                __pixel++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1582
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1583
            __srcIdx += 3;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1584
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1585
            __oX++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1586
            if (__oX == __dW) __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1587
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1588
            __byte = (__byte << __depth) | __pixel;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1589
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1590
            __bitCnt = __bitCnt - __depth;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1591
            if (__bitCnt == 0) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1592
                __outBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1593
                __dstIdx++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1594
                __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1595
                __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1596
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1597
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1598
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1599
        if (__bitCnt != 8) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1600
            __byte = __byte << __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1601
            __outBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1602
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1603
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1604
        __oY++; __dY += __dW;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1605
        if (__oY == __dH) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1606
            __oY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1607
            __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1608
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1609
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1610
        __srcIdx = __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1611
        __dstIdx = __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1612
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1613
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1614
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1615
    ^ outBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1616
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1617
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1618
     |i|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1619
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1620
     i := Image fromFile:'bitmaps/granite.tiff'.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1621
     i asOrderedDitheredMonochromeImage inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1622
     i asOrderedDitheredDepth2GrayImage inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1623
     i asOrderedDitheredDepth4GrayImage inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1624
     i asOrderedDitheredDepth8GrayImage inspect.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1625
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1626
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1627
    "Created: 7.6.1996 / 10:48:06 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1628
    "Modified: 7.6.1996 / 11:08:50 / cg"
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1629
!
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1630
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1631
orderedDitheredMonochromeBitsWithDitherMatrix:ditherMatrix ditherWidth:dW
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1632
    "return the dithered monochrome bits for the receiver image;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1633
     with a constant ditherMatrix, this can be used for thresholding.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1634
     Redefined to make use of knowing that pixels are 24-bit values."
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1635
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1636
    |f dH nDither   
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1637
     greyMap monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1638
     bytesPerMonoRow "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1639
     bytesPerRow     "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1640
     w               "{Class: SmallInteger }"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1641
     h               "{Class: SmallInteger }"|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1642
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1643
    photometric ~~ #rgb ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1644
        self error:'invalid format'.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1645
        ^ nil
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1646
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1647
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1648
    nDither := ditherMatrix size.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1649
    dH := nDither / dW.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1650
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1651
    w := width.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1652
    h := height.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1653
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1654
    bytesPerRow := self bytesPerRow.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1655
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1656
    bytesPerMonoRow := w + 7 // 8.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1657
    monoBits := ByteArray uninitializedNew:(bytesPerMonoRow * h).
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1658
    (monoBits isNil or:[bytes isNil]) ifTrue:[
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1659
        ^ nil
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1660
    ].
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1661
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1662
%{
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1663
    int __dW = __intVal(dW);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1664
    int __dH = __intVal(dH);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1665
    int __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1666
    int __nDither = __intVal(nDither);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1667
    int __dT;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1668
    int __dstIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1669
    int __srcIdx = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1670
    int __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1671
    int __grey;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1672
    int __w = __intVal(w);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1673
    int __h = __intVal(h);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1674
    int __x;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1675
    int __y;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1676
    int __oX, __oY, __dY;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1677
    int __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1678
    int __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1679
    int __bytesPerRow = __intVal(bytesPerRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1680
    int __bytesPerMonoRow = __intVal(bytesPerMonoRow);
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1681
1812
beeaf75b245b avoid type warnings (char * vs. unsigned char *)
Claus Gittinger <cg@exept.de>
parents: 1782
diff changeset
  1682
    unsigned char *__monoBits = __ByteArrayInstPtr(monoBits)->ba_element;
810
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1683
    unsigned char *__ditherMatrix = __ByteArrayInstPtr(ditherMatrix)->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1684
    unsigned char *__bytes = __ByteArrayInstPtr(__INST(bytes))->ba_element;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1685
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1686
    __oY = __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1687
    for (__y=0; __y<__h; __y++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1688
        __nextDst = __dstIdx + __bytesPerMonoRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1689
        __nextSrc = __srcIdx + __bytesPerRow;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1690
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1691
        __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1692
        __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1693
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1694
        __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1695
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1696
        for (__x=0; __x<__w; __x++) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1697
            __grey = (__bytes[__srcIdx] * 3)           /* 0.3*r + 0.6*g + b -> 0..2550 */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1698
                     + (__bytes[__srcIdx+1] * 6)
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1699
                     + __bytes[__srcIdx+2];   
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1700
            __grey = __grey * (__nDither+1) / 2550;    /* 0 .. nDither+1 */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1701
            __srcIdx += 3;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1702
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1703
            __dT = __ditherMatrix[__dY + __oX];
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1704
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1705
            __oX++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1706
            if (__oX == __dW) __oX = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1707
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1708
            __byte = __byte << 1;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1709
            if (__grey > __dT) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1710
                __byte = __byte | 1;                   /* white */
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1711
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1712
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1713
            __bitCnt--;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1714
            if (__bitCnt == 0) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1715
                __monoBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1716
                __dstIdx++;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1717
                __byte = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1718
                __bitCnt = 8;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1719
            }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1720
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1721
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1722
        if (__bitCnt != 8) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1723
            __byte = __byte << __bitCnt;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1724
            __monoBits[__dstIdx] = __byte;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1725
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1726
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1727
        __oY++; __dY += __dW;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1728
        if (__oY == __dH) {
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1729
            __oY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1730
            __dY = 0;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1731
        }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1732
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1733
        __srcIdx = __nextSrc;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1734
        __dstIdx = __nextDst;
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1735
    }
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1736
%}.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1737
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1738
    ^ monoBits
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1739
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1740
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1741
     |i f|
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1742
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1743
     i := Image fromFile:'bitmaps/granite.tiff'.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1744
     f := i asOrderedDitheredMonochromeFormOn:Display.
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1745
    "
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1746
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1747
    "Created: 7.6.1996 / 10:48:06 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1748
    "Modified: 7.6.1996 / 11:08:50 / cg"
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1749
!
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1750
9789d836dbc4 more dithering
Claus Gittinger <cg@exept.de>
parents: 808
diff changeset
  1751
threshold8BitGrayBits
808
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1752
    "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
  1753
     Special code, since this is a common case."
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1754
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1755
    |greyBits
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1756
     srcIndex "{ Class: SmallInteger }"
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1757
     dstIndex "{ Class: SmallInteger }"|
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1758
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1759
    greyBits := ByteArray uninitializedNew:(width * height).
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1760
%{
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1761
    register unsigned char *srcPtr, *dstPtr;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1762
    register __v;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1763
    register i;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1764
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1765
    if ((__Class(__INST(bytes)) == ByteArray)
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1766
     && (__Class(greyBits) == ByteArray)) {
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1767
        srcPtr = __ByteArrayInstPtr(__INST(bytes))->ba_element;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1768
        dstPtr = __ByteArrayInstPtr(greyBits)->ba_element;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1769
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1770
        i = __intVal(__INST(height)) * __intVal(__INST(width));
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1771
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1772
        for (; i > 0; i--) {
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1773
            __v = (srcPtr[0] * 3);     /* 3*r + 6*g + b ; 0 .. 2550 */
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1774
            __v += (srcPtr[1] * 6);
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1775
            __v += srcPtr[2];
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1776
            srcPtr += 3;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1777
            __v /= 10;                 /* 0..255 */
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1778
            *dstPtr++ = __v ;
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1779
        }
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1780
    }
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1781
%}.
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1782
    ^ greyBits
f548a3c6ca8c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 807
diff changeset
  1783
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1784
! !
304f026e10cd Initial revision
claus
parents:
diff changeset
  1785
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1786
!Depth24Image methodsFor:'enumerating'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1787
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1788
colorsAtY:y from:xLow to:xHigh do:aBlock
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1789
    "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
  1790
     The block is passed the color at each pixel.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1791
     This method allows slighly faster processing of an
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1792
     image than using atX:y:, since some processing can be
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1793
     avoided when going from pixel to pixel. However, for
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1794
     real image processing, specialized methods should be written."
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1795
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1796
    |srcIndex "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1797
     x1       "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1798
     x2       "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1799
     rVal     "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1800
     gVal     "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1801
     bVal     "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1802
     lastR lastG lastB lastColor|
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1803
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1804
    photometric ~~ #rgb ifTrue:[
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  1805
        ^ super colorsAtY:y from:xLow to:xHigh do:aBlock.
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1806
    ].
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1807
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1808
    x1 := xLow.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1809
    x2 := xHigh.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1810
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1811
    srcIndex := 1 + (((width * y) + x1) * 3).
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1812
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1813
    x1 to:x2 do:[:x |
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1814
        rVal := bytes at:(srcIndex).
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1815
        gVal := bytes at:(srcIndex + 1).
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1816
        bVal := bytes at:(srcIndex + 2).
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1817
        srcIndex := srcIndex + 3.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1818
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1819
        (rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
1350
3fced8a1576c *** empty log message ***
ca
parents: 1237
diff changeset
  1820
            lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal * 100 / 255.
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1821
            lastR := rVal.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1822
            lastG := gVal.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1823
            lastB := bVal.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1824
        ].
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1825
        aBlock value:x value:lastColor
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1826
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1827
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1828
    "Created: 7.6.1996 / 19:12:28 / cg"
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  1829
    "Modified: 8.6.1996 / 10:16:51 / cg"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1830
!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1831
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1832
valuesAtY:y from:xLow to:xHigh do:aBlock
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1833
    "perform aBlock for each pixelValue from x1 to x2 in row y.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1834
     The block is passed the pixelValue at each pixel.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1835
     This method allows slighly faster processing of an
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1836
     image than using valueAtX:y:, since some processing can be
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1837
     avoided when going from pixel to pixel. However, for
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1838
     real image processing, specialized methods should be written.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1839
     Notice that the pixelValue is the r/g/b value packed into an integer
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1840
     (r bitShift:16) bitOr:(g bitSHift:8) bitOr:b"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1841
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1842
    |srcIndex "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1843
     x1       "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1844
     x2       "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1845
     r        "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1846
     g        "{ Class: SmallInteger }"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1847
     b        "{ Class: SmallInteger }"|
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1848
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1849
    x1 := xLow.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1850
    x2 := xHigh.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1851
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1852
    srcIndex := 1 + (((width * y) + x1) * 3).
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1853
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1854
    x1 to:x2 do:[:x |
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1855
        r := bytes at:(srcIndex).
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1856
        g := bytes at:(srcIndex + 1).
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1857
        b := bytes at:(srcIndex + 2).
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1858
        srcIndex := srcIndex + 3.
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1859
        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
  1860
    ]
798
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1861
31ed4a1d4b4a better dither
Claus Gittinger <cg@exept.de>
parents: 746
diff changeset
  1862
    "Created: 7.6.1996 / 19:09:40 / cg"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1863
! !
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1864
1767
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1865
!Depth24Image methodsFor:'image manipulations'!
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1866
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1867
negative
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1868
    |index newImage newBytes nBytes r g b|
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1869
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1870
    photometric ~~ #rgb ifTrue:[
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1871
        ^ super negative.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1872
    ].
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1873
    newImage := self copy.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1874
    nBytes := bytes size.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1875
    newImage bits:(newBytes := ByteArray new:nBytes).
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1876
    index := 1.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1877
    [index < nBytes] whileTrue:[
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1878
        r := bytes at:index.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1879
        newBytes at:index put:(255-r).
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1880
        index := index + 1.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1881
        g := bytes at:index.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1882
        newBytes at:index put:(255-g).
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1883
        index := index + 1.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1884
        b := bytes at:index.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1885
        newBytes at:index put:(255-b).
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1886
        index := index + 1.
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1887
    ].
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1888
    ^ newImage
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1889
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1890
    "Modified: 23.6.1997 / 09:57:19 / cg"
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1891
! !
a043a8417e73 #negative
Claus Gittinger <cg@exept.de>
parents: 1738
diff changeset
  1892
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  1893
!Depth24Image methodsFor:'magnification'!
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  1894
1738
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1895
hardAntiAliasedMagnifiedBy:scalePoint
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1896
    "return a new image magnified by scalePoint, aPoint.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1897
     This interpolates pixels and is therefore slower."
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1898
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1899
    |mX        
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1900
     mY        
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1901
     newWidth  "{ Class: SmallInteger }"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1902
     newHeight "{ Class: SmallInteger }"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1903
     w         "{ Class: SmallInteger }"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1904
     h         "{ Class: SmallInteger }"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1905
     newImage newBits bitsPerPixel newBytesPerRow newMask
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1906
     value 
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1907
     srcRow pixelArray|
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1908
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1909
    mX := scalePoint x.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1910
    mY := scalePoint y.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1911
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1912
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1913
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1914
    newWidth := (width * mX) truncated.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1915
    newHeight := (height * mY) truncated.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1916
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1917
    bitsPerPixel := self depth.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1918
    newBytesPerRow := ((newWidth * bitsPerPixel) + 7) // 8.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1919
    newBits := ByteArray new: "uninitializedNew:" (newBytesPerRow * newHeight).
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1920
    newBits isNil ifTrue:[self halt].
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1921
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1922
    mask notNil ifTrue:[
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1923
        newMask := (mask magnifiedBy:scalePoint)
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1924
    ].
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1925
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1926
    newImage := self species new.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1927
    newImage 
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1928
        width:newWidth 
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1929
        height:newHeight 
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1930
        photometric:photometric 
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1931
        samplesPerPixel:samplesPerPixel 
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1932
        bitsPerSample:bitsPerSample 
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1933
        colorMap:colorMap copy
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1934
        bits:newBits
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1935
        mask:newMask.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1936
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1937
    mY := mY asFloat.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1938
    mX := mX asFloat.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1939
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1940
%{
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1941
    REGISTER unsigned char *_dstP = __ByteArrayInstPtr(newBits)->ba_element;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1942
    unsigned char *_srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1943
    unsigned char *_srcRowP, *sP;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1944
    int _width3 = __intVal(_INST(width)) * 3;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1945
    int _oldW = __intVal(_INST(width)) - 1;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1946
    int _oldH = __intVal(_INST(height)) - 1;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1947
    int _w = __intVal(newWidth) - 1;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1948
    int _h = __intVal(newHeight) - 1;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1949
    int _row, _col;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1950
    double _mX = __floatVal(mX);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1951
    double _mY = __floatVal(mY);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1952
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1953
    for (_row = 0; _row <= _h; _row++) {
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1954
        double _srcY;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1955
        double _dY;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1956
        int _sR;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1957
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1958
        _srcY = ((double)_row / _mY);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1959
        _sR = (int)_srcY;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1960
        _dY = _srcY - ((double)_sR);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1961
        _srcRowP = _srcP + (_width3 * _sR);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1962
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1963
        for (_col = 0; _col <= _w; _col++) {
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1964
            unsigned int rHere, gHere, bHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1965
            unsigned int rRight, gRight, bRight;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1966
            unsigned int rRightBelow, gRightBelow, bRightBelow;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1967
            unsigned int rBelow, gBelow, bBelow;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1968
            unsigned int _r, _g, _b;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1969
            double wHere, wRight, wRightBelow, wBelow, sumW;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1970
            double _srcX;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1971
            double _dX;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1972
            int _sC;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1973
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1974
            _srcX = ((double)_col / _mX);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1975
            _sC = (int)_srcX;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1976
            _dX = _srcX - ((double)_sC);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1977
            sP = _srcRowP + (_sC * 3);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1978
        
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1979
            rHere = sP[0];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1980
            gHere = sP[1];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1981
            bHere = sP[2];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1982
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1983
            if (_sC < _oldW) {
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1984
                rRight = sP[3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1985
                gRight = sP[4];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1986
                bRight = sP[5];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1987
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1988
                if (_sR < _oldH) {
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1989
                    rBelow = sP[0+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1990
                    gBelow = sP[1+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1991
                    bBelow = sP[2+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1992
                    rRightBelow = sP[3+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1993
                    gRightBelow = sP[4+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1994
                    bRightBelow = sP[5+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1995
                } else {
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1996
                    rRightBelow = rHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1997
                    gRightBelow = gHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1998
                    bRightBelow = bHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  1999
                    rBelow = rHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2000
                    gBelow = gHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2001
                    bBelow = bHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2002
                }
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2003
            } else {
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2004
                rRight = rRightBelow = rHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2005
                gRight = gRightBelow = gHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2006
                bRight = bRightBelow = bHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2007
                if (_sR < _oldH) {
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2008
                    rBelow = sP[0+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2009
                    gBelow = sP[1+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2010
                    bBelow = sP[2+_width3];
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2011
                } else {
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2012
                    rBelow = rHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2013
                    gBelow = gHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2014
                    bBelow = bHere;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2015
                }
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2016
            }
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2017
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2018
            wHere = (1.0 - _dX) * (1.0 - _dY);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2019
            wRight = _dX * (1.0 - _dY);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2020
            wBelow = _dY * (1.0 - _dX);
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2021
            wRightBelow = _dX * _dY;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2022
            sumW = wHere + wRight + wBelow + wRightBelow;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2023
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2024
            _r = ((rHere * wHere) + (rRight * wRight) + (rBelow * wBelow) + (rRightBelow * wRightBelow)) / sumW;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2025
            _g = ((gHere * wHere) + (gRight * wRight) + (gBelow * wBelow) + (gRightBelow * wRightBelow)) / sumW;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2026
            _b = ((bHere * wHere) + (bRight * wRight) + (bBelow * wBelow) + (bRightBelow * wRightBelow)) / sumW;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2027
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2028
            _dstP[0] = _r;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2029
            _dstP[1] = _g;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2030
            _dstP[2] = _b;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2031
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2032
            _dstP += 3;
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2033
        }
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2034
    }
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2035
%}.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2036
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2037
    ^ newImage
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2038
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2039
    "
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2040
     |i|
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2041
     i := Image fromFile:'bitmaps/gifImages/garfield.gif'.
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2042
     i hardAntiAliasedMagnifiedBy:2@2
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2043
    "
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2044
    "
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2045
     |i|
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2046
     i := Depth24Image width:3 height:3 fromArray:#[ 0 0 0  0 0 0  0 0 0
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2047
                                                     0 0 0  255 255 255  0 0 0
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2048
                                                     0 0 0  0 0 0  0 0 0].
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2049
     i hardAntiAliasedMagnifiedBy:8@8
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2050
    "
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2051
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2052
    "Modified: 2.6.1997 / 12:28:18 / cg"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2053
    "Created: 2.6.1997 / 13:18:53 / cg"
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2054
!
4f1466e0d379 antiAliasing
Claus Gittinger <cg@exept.de>
parents: 1666
diff changeset
  2055
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2056
hardMagnifiedBy:scalePoint
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2057
    "return a new image magnified by scalePoint, aPoint.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2058
     This is  the general magnification method, handling non-integral values"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2059
304f026e10cd Initial revision
claus
parents:
diff changeset
  2060
    |mX mY
304f026e10cd Initial revision
claus
parents:
diff changeset
  2061
     newWidth  "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2062
     newHeight "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2063
     w         "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2064
     h         "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2065
     newImage newBytes
304f026e10cd Initial revision
claus
parents:
diff changeset
  2066
     value     "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2067
     srcRowIdx "{ Class: SmallInteger }"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2068
     srcIndex  "{ Class: SmallInteger }"
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2069
     dstIndex  "{ Class: SmallInteger }"
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2070
     newMask|
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2071
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2072
    mX := scalePoint x.
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2073
    mY := scalePoint y.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2074
    ((mX < 0) or:[mY < 0]) ifTrue:[^ nil].
304f026e10cd Initial revision
claus
parents:
diff changeset
  2075
    ((mX = 1) and:[mY = 1]) ifTrue:[^ self].
304f026e10cd Initial revision
claus
parents:
diff changeset
  2076
304f026e10cd Initial revision
claus
parents:
diff changeset
  2077
    newWidth := (width * mX) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2078
    newHeight := (height * mY) truncated.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2079
    newBytes := ByteArray uninitializedNew:(newWidth * 3 * newHeight).
304f026e10cd Initial revision
claus
parents:
diff changeset
  2080
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2081
    mask notNil ifTrue:[
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2082
        newMask := (mask magnifiedBy:scalePoint)
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2083
    ].
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2084
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2085
    newImage := self species new.
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2086
    newImage 
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2087
        width:newWidth 
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2088
        height:newHeight 
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2089
        photometric:photometric 
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2090
        samplesPerPixel:samplesPerPixel 
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2091
        bitsPerSample:#(8 8 8) 
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2092
        colorMap:nil
1577
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2093
        bits:newBytes
3d8eedcc0ad8 magnify mask as well.
Claus Gittinger <cg@exept.de>
parents: 1350
diff changeset
  2094
        mask:newMask.
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2095
304f026e10cd Initial revision
claus
parents:
diff changeset
  2096
    "walk over destination image fetching pixels from source image"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2097
304f026e10cd Initial revision
claus
parents:
diff changeset
  2098
    mY := mY asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2099
    mX := mX asFloat.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2100
%{
304f026e10cd Initial revision
claus
parents:
diff changeset
  2101
    REGISTER unsigned char *_dstP = _ByteArrayInstPtr(newBytes)->ba_element;
304f026e10cd Initial revision
claus
parents:
diff changeset
  2102
    unsigned char *_srcP = _ByteArrayInstPtr(_INST(bytes))->ba_element;
304f026e10cd Initial revision
claus
parents:
diff changeset
  2103
    unsigned char *_srcRowP, *sP;
304f026e10cd Initial revision
claus
parents:
diff changeset
  2104
    int _width3 = _intVal(_INST(width)) * 3;
304f026e10cd Initial revision
claus
parents:
diff changeset
  2105
    int _w = _intVal(newWidth) - 1;
304f026e10cd Initial revision
claus
parents:
diff changeset
  2106
    int _h = _intVal(newHeight) - 1;
304f026e10cd Initial revision
claus
parents:
diff changeset
  2107
    int _row, _col;
304f026e10cd Initial revision
claus
parents:
diff changeset
  2108
    double _mX = _floatVal(mX);
304f026e10cd Initial revision
claus
parents:
diff changeset
  2109
    double _mY = _floatVal(mY);
304f026e10cd Initial revision
claus
parents:
diff changeset
  2110
304f026e10cd Initial revision
claus
parents:
diff changeset
  2111
    for (_row = 0; _row <= _h; _row++) {
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2112
        _srcRowP = _srcP + (_width3 * (int)((double)_row / _mY));
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2113
        for (_col = 0; _col <= _w; _col++) {
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2114
            sP = _srcRowP + (((int)((double)_col / _mX)) * 3);
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2115
            _dstP[0] = sP[0];
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2116
            _dstP[1] = sP[1];
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2117
            _dstP[2] = sP[2];
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2118
            _dstP += 3;
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2119
        }
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2120
    }
304f026e10cd Initial revision
claus
parents:
diff changeset
  2121
%}
304f026e10cd Initial revision
claus
parents:
diff changeset
  2122
.
81
4ba554473294 *** empty log message ***
claus
parents: 66
diff changeset
  2123
"   the above C-code is equivalent to:
4ba554473294 *** empty log message ***
claus
parents: 66
diff changeset
  2124
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2125
    dstIndex := 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2126
    w := newWidth - 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2127
    h := newHeight - 1.
304f026e10cd Initial revision
claus
parents:
diff changeset
  2128
    0 to:h do:[:row |
886
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2129
        srcRowIdx := (width * 3 * (row // mY)) + 1.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2130
        0 to:w do:[:col |
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2131
            srcIndex := srcRowIdx + ((col // mX) * 3).
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2132
            value := bytes at:srcIndex.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2133
            newBytes at:dstIndex put:value.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2134
            value := bytes at:(srcIndex + 1).
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2135
            newBytes at:(dstIndex + 1) put:value.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2136
            value := bytes at:(srcIndex + 2).
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2137
            newBytes at:(dstIndex + 2) put:value.
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2138
            dstIndex := dstIndex + 3
04b88b61c640 tuned hardMagnify (there is more to tune there ...)
Claus Gittinger <cg@exept.de>
parents: 858
diff changeset
  2139
        ]
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2140
    ].
304f026e10cd Initial revision
claus
parents:
diff changeset
  2141
"
304f026e10cd Initial revision
claus
parents:
diff changeset
  2142
    ^ newImage
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2143
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2144
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2145
magnifyRowFrom:srcBytes offset:srcStart
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2146
	  into:dstBytes offset:dstStart factor:mX
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2147
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2148
    "magnify a single pixel row - can only magnify by integer factors"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2149
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2150
%{
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2151
    unsigned char *srcP, *dstP;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2152
    int _mag;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2153
    REGISTER int i;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2154
    REGISTER unsigned char byte1, byte2, byte3;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2155
    int _pixels;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2156
    OBJ w = _INST(width);
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2157
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2158
    if (__bothSmallInteger(srcStart, dstStart)
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2159
     && __bothSmallInteger(w, mX)
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2160
     && __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2161
	_mag = _intVal(mX);
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2162
	srcP = _ByteArrayInstPtr(srcBytes)->ba_element - 1 + _intVal(srcStart);
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2163
	dstP = _ByteArrayInstPtr(dstBytes)->ba_element - 1 + _intVal(dstStart);
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2164
	_pixels = _intVal(w);
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2165
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2166
	while (_pixels--) {
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2167
	    byte1 = *srcP;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2168
	    byte2 = *(srcP+1);
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2169
	    byte3 = *(srcP+2);
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2170
	    srcP += 3;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2171
	    for (i=_mag; i>0; i--) {
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2172
		*dstP = byte1;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2173
		*(dstP+1) = byte2;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2174
		*(dstP+2) = byte3;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2175
		dstP += 3;
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2176
	    }
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2177
	}
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2178
	RETURN (self);
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2179
    }
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2180
%}
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2181
.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2182
    self primitiveFailed
1
304f026e10cd Initial revision
claus
parents:
diff changeset
  2183
! !
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2184
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2185
!Depth24Image methodsFor:'queries'!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2186
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2187
bitsPerPixel
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2188
    "return the number of bits per pixel"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2189
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2190
    ^ 24
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2191
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2192
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2193
bitsPerRow
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2194
    "return the number of bits in one scanline of the image"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2195
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2196
    ^  width * 24
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2197
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2198
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2199
bitsPerSample
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2200
    "return the number of bits per sample.
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2201
     The return value is an array of bits-per-plane."
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2202
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  2203
    bitsPerSample notNil ifTrue:[^ bitsPerSample].
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2204
    ^ #(8 8 8)
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  2205
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  2206
    "Modified: 10.6.1996 / 18:02:33 / cg"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2207
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2208
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2209
blueBitsOf:pixel
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2210
    ^ pixel bitAnd:16rFF.
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2211
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2212
    "Created: 8.6.1996 / 09:56:20 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2213
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2214
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2215
blueComponentOf:pixel
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2216
    ^ (100.0 / 255.0) * (pixel bitAnd:16rFF)
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2217
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2218
    "Created: 8.6.1996 / 08:42:44 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2219
    "Modified: 8.6.1996 / 09:57:41 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2220
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2221
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2222
bytesPerRow
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2223
    "return the number of bytes in one scanline of the image"
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2224
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2225
    ^ width * 3
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2226
!
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2227
805
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2228
greenBitsOf:pixel
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2229
    ^ (pixel bitShift:-8) bitAnd:16rFF.
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2230
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2231
    "Modified: 8.6.1996 / 08:56:28 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2232
    "Created: 8.6.1996 / 09:56:30 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2233
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2234
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2235
greenComponentOf:pixel
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2236
    ^ (100.0 / 255.0) * (pixel bitShift:-8) bitAnd:16rFF.
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2237
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2238
    "Created: 8.6.1996 / 08:42:37 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2239
    "Modified: 8.6.1996 / 09:57:32 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2240
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2241
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2242
redBitsOf:pixel
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2243
    ^ (pixel bitShift:-16) bitAnd:16rFF.
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2244
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2245
    "Modified: 8.6.1996 / 08:56:31 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2246
    "Created: 8.6.1996 / 09:56:39 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2247
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2248
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2249
redComponentOf:pixel
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2250
    ^ (100.0 / 255.0) * (pixel bitShift:-16) bitAnd:16rFF.
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2251
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2252
    "Created: 8.6.1996 / 08:42:25 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2253
    "Modified: 8.6.1996 / 09:57:23 / cg"
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2254
!
5573c2078b73 specialized code relaxed
Claus Gittinger <cg@exept.de>
parents: 798
diff changeset
  2255
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2256
samplesPerPixel
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2257
    "return the number of samples per pixel in the image."
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2258
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  2259
    samplesPerPixel notNil ifTrue:[^ samplesPerPixel].
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2260
    ^ 3
813
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  2261
8bc17dba7a02 removed obsolete comversion stuff
Claus Gittinger <cg@exept.de>
parents: 810
diff changeset
  2262
    "Modified: 10.6.1996 / 18:03:09 / cg"
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2263
! !
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2264
1167
4998857f7a9a new infoMessage scheme
Claus Gittinger <cg@exept.de>
parents: 938
diff changeset
  2265
!Depth24Image class methodsFor:'documentation'!
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2266
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2267
version
1818
fd245b7ae2f9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1817
diff changeset
  2268
    ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.56 1997-07-22 10:09:50 cg Exp $'
282
fe2d82f516f1 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 236
diff changeset
  2269
! !