Image.st
changeset 3157 f95dc03365da
parent 3145 be28f5978253
child 3256 77bb9ec36221
equal deleted inserted replaced
3156:38b73e5c08aa 3157:f95dc03365da
  3168 
  3168 
  3169     "Created: 10.6.1996 / 12:34:44 / cg"
  3169     "Created: 10.6.1996 / 12:34:44 / cg"
  3170     "Modified: 12.6.1996 / 13:58:16 / cg"
  3170     "Modified: 12.6.1996 / 13:58:16 / cg"
  3171 !
  3171 !
  3172 
  3172 
       
  3173 asDitheredImageUsing:colors
       
  3174     "return a dithered image from the picture,
       
  3175      using colors in colors for dithering."
       
  3176 
       
  3177     ^ self asDitheredImageUsing:colors depth:self depth
       
  3178 !
       
  3179 
       
  3180 asDitheredImageUsing:colors depth:d
       
  3181     "return a dithered image from the picture,
       
  3182      using colors in colors for dithering."
       
  3183 
       
  3184     |newBits|
       
  3185 
       
  3186     newBits := self floydSteinbergDitheredDepth8BitsColors:colors map:(0 to:colors size - 1).
       
  3187     ^ self class extent:(self extent) depth:d palette:colors bits:newBits
       
  3188 
       
  3189 !
       
  3190 
  3173 asErrorDitheredMonochromeImage
  3191 asErrorDitheredMonochromeImage
  3174     "return an error-diffusion dithered monochrome image from the receiver image."
  3192     "return an error-diffusion dithered monochrome image from the receiver image."
  3175 
  3193 
  3176     DitherAlgorithm == #burkes ifTrue:[
  3194     DitherAlgorithm == #burkes ifTrue:[
  3177         ^ self asBurkesDitheredMonochromeImage
  3195         ^ self asBurkesDitheredMonochromeImage
  5930     "return a floyd-steinberg dithered bitmap from the receiver picture,
  5948     "return a floyd-steinberg dithered bitmap from the receiver picture,
  5931      which must be a depth-8 image. 
  5949      which must be a depth-8 image. 
  5932      This method expects an array of colors to be used for dithering
  5950      This method expects an array of colors to be used for dithering
  5933      (which need not be a colorCubes colors)."
  5951      (which need not be a colorCubes colors)."
  5934 
  5952 
       
  5953     ^ self floydSteinbergDitheredDepth8BitsColors:colors map:nil
       
  5954 
       
  5955 !
       
  5956 
       
  5957 floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
       
  5958     "return a floyd-steinberg dithered bitmap from the receiver picture,
       
  5959      which must be a depth-8 image. 
       
  5960      This method expects an array of colors to be used for dithering
       
  5961      (which need not be a colorCubes colors)."
       
  5962 
  5935     |pseudoBits  
  5963     |pseudoBits  
  5936      rgbBytes 
  5964      rgbBytes 
  5937      ditherRGBBytes ditherColors
  5965      ditherRGBBytes ditherColors
  5938      w       "{Class: SmallInteger }"
  5966      w       "{Class: SmallInteger }"
  5939      h       "{Class: SmallInteger }"
  5967      h       "{Class: SmallInteger }"
  5966 
  5994 
  5967         index := index + 3.
  5995         index := index + 3.
  5968     ].
  5996     ].
  5969 
  5997 
  5970     "/ collect valid ditherColors ...
  5998     "/ collect valid ditherColors ...
  5971 
  5999     aMapOrNil isNil ifTrue:[
  5972     ditherColors := colors select:[:clr | clr notNil].
  6000         ditherColors := colors select:[:clr | clr notNil].
       
  6001     ] ifFalse:[
       
  6002         ditherColors := colors
       
  6003     ].
  5973 
  6004 
  5974     "/ ... and sort by manhatten distance from black
  6005     "/ ... and sort by manhatten distance from black
  5975 
  6006 
  5976     qScramble := #(
  6007     qScramble := #(
  5977                 "/  2rX00X00X00X00
  6008                 "/  2rX00X00X00X00
  6015                                 i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
  6046                                 i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
  6016                                 i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
  6047                                 i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
  6017 
  6048 
  6018                                 i1 < i2
  6049                                 i1 < i2
  6019                     ].
  6050                     ].
  6020     ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
  6051     aMapOrNil isNil ifTrue:[
       
  6052         ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
       
  6053     ] ifFalse:[
       
  6054         ditherIds := aMapOrNil asByteArray
       
  6055     ].
  6021 
  6056 
  6022     "/ build an index table, for fast lookup from manhatten-r-g-b distance
  6057     "/ build an index table, for fast lookup from manhatten-r-g-b distance
  6023     "/ to the position in the colorList
  6058     "/ to the position in the colorList
  6024 
  6059 
  6025     clrLookup := ByteArray new:(4096).
  6060     clrLookup := ByteArray new:(4096).
  6056     1 to:lastColor do:[:pix |
  6091     1 to:lastColor do:[:pix |
  6057         clr := ditherColors at:pix.
  6092         clr := ditherColors at:pix.
  6058         ditherRGBBytes at:index put:(clr redByte).
  6093         ditherRGBBytes at:index put:(clr redByte).
  6059         ditherRGBBytes at:index+1 put:(clr greenByte).
  6094         ditherRGBBytes at:index+1 put:(clr greenByte).
  6060         ditherRGBBytes at:index+2 put:(clr blueByte).
  6095         ditherRGBBytes at:index+2 put:(clr blueByte).
  6061         ditherIds at:pix put:clr colorId.
  6096         aMapOrNil isNil ifTrue:[
  6062 
  6097             ditherIds at:pix put:clr colorId.
       
  6098         ] ifFalse:[
       
  6099             ditherIds at:pix put:(aMapOrNil at:pix).
       
  6100         ].
  6063         index := index + 3.
  6101         index := index + 3.
  6064     ].
  6102     ].
  6065 
  6103 
  6066     pseudoBits := ByteArray uninitializedNew:(width * height).
  6104     pseudoBits := ByteArray uninitializedNew:(width * height).
  6067 
  6105 
 12013 ! !
 12051 ! !
 12014 
 12052 
 12015 !Image class methodsFor:'documentation'!
 12053 !Image class methodsFor:'documentation'!
 12016 
 12054 
 12017 version
 12055 version
 12018     ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.293 2000-01-17 11:22:29 cg Exp $'
 12056     ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.294 2000-01-26 15:36:31 cg Exp $'
 12019 ! !
 12057 ! !
 12020 Image initialize!
 12058 Image initialize!