--- a/Depth24Image.st Tue Mar 23 19:50:36 1999 +0100
+++ b/Depth24Image.st Wed Mar 24 19:51:07 1999 +0100
@@ -768,10 +768,10 @@
depth nColorCells deep nColorsNeeded|
aDevice fixColors notNil ifTrue:[
- "/ no need to look for used colors - dithering anyway ...
+ "/ no need to look for used colors - dithering anyway ...
- f := self rgbImageAsDitheredPseudoFormOn:aDevice.
- f notNil ifTrue:[^ f].
+ f := self rgbImageAsDitheredPseudoFormOn:aDevice.
+ f notNil ifTrue:[^ f].
].
"find used colors; build color-tree"
@@ -790,205 +790,211 @@
'Depth24Image [info]: allocating colors ...' infoPrintCR.
[fit] whileFalse:[
- [fitMap] whileFalse:[
- srcIndex := 1.
- redArray := Array new:256.
+ [fitMap] whileFalse:[
+ srcIndex := 1.
+ redArray := Array new:256.
- "
- find used colors, build [r][g][b] 3-dimensional array
- containing true for used colors
- "
- nColors := 0.
- srcIndex := 1.
- dataSize := bytes size.
- [(srcIndex < dataSize)
- and:[nColors <= nColorCells]] whileTrue:[
+ "
+ find used colors, build [r][g][b] 3-dimensional array
+ containing true for used colors
+ "
+ nColors := 0.
+ srcIndex := 1.
+ dataSize := bytes size.
+ [(srcIndex < dataSize)
+ and:[nColors <= nColorCells]] whileTrue:[
%{
- if (__isByteArray(_INST(bytes))) {
- int sI = __intVal(srcIndex);
- unsigned char *cp = __ByteArrayInstPtr(_INST(bytes))->ba_element;
+ if (__isByteArray(_INST(bytes))) {
+ int sI = __intVal(srcIndex);
+ unsigned char *cp = __ByteArrayInstPtr(_INST(bytes))->ba_element;
- r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1);
- g = __MKSMALLINT((cp[sI] & __intVal(gMask)) + 1);
- b = __MKSMALLINT((cp[sI + 1] & __intVal(bMask)) + 1);
- srcIndex = __MKSMALLINT(sI + 3);
- fast = true;
- } else {
- fast = false;
- }
+ r = __MKSMALLINT((cp[sI - 1] & __intVal(rMask)) + 1);
+ g = __MKSMALLINT((cp[sI] & __intVal(gMask)) + 1);
+ b = __MKSMALLINT((cp[sI + 1] & __intVal(bMask)) + 1);
+ srcIndex = __MKSMALLINT(sI + 3);
+ fast = true;
+ } else {
+ fast = false;
+ }
%}
.
- fast ifFalse:[
- r := bytes at:srcIndex.
- r := (r bitAnd:rMask) + 1.
- srcIndex := srcIndex + 1.
- g := bytes at:srcIndex.
- g := (g bitAnd:gMask) + 1.
- srcIndex := srcIndex + 1.
- b := bytes at:srcIndex.
- b := (b bitAnd:bMask) + 1.
- srcIndex := srcIndex + 1
- ].
+ fast ifFalse:[
+ r := bytes at:srcIndex.
+ r := (r bitAnd:rMask) + 1.
+ srcIndex := srcIndex + 1.
+ g := bytes at:srcIndex.
+ g := (g bitAnd:gMask) + 1.
+ srcIndex := srcIndex + 1.
+ b := bytes at:srcIndex.
+ b := (b bitAnd:bMask) + 1.
+ srcIndex := srcIndex + 1
+ ].
- greenArray := redArray at:r.
- greenArray isNil ifTrue:[
- greenArray := Array new:256.
- redArray at:r put:greenArray
- ].
- blueArray := greenArray at:g.
- blueArray isNil ifTrue:[
- deep ifTrue:[blueArray := Array new:256]
- ifFalse:[blueArray := ByteArray new:256].
- greenArray at:g put:blueArray
- ].
- (blueArray at:b) == 0 ifTrue:[
- blueArray at:b put:1.
- nColors := nColors + 1.
- (nColors > nColorCells) ifTrue:[
+ greenArray := redArray at:r.
+ greenArray isNil ifTrue:[
+ greenArray := Array new:256.
+ redArray at:r put:greenArray
+ ].
+ blueArray := greenArray at:g.
+ blueArray isNil ifTrue:[
+ deep ifTrue:[blueArray := Array new:256]
+ ifFalse:[blueArray := ByteArray new:256].
+ greenArray at:g put:blueArray
+ ].
+ (blueArray at:b) == 0 ifTrue:[
+ blueArray at:b put:1.
+ nColors := nColors + 1.
+ (nColors > nColorCells) ifTrue:[
"/ 'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR.
- srcIndex := dataSize + 1
- ]
- ]
- ].
- nColorsNeeded isNil ifTrue:[
- nColorsNeeded := nColors
- ].
+ srcIndex := dataSize + 1
+ ]
+ ]
+ ].
+ nColorsNeeded isNil ifTrue:[
+ nColorsNeeded := nColors
+ ].
- "again with less color bits if it does not fit colormap"
+ "again with less color bits if it does not fit colormap"
- (nColors <= nColorCells) ifTrue:[
- fitMap := true
- ] ifFalse:[
- "/ must try again - cutting off some bits
- "/ blue bits are snipped off faster.
- (bMask == 2r11111111) ifTrue:[
- bMask := 2r11111100
- ] ifFalse:[
- (bMask == 2r11111100) ifTrue:[
- bMask := 2r11110000
- ] ifFalse:[
- (rMask == 2r11111111) ifTrue:[
- rMask := 2r11111100.
- gMask := 2r11111100.
- ] ifFalse:[
- rMask := (rMask bitShift:1) bitAnd:2r11111111.
- gMask := (gMask bitShift:1) bitAnd:2r11111111.
- bMask := (bMask bitShift:1) bitAnd:2r11111111
- ]
- ]
- ].
+ (nColors <= nColorCells) ifTrue:[
+ fitMap := true
+ ] ifFalse:[
+ "/ must try again - cutting off some bits
+ "/ blue bits are snipped off faster.
+ (bMask == 2r11111111) ifTrue:[
+ bMask := 2r11111100
+ ] ifFalse:[
+ (bMask == 2r11111100) ifTrue:[
+ bMask := 2r11110000
+ ] ifFalse:[
+ (rMask == 2r11111111) ifTrue:[
+ rMask := 2r11111100.
+ gMask := 2r11111100.
+ ] ifFalse:[
+ rMask := (rMask bitShift:1) bitAnd:2r11111111.
+ gMask := (gMask bitShift:1) bitAnd:2r11111111.
+ bMask := (bMask bitShift:1) bitAnd:2r11111111
+ ]
+ ]
+ ].
"/ 'Depth24Image [info]: too many colors; retry with less color resolution' infoPrintCR.
"
'masks:' print. rMask print. ' ' print. gMask print. ' ' print.
bMask printNewline
"
- ]
- ].
+ ]
+ ].
"/ 'Depth24Image [info]: ' infoPrint. nColors infoPrint. ' colors used' infoPrintCR.
- colors := Array new:nColors.
- colorIndex := 1.
+ colors := Array new:nColors.
+ colorIndex := 1.
- "
- now, we have reduced things to the number of colors
- which are theoretically supported by the devices colormap.
- allocate all used colors in walking over true entries in
- the [r][g][b] table - this may still fail,
- if we run out of device colors.
- "
- fit := true.
+ "
+ now, we have reduced things to the number of colors
+ which are theoretically supported by the devices colormap.
+ allocate all used colors in walking over true entries in
+ the [r][g][b] table - this may still fail,
+ if we run out of device colors.
+ "
+ fit := true.
- r := 0.
- redArray do:[:greenArray |
- (fit and:[greenArray notNil]) ifTrue:[
- g := 0.
- greenArray do:[:blueArray |
- (fit and:[blueArray notNil]) ifTrue:[
- b := 0.
- blueArray do:[:present |
- |id|
+ r := 0.
+ redArray do:[:greenArray |
+ (fit and:[greenArray notNil]) ifTrue:[
+ g := 0.
+ greenArray do:[:blueArray |
+ (fit and:[blueArray notNil]) ifTrue:[
+ b := 0.
+ blueArray do:[:present |
+ |id|
- (fit and:[present ~~ 0]) ifTrue:[
- color := Color redByte:r
- greenByte:g
- blueByte:b.
- color := color on:aDevice.
- (id := color colorId) isNil ifTrue:[
- fit := false
- ] ifFalse:[
- colors at:colorIndex put:color.
- colorIndex := colorIndex + 1.
- blueArray at:(b + 1) put:id
- ]
- ].
- b := b + 1
- ]
- ].
- g := g + 1
- ]
- ].
- r := r + 1
- ].
+ (fit and:[present ~~ 0]) ifTrue:[
+ color := Color redByte:r
+ greenByte:g
+ blueByte:b.
+ color := color on:aDevice.
+ (id := color colorId) isNil ifTrue:[
+ fit := false
+ ] ifFalse:[
+ colors at:colorIndex put:color.
+ colorIndex := colorIndex + 1.
+ blueArray at:(b + 1) put:id
+ ]
+ ].
+ b := b + 1
+ ]
+ ].
+ g := g + 1
+ ]
+ ].
+ r := r + 1
+ ].
- "again with less color bits if we did not get all colors"
+ "again with less color bits if we did not get all colors"
- fit ifFalse:[
+ fit ifFalse:[
"/ 'Depth24Image [info]: could not allocate color(s)' infoPrintCR.
- "free the allocated colors"
- colors atAllPut:nil.
- "a kludge - force immediate freeing of colors"
- ObjectMemory scavenge; finalize.
+ "free the allocated colors"
+ colors atAllPut:nil.
+ "a kludge - force immediate freeing of colors"
+ ObjectMemory scavenge; finalize.
- "cut off one more color-bit - cut off blue first"
- (bMask == 2r11111111) ifTrue:[
- bMask := 2r11111100
- ] ifFalse:[
- (bMask == 2r11111100) ifTrue:[
- bMask := 2r11110000
- ] ifFalse:[
- (rMask == 2r11111111) ifTrue:[
- rMask := 2r11111100.
- gMask := 2r11111100.
- ] ifFalse:[
- rMask := (rMask bitShift:1) bitAnd:2r11111111.
- gMask := (gMask bitShift:1) bitAnd:2r11111111.
- bMask := (bMask bitShift:1) bitAnd:2r11111111
- ]
- ]
- ].
- fitMap := false.
- redArray := nil
- ]
+ "cut off one more color-bit - cut off blue first"
+ (bMask == 2r11111111) ifTrue:[
+ bMask := 2r11111100
+ ] ifFalse:[
+ (bMask == 2r11111100) ifTrue:[
+ bMask := 2r11110000
+ ] ifFalse:[
+ (rMask == 2r11111111) ifTrue:[
+ rMask := 2r11111100.
+ gMask := 2r11111100.
+ ] ifFalse:[
+ rMask := (rMask bitShift:1) bitAnd:2r11111111.
+ gMask := (gMask bitShift:1) bitAnd:2r11111111.
+ bMask := (bMask bitShift:1) bitAnd:2r11111111
+ ]
+ ]
+ ].
+ fitMap := false.
+ redArray := nil
+ ]
].
(nColors ~~ nColorsNeeded) ifTrue:[
- "/ mhmh - did not get all colors ...
- "/ add existing colors and dither.
+ "/ mhmh - did not get all colors ...
+ "/ add existing colors and dither.
- 'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint.
- nColorsNeeded infoPrint. ' image colors.' infoPrintCR.
+ 'Depth24Image [info]: only got ' infoPrint. nColors infoPrint. ' out of ' infoPrint.
+ nColorsNeeded infoPrint. ' image colors.' infoPrintCR.
- "/
- "/ dither using those we got ...
- "/
- DitherAlgorithm == #floydSteinberg ifTrue:[
- colors := colors asSet.
+ "/
+ "/ dither using those we got ...
+ "/
+ DitherAlgorithm == #floydSteinberg ifTrue:[
+ colors := colors asSet.
"/ ditherColors := aDevice availableDitherColors.
"/ ditherColors notNil ifTrue:[
"/ colors addAll:ditherColors.
"/ ].
"/ colors addAll:aDevice deviceColors.
- colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]).
- colors := colors select:[:c | c colorId notNil].
- colors := colors asArray.
- colors size > 256 ifTrue:[
- colors := colors copyTo:256
- ].
- f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors.
- f notNil ifTrue:[^ f].
- ].
+ colors addAll:(aDevice colorMap collect:[:c|c onDevice:aDevice]).
+ colors := colors select:[:c | c colorId notNil].
+ colors := colors asArray.
+ colors size > 256 ifTrue:[
+ colors := colors copyTo:256
+ ].
+ f := self rgbImageAsDitheredPseudoFormOn:aDevice colors:colors.
+ f notNil ifTrue:[^ f].
+ ].
+ ].
+
+ "/ the device ought to support 8-bit images ...
+ (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
+ "/ cannot draw directly
+ ^ nil
].
"create pseudocolor bits and translate"
@@ -1001,34 +1007,34 @@
(rMask == 2r11111111
and:[gMask == 2r11111111
and:[bMask == 2r11111111]]) ifTrue:[
- [srcIndex < dataSize] whileTrue:[
- r := bytes at:srcIndex.
- srcIndex := srcIndex + 1.
- g := bytes at:srcIndex.
- srcIndex := srcIndex + 1.
- b := bytes at:srcIndex.
- srcIndex := srcIndex + 1.
- greenArray := redArray at:(r + 1).
- blueArray := greenArray at:(g + 1).
- pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
- dstIndex := dstIndex + 1
- ]
+ [srcIndex < dataSize] whileTrue:[
+ r := bytes at:srcIndex.
+ srcIndex := srcIndex + 1.
+ g := bytes at:srcIndex.
+ srcIndex := srcIndex + 1.
+ b := bytes at:srcIndex.
+ srcIndex := srcIndex + 1.
+ greenArray := redArray at:(r + 1).
+ blueArray := greenArray at:(g + 1).
+ pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
+ dstIndex := dstIndex + 1
+ ]
] ifFalse:[
- [srcIndex < dataSize] whileTrue:[
- r := bytes at:srcIndex.
- r := r bitAnd:rMask.
- srcIndex := srcIndex + 1.
- g := bytes at:srcIndex.
- g := g bitAnd:gMask.
- srcIndex := srcIndex + 1.
- b := bytes at:srcIndex.
- b := b bitAnd:bMask.
- srcIndex := srcIndex + 1.
- greenArray := redArray at:(r + 1).
- blueArray := greenArray at:(g + 1).
- pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
- dstIndex := dstIndex + 1
- ]
+ [srcIndex < dataSize] whileTrue:[
+ r := bytes at:srcIndex.
+ r := r bitAnd:rMask.
+ srcIndex := srcIndex + 1.
+ g := bytes at:srcIndex.
+ g := g bitAnd:gMask.
+ srcIndex := srcIndex + 1.
+ b := bytes at:srcIndex.
+ b := b bitAnd:bMask.
+ srcIndex := srcIndex + 1.
+ greenArray := redArray at:(r + 1).
+ blueArray := greenArray at:(g + 1).
+ pseudoBits at:dstIndex put:(blueArray at:(b + 1)).
+ dstIndex := dstIndex + 1
+ ]
].
f := Form width:width height:height depth:depth on:aDevice.
@@ -1036,16 +1042,16 @@
f colorMap:colors.
f initGC.
aDevice
- drawBits:pseudoBits
- bitsPerPixel:8
- depth:depth
- padding:8
- width:width height:height
- x:0 y:0
- into:(f id)
- x:0 y:0
- width:width height:height
- with:(f gcId).
+ drawBits:pseudoBits
+ bitsPerPixel:8
+ depth:depth
+ padding:8
+ width:width height:height
+ x:0 y:0
+ into:(f id)
+ x:0 y:0
+ width:width height:height
+ with:(f gcId).
^ f
!
@@ -2410,5 +2416,5 @@
!Depth24Image class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.68 1999-03-23 18:09:22 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.69 1999-03-24 18:51:07 cg Exp $'
! !