--- a/Colormap.st Fri Apr 25 02:11:27 2003 +0200
+++ b/Colormap.st Mon Apr 28 12:14:49 2003 +0200
@@ -112,8 +112,8 @@
"Modified: 23.4.1996 / 22:16:00 / cg"
!
-rgbVector:rgbVector
- "given a single vector containing r-g-b values,
+rgbBytesVector:rgbVector
+ "given a single vector containing r-g-b byte values,
return a new instance of myself.
The values must be in the range 0..255."
@@ -151,6 +151,44 @@
"
!
+rgbValueVector:rgbValueVector
+ "given a single vector containing r-g-b pixel-values,
+ return a new instance of myself.
+ The values must be of the rgb-form i.e. 16rRRGGBB"
+
+ |rV gV bV nColors|
+
+ nColors := rgbValueVector size.
+ rV := ByteArray new:nColors.
+ gV := ByteArray new:nColors.
+ bV := ByteArray new:nColors.
+
+ 1 to:nColors do:[:index |
+ |rgb r g b|
+
+ rgb := rgbValueVector at:index.
+ r := (rgb bitShift:-16) bitAnd:16rFF.
+ g := (rgb bitShift:-8) bitAnd:16rFF.
+ b := rgb bitAnd:16rFF.
+
+ rV at:index put:r.
+ gV at:index put:g.
+ bV at:index put:b.
+ ].
+
+ ^ self
+ redVector:rV
+ greenVector:gV
+ blueVector:bV
+
+ "
+ |map|
+
+ map := Colormap rgbValueVector:#(16r000000 16r7F7F7F 16r800000 16rFFFFFF).
+ map atPixelValue:2
+ "
+!
+
withColors:aColorArray
"given a sequenceable collection of colors, return a new instance
of myself. Renamed from #fromColors: for ST-80 compatibility."
@@ -478,5 +516,5 @@
!Colormap class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.34 2003-04-10 14:45:19 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Colormap.st,v 1.35 2003-04-28 10:14:49 cg Exp $'
! !
--- a/Image.st Fri Apr 25 02:11:27 2003 +0200
+++ b/Image.st Mon Apr 28 12:14:49 2003 +0200
@@ -2186,43 +2186,16 @@
#( red0 green0 blue0 red1 green1 blue1 ... redN greenN blueN)
where each component must be a byteValue in 0..255."
- |colors rS gS bS|
-
- rS := #[] writeStream.
- gS := #[] writeStream.
- bS := #[] writeStream.
- anArray inGroupsOf:3 do:[:r :g :b | rS nextPut:r. gS nextPut:g. bS nextPut:b.].
- colors := Colormap redVector:(rS contents) greenVector:(gS contents) blueVector:(bS contents).
-
-"/ colors := OrderedCollection new.
-"/
-"/ 1 to: anArray size by: 3 do:
-"/ [:i|
-"/ colors add: (Color redByte: (anArray at: i) greenByte: (anArray at: i + 1) blueByte: (anArray at: i + 2))
-"/ ].
-
- self colorMap: colors
-
- "Modified: / 22.8.1998 / 12:28:43 / cg"
-!
-
-colorMapFromRGBValueArray: anArray
+ self colorMap:(MappedPalette rgbBytesVector:anArray)
+!
+
+colorMapFromRGBValueArray:anArray
"set the colorMap by reading colors from an array with rgb-integer values.
The (integer-)Array argument should be of the form:
- #( rgb0 rgb1 ... rgbN)
+ #( rgb0 rgb1 ... rgbN)
where each element must be an rgbValue in 0..FFFFFF."
- |colors|
-
- colors := OrderedCollection new.
- anArray do:[:rgb|
- colors add: (Color rgbValue:rgb).
- ].
-
- self colorMap: colors
-
- "Created: / 22.8.1998 / 12:27:16 / cg"
- "Modified: / 22.8.1998 / 12:30:22 / cg"
+ self colorMap:(MappedPalette rgbValueVector:anArray)
!
container:aVisualContainer
@@ -5893,14 +5866,74 @@
"Modified: 29.5.1996 / 10:52:36 / cg"
!
-displayOn:aGC x:x y:y
- "draw the receiver in the graphicsContext, aGC.
- Smalltalk-80 compatibility"
-
- aGC displayForm:self x:x y:y.
-
- "Modified: 23.4.1996 / 11:12:31 / cg"
- "Created: 12.5.1996 / 20:14:31 / cg"
+asOrderedDitheredGrayImageDepth:depth
+ "return a dithered depth-x grey image from the receiver image.
+ Uses an 8x8 dithermatrix."
+
+ |dither|
+
+ dither := self class orderedDitherMatrixOfSize:8.
+
+ (depth == 1) ifTrue:[
+ "/ for monochrome, there is highly specialized
+ "/ monochrome dither code available
+
+ ^ Depth1Image
+ width:width
+ height:height
+ fromArray:(
+ self
+ orderedDitheredMonochromeBitsWithDitherMatrix:dither
+ ditherWidth:8)
+ ].
+
+ ^ (self class implementorForDepth:depth)
+ width:width
+ height:height
+ fromArray:(
+ self
+ orderedDitheredGrayBitsWithDitherMatrix:dither
+ ditherWidth:8
+ depth:depth)
+
+ "
+ |i i1 i2 i4 i8|
+
+ i := Image fromFile:'goodies/bitmaps/claus.gif'.
+ i1 := i asOrderedDitheredGrayImageDepth:1.
+ i1 inspect.
+
+ i2 := i asOrderedDitheredGrayImageDepth:2.
+ i2 inspect.
+
+ i4 := i asOrderedDitheredGrayImageDepth:4.
+ i4 inspect.
+
+ i8 := i asOrderedDitheredGrayImageDepth:8.
+ i8 inspect.
+ "
+
+ "
+ |i i1 i2 i4 i8|
+ i := Image fromFile:'goodies/bitmaps/garfield.gif'.
+ i1 := i asOrderedDitheredGrayImageDepth:1.
+ i1 inspect.
+
+ i2 := i asOrderedDitheredGrayImageDepth:2.
+ i2 inspect.
+
+ i4 := i asOrderedDitheredGrayImageDepth:4.
+ i4 inspect.
+
+ i8 := i asOrderedDitheredGrayImageDepth:8.
+ i8 inspect.
+
+ i2 := i8 asOrderedDitheredGrayImageDepth:2.
+ i2 inspect.
+ "
+
+ "Created: 7.6.1996 / 18:03:54 / cg"
+ "Modified: 24.6.1997 / 22:19:36 / cg"
!
displayOn:aGC x:x y:y opaque:opaque
@@ -12174,44 +12207,6 @@
isMSB := ((info at:#byteOrder) == #msbFirst).
- "
- Note: bit- and byte ordering doesn't matter for palette images!!
- "
- photometric ~~ #palette ifTrue:[
- "/
- "/ check if byteorder is what I like (msbFirst)
- "/
-
- "/ now done on-the-fly (see isMSB arg)
-
-"/ (info at:#byteOrder) ~~ #msbFirst ifTrue:[
-"/ bitsPerPixelIn == 16 ifTrue:[
-"/ "/ must swap bytes
-"/ inData swapBytes
-"/ ] ifFalse:[
-"/ bitsPerPixelIn == 32 ifTrue:[
-"/ "/ must swap longs
-"/ inData swapLongs
-"/ ]
-"/ ]
-"/ ].
-
- "/
- "/ check if bitorder is what I like (msbFirst)
- "/
- "/ mhmh - thats not needed
-
-"/ bitOrder := info at:#bitOrder.
-"/ bitOrder ~~ #msbFirst ifTrue:[
-"/ inData
-"/ expandPixels:8
-"/ width:(inData size)
-"/ height:1
-"/ into:inData
-"/ mapping:(ImageReader reverseBits).
-"/ ].
- ].
-
"/
"/ check if bitorder is what I like (msbFirst)
"/
@@ -12250,7 +12245,6 @@
bitsPerPixelIn ~~ bitsPerPixel ifTrue:[
"/ for now, only 32 -> 24 is supported
-
maskR == 0 ifTrue:[
bitsR := device bitsRed.
@@ -12314,11 +12308,6 @@
inData at:dstIndex put:(r bitShift:shR2).
inData at:dstIndex+1 put:(g bitShift:shG2).
inData at:dstIndex+2 put:(b bitShift:shB2).
-"/ word print.
-"/ ' -> ' print.
-"/ (r bitShift:shR2) print.
-"/ ' ' print. (g bitShift:shG2) print.
-"/ ' ' print. (b bitShift:shB2) printCR.
srcIndex := srcIndex + 2.
dstIndex := dstIndex + 3.
@@ -12334,9 +12323,9 @@
]
].
] ifFalse:[
- "
- repad in the buffer
- "
+ "/
+ "/ repad in the buffer
+ "/
1 to:h do:[:hi |
inData replaceFrom:dstRow to:(dstRow + bytesPerLine - 1)
with:tmpData startingAt:srcRow.
@@ -12353,16 +12342,14 @@
].
bytes := inData.
- "info printNL."
-
- "
- if not #palette we are done, the pixel values are the rgb/grey values
- "
+ "/
+ "/ if not #palette we are done, the pixel values are the rgb/grey values
+ "/
photometric == #palette ifTrue:[
- "
- what we have now are the color numbers - still need the r/g/b values.
- find out, which colors are in the picture
- "
+ "/
+ "/ what we have now are the color numbers - still need the r/g/b values.
+ "/ find out, which colors are in the picture
+ "/
usedPixels := inData usedValues.
mapSize := usedPixels max + 1.
@@ -12549,7 +12536,7 @@
!Image class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.334 2003-04-25 00:11:27 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Image.st,v 1.335 2003-04-28 10:14:11 cg Exp $'
! !
Image initialize!