--- a/Depth24Image.st Wed Jan 24 14:41:11 2007 +0100
+++ b/Depth24Image.st Wed Jan 24 14:41:20 2007 +0100
@@ -163,11 +163,11 @@
bytes := self bits.
dstIdx := (y * self bytesPerRow) + 1.
0 to:width-1 do:[:col |
- pixel := pixelArray at:(startIndex + col).
- bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
- bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
- bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
- dstIdx := dstIdx + 3.
+ pixel := pixelArray at:(startIndex + col).
+ bytes at:dstIdx put:((pixel bitShift:-16) bitAnd:16rFF).
+ bytes at:dstIdx+1 put:((pixel bitShift:-8) bitAnd:16rFF).
+ bytes at:dstIdx+2 put:(pixel bitAnd:16rFF).
+ dstIdx := dstIdx + 3.
].
^ pixelArray
@@ -248,7 +248,7 @@
|ditherColors|
(ditherColors := aDevice fixColors) notNil ifTrue:[
- ^ self
+ ^ self
rgbImageAsDitheredPseudoFormOn:aDevice
colors:ditherColors
nRed:aDevice numFixRed
@@ -260,8 +260,8 @@
ditherColors addAll:(aDevice ditherColors).
ditherColors addAll:(aDevice deviceColors).
ditherColors := ditherColors asArray.
- ^ self
- rgbImageAsDitheredPseudoFormOn:aDevice
+ ^ self
+ rgbImageAsDitheredPseudoFormOn:aDevice
colors:ditherColors.
"Modified: 22.4.1997 / 11:59:44 / cg"
@@ -283,8 +283,8 @@
numFix := fixColors size.
numFix == 256 ifTrue:[
- "/ algorithm below only handles 255 colors.
- numFix := 255.
+ "/ algorithm below only handles 255 colors.
+ numFix := 255.
].
fixColorArray := fixColors asArray.
@@ -299,9 +299,9 @@
deviceDepth := aDevice depth.
deviceDepth == 8 ifFalse:[
- (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
- ^ nil
- ]
+ (aDevice supportedImageFormatForDepth:8) isNil ifTrue:[
+ ^ nil
+ ]
].
idsUsed := ByteArray new:(fixIds size).
@@ -330,131 +330,131 @@
&& __isByteArray(fixRed)
&& __isByteArray(fixGreen)
&& __isByteArray(fixBlue) ) {
- failed = false;
-
- srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
- dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
- idP = __ByteArrayInstPtr(fixIds)->ba_element;
- usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
- redP = __ByteArrayInstPtr(fixRed)->ba_element;
- greenP = __ByteArrayInstPtr(fixGreen)->ba_element;
- blueP = __ByteArrayInstPtr(fixBlue)->ba_element;
- cacheP = __ByteArrayInstPtr(cache)->ba_element;
- __numFix = __intVal(numFix);
-
- for (__y=__intVal(h); __y>0; __y--) {
- __eR = __eG = __eB = 0;
- for (__x=__w; __x>0; __x--) {
- int cacheIdx, clrIdx;
- int __wantR, __wantG, __wantB;
-
- __wantR = srcP[0] + __eR;
- if (__wantR > 255) __wantR = 255;
- else if (__wantR < 0) __wantR = 0;
-
- __wantG = srcP[1] + __eG;
- if (__wantG > 255) __wantG = 255;
- else if (__wantG < 0) __wantG = 0;
-
- __wantB = srcP[2] + __eB;
- if (__wantB > 255) __wantB = 255;
- else if (__wantB < 0) __wantB = 0;
-
- /*
- * compute cache index
- */
- cacheIdx = ((__wantR & 0xF8) >> 3);
- cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3);
- cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4);
-
- clrIdx = cacheP[cacheIdx];
- if (clrIdx == 0xFF) { /* invalid slot */
- unsigned minErr, minIdx;
- int i;
-
- /*
- * must search ...
- */
- minErr = 0x7FFFFFF; minIdx = 0;
- for (i=0; i<__numFix; i++) {
- unsigned cR, cG, cB, e;
- int eR, eG, eB;
-
- cR = redP[i]; cG = greenP[i]; cB = blueP[i];
- eR = cR - __wantR;
- if (eR < 0) eR = -eR;
-
- eG = cG - __wantG;
- if (eG < 0) eG = -eG;
-
- eB = cB - __wantB;
- if (eB < 0) eB = -eB;
-
- e = eR + eG + eB;
- if (e < minErr) {
- minErr = e;
- minIdx = i;
- if (e < 7) {
- break;
- }
- }
- }
-
- /*
- * minIdx is now index into fixColors
- */
- cacheP[cacheIdx] = clrIdx = minIdx;
+ failed = false;
+
+ srcP = __ByteArrayInstPtr(__INST(bytes))->ba_element;
+ dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+ idP = __ByteArrayInstPtr(fixIds)->ba_element;
+ usedIdP = __ByteArrayInstPtr(idsUsed)->ba_element;
+ redP = __ByteArrayInstPtr(fixRed)->ba_element;
+ greenP = __ByteArrayInstPtr(fixGreen)->ba_element;
+ blueP = __ByteArrayInstPtr(fixBlue)->ba_element;
+ cacheP = __ByteArrayInstPtr(cache)->ba_element;
+ __numFix = __intVal(numFix);
+
+ for (__y=__intVal(h); __y>0; __y--) {
+ __eR = __eG = __eB = 0;
+ for (__x=__w; __x>0; __x--) {
+ int cacheIdx, clrIdx;
+ int __wantR, __wantG, __wantB;
+
+ __wantR = srcP[0] + __eR;
+ if (__wantR > 255) __wantR = 255;
+ else if (__wantR < 0) __wantR = 0;
+
+ __wantG = srcP[1] + __eG;
+ if (__wantG > 255) __wantG = 255;
+ else if (__wantG < 0) __wantG = 0;
+
+ __wantB = srcP[2] + __eB;
+ if (__wantB > 255) __wantB = 255;
+ else if (__wantB < 0) __wantB = 0;
+
+ /*
+ * compute cache index
+ */
+ cacheIdx = ((__wantR & 0xF8) >> 3);
+ cacheIdx = (cacheIdx << 5) | ((__wantG & 0xF8) >> 3);
+ cacheIdx = (cacheIdx << 4) | ((__wantB & 0xF0) >> 4);
+
+ clrIdx = cacheP[cacheIdx];
+ if (clrIdx == 0xFF) { /* invalid slot */
+ unsigned minErr, minIdx;
+ int i;
+
+ /*
+ * must search ...
+ */
+ minErr = 0x7FFFFFF; minIdx = 0;
+ for (i=0; i<__numFix; i++) {
+ unsigned cR, cG, cB, e;
+ int eR, eG, eB;
+
+ cR = redP[i]; cG = greenP[i]; cB = blueP[i];
+ eR = cR - __wantR;
+ if (eR < 0) eR = -eR;
+
+ eG = cG - __wantG;
+ if (eG < 0) eG = -eG;
+
+ eB = cB - __wantB;
+ if (eB < 0) eB = -eB;
+
+ e = eR + eG + eB;
+ if (e < minErr) {
+ minErr = e;
+ minIdx = i;
+ if (e < 7) {
+ break;
+ }
+ }
+ }
+
+ /*
+ * minIdx is now index into fixColors
+ */
+ cacheP[cacheIdx] = clrIdx = minIdx;
/*
-printf("want %d/%d/%d best: %d [%d/%d/%d]\n", __wantR, __wantG, __wantB, clrIdx, redP[clrIdx], greenP[clrIdx], blueP[clrIdx]);
+console_printf("want %d/%d/%d best: %d [%d/%d/%d]\n", __wantR, __wantG, __wantB, clrIdx, redP[clrIdx], greenP[clrIdx], blueP[clrIdx]);
*/
- }
-
- /*
- * store the corresponding dither colorId
- */
- *dstP++ = idP[clrIdx];
- usedIdP[clrIdx] = 1;
-
- srcP += 3;
-
- /*
- * the new error:
- */
- __eR = __wantR - redP[clrIdx];
- __eG = __wantG - greenP[clrIdx];
- __eB = __wantB - blueP[clrIdx];
- }
- }
+ }
+
+ /*
+ * store the corresponding dither colorId
+ */
+ *dstP++ = idP[clrIdx];
+ usedIdP[clrIdx] = 1;
+
+ srcP += 3;
+
+ /*
+ * the new error:
+ */
+ __eR = __wantR - redP[clrIdx];
+ __eG = __wantG - greenP[clrIdx];
+ __eB = __wantB - blueP[clrIdx];
+ }
+ }
}
%}.
failed ifTrue:[
- self primitiveFailed.
- ^ nil
+ self primitiveFailed.
+ ^ nil
].
"/ not all colors may be really in use ...
usedColors := fixColors copy.
idsUsed keysAndValuesDo:[:idx :flag |
- flag == 0 ifTrue:[
- usedColors at:idx put:nil
- ]
+ flag == 0 ifTrue:[
+ usedColors at:idx put:nil
+ ]
].
f := Form width:width height:height depth:aDevice depth on:aDevice.
f isNil ifTrue:[^ nil].
f colorMap:usedColors.
f initGC.
- aDevice
- drawBits:pseudoBits
- bitsPerPixel:8
- depth:aDevice 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).
+ aDevice
+ drawBits:pseudoBits
+ bitsPerPixel:8
+ depth:aDevice 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
!
@@ -590,8 +590,8 @@
/*
* the new error:
*/
- __eR = __wantR - (iR * 256 / __fR);
- __eG = __wantG - (iG * 256 / __fG);
+ __eR = __wantR - (iR * 256 / __fR);
+ __eG = __wantG - (iG * 256 / __fG);
__eB = __wantB - (iB * 256 / __fB);
}
leftToRight = 0;
@@ -644,9 +644,9 @@
/*
* the new error:
*/
- __eR = __wantR - (iR * 256 / __fR);
- __eG = __wantG - (iG * 256 / __fG);
- __eB = __wantB - (iB * 256 / __fB);
+ __eR = __wantR - (iR * 256 / __fR);
+ __eG = __wantG - (iG * 256 / __fG);
+ __eB = __wantB - (iB * 256 / __fB);
}
srcP += (__w*3);
dstP += __w;
@@ -669,7 +669,7 @@
"/ eR := eG := eB := 0.
"/ 1 to:w do:[:x |
"/ |pixel "{ Class: SmallInteger }"
-"/ clr
+"/ clr
"/ idx "{ Class: SmallInteger }"
"/ iR "{ Class: SmallInteger }"
"/ iG "{ Class: SmallInteger }"
@@ -721,16 +721,16 @@
f isNil ifTrue:[^ nil].
f colorMap:usedColors.
f initGC.
- aDevice
- drawBits:pseudoBits
- bitsPerPixel:8
+ aDevice
+ drawBits:pseudoBits
+ bitsPerPixel:8
depth:aDevice depth
padding:8
width:width height:height
x:0 y:0
- into:(f id)
- x:0 y:0
- width:width height:height
+ into:(f id)
+ x:0 y:0
+ width:width height:height
with:(f gcId).
^ f
!
@@ -739,7 +739,7 @@
"return a pseudocolor form from the rgb-picture.
If a colorCube is used, pass the work on to the cube-dither
code. Otherwise, allocate as many colors as possible, then
- use those for dithering.
+ use those for dithering.
Could be improved, by searching for (& allocating)
heavily used colors and/or min-max colors first."
@@ -761,17 +761,17 @@
depth nColorCells deep nColorsNeeded bytes|
aDevice fixColors notNil ifTrue:[
- "/ no need to look for used colors - dithering anyway ...
-
- f := self rgbImageAsDitheredPseudoFormOn:aDevice.
- f notNil ifTrue:[^ f].
+ "/ no need to look for used colors - dithering anyway ...
+
+ f := self rgbImageAsDitheredPseudoFormOn:aDevice.
+ f notNil ifTrue:[^ f].
].
bytes := self bits.
"find used colors; build color-tree"
- fit := false.
+ fit := false.
fitMap := false.
depth := aDevice depth.
nColorCells := aDevice ncells.
@@ -785,211 +785,211 @@
'Depth24Image [info]: allocating colors ...' infoPrintCR.
[fit] whileFalse:[
- [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:[
+ [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:[
%{
- if (__isByteArray(bytes)) {
- int sI = __intVal(srcIndex);
- unsigned char *cp = __ByteArrayInstPtr(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;
- }
+ if (__isByteArray(bytes)) {
+ int sI = __intVal(srcIndex);
+ unsigned char *cp = __ByteArrayInstPtr(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;
+ }
%}
.
- 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:[
+ 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:[
"/ 'Depth24Image [info]: more than ' infoPrint. nColorCells infoPrint. ' colors' infoPrintCR.
- srcIndex := dataSize + 1
- ]
- ]
- ].
- nColorsNeeded isNil ifTrue:[
- nColorsNeeded := nColors
- ].
-
- "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
- ]
- ]
- ].
+ srcIndex := dataSize + 1
+ ]
+ ]
+ ].
+ nColorsNeeded isNil ifTrue:[
+ nColorsNeeded := nColors
+ ].
+
+ "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
+ ]
+ ]
+ ].
"/ '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.
-
- "
- 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|
-
- (fit and:[present ~~ 0]) ifTrue:[
- color := Color redByte:r
- greenByte:g
- blueByte:b.
- color := color onDevice: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"
-
- fit ifFalse:[
+ 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.
+
+ 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 onDevice: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"
+
+ 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.
-
- "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
- ]
+ "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
+ ]
].
(nColors ~~ nColorsNeeded) ifTrue:[
- "/ 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.
-
- "/
- "/ dither using those we got ...
- "/
- DitherAlgorithm == #floydSteinberg ifTrue:[
- colors := colors asSet.
+ "/ 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.
+
+ "/
+ "/ 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
+ "/ cannot draw directly
+ ^ nil
].
"create pseudocolor bits and translate"
@@ -1002,58 +1002,58 @@
(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.
f isNil ifTrue:[^ nil].
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).
+ 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).
^ f
!
rgbImageAsTrueColorFormOn:aDevice
"return a truecolor form from the rgb-picture."
- |bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding
+ |bytes bestFormat usedDeviceDepth usedDeviceBitsPerPixel usedDevicePadding
myDepth form imageBits padd
rightShiftR rightShiftG rightShiftB shiftRed shiftGreen shiftBlue|
@@ -1077,444 +1077,444 @@
"/
myDepth := self bitsPerPixel.
myDepth == usedDeviceBitsPerPixel ifTrue:[
- "/
- "/ first, the trivial case, where the depths match
- "/ 24 bit/pixel
- "/
- imageBits := bytes.
- "/
- "/ however, the rgb-order could still be different
- "/
- (shiftBlue == 0) ifFalse:[
- imageBits := ByteArray uninitializedNew:(width * height * 3).
- usedDevicePadding := 8.
-
- "/ now, walk over the image and compose 24bit values from the r/g/b triples
+ "/
+ "/ first, the trivial case, where the depths match
+ "/ 24 bit/pixel
+ "/
+ imageBits := bytes.
+ "/
+ "/ however, the rgb-order could still be different
+ "/
+ (shiftBlue == 0) ifFalse:[
+ imageBits := ByteArray uninitializedNew:(width * height * 3).
+ usedDevicePadding := 8.
+
+ "/ now, walk over the image and compose 24bit values from the r/g/b triples
%{
- unsigned char *srcPtr = 0;
- unsigned char *dstPtr = 0;
-
- if (__isByteArray(bytes)) {
- srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
- } else {
- if (__isExternalBytesLike(bytes)) {
- srcPtr = __externalBytesAddress(bytes);
- }
- }
- if (__isByteArray(imageBits)) {
- dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
- } else {
- if (__isExternalBytesLike(imageBits)) {
- dstPtr = __externalBytesAddress(imageBits);
- }
- }
-
- if (__bothSmallInteger(_INST(height), _INST(width))
- && __bothSmallInteger(rightShiftR, shiftRed)
- && __bothSmallInteger(rightShiftG, shiftGreen)
- && __bothSmallInteger(rightShiftB, shiftBlue)
- && srcPtr
- && dstPtr) {
- int rShRed = __intVal(rightShiftR),
- rShGreen = __intVal(rightShiftG),
- rShBlue = __intVal(rightShiftB),
- lShRed = __intVal(shiftRed),
- lShGreen = __intVal(shiftGreen),
- lShBlue = __intVal(shiftBlue);
- int x, y, w;
-
- w = __intVal(_INST(width));
- if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
- for (y=__intVal(_INST(height)); y > 0; y--) {
- for (x=w; x > 0; x--) {
- unsigned v;
-
- v = srcPtr[0] << lShRed;
- v |= (srcPtr[1] << lShGreen);
- v |= (srcPtr[2] << lShBlue);
+ unsigned char *srcPtr = 0;
+ unsigned char *dstPtr = 0;
+
+ if (__isByteArray(bytes)) {
+ srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
+ } else {
+ if (__isExternalBytesLike(bytes)) {
+ srcPtr = __externalBytesAddress(bytes);
+ }
+ }
+ if (__isByteArray(imageBits)) {
+ dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
+ } else {
+ if (__isExternalBytesLike(imageBits)) {
+ dstPtr = __externalBytesAddress(imageBits);
+ }
+ }
+
+ if (__bothSmallInteger(_INST(height), _INST(width))
+ && __bothSmallInteger(rightShiftR, shiftRed)
+ && __bothSmallInteger(rightShiftG, shiftGreen)
+ && __bothSmallInteger(rightShiftB, shiftBlue)
+ && srcPtr
+ && dstPtr) {
+ int rShRed = __intVal(rightShiftR),
+ rShGreen = __intVal(rightShiftG),
+ rShBlue = __intVal(rightShiftB),
+ lShRed = __intVal(shiftRed),
+ lShGreen = __intVal(shiftGreen),
+ lShBlue = __intVal(shiftBlue);
+ int x, y, w;
+
+ w = __intVal(_INST(width));
+ if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
+ for (y=__intVal(_INST(height)); y > 0; y--) {
+ for (x=w; x > 0; x--) {
+ unsigned v;
+
+ v = srcPtr[0] << lShRed;
+ v |= (srcPtr[1] << lShGreen);
+ v |= (srcPtr[2] << lShBlue);
# ifdef __MSBFIRST
- dstPtr[0] = (v) & 0xFF;
- dstPtr[1] = (v>>8) & 0xFF;
- dstPtr[2] = (v>>16) & 0xFF;
+ dstPtr[0] = (v) & 0xFF;
+ dstPtr[1] = (v>>8) & 0xFF;
+ dstPtr[2] = (v>>16) & 0xFF;
# else /* not MSB */
- dstPtr[0] = (v>>16) & 0xFF;
- dstPtr[1] = (v>>8) & 0xFF;
- dstPtr[2] = (v) & 0xFF;
+ dstPtr[0] = (v>>16) & 0xFF;
+ dstPtr[1] = (v>>8) & 0xFF;
+ dstPtr[2] = (v) & 0xFF;
# endif /* not MSB */
- dstPtr += 3;
- srcPtr += 3;
- }
- }
- } else {
- for (y=__intVal(_INST(height)); y > 0; y--) {
- for (x=w; x > 0; x--) {
- unsigned r, g, b, v;
-
- r = srcPtr[0] >> rShRed;
- g = srcPtr[1] >> rShGreen;
- b = srcPtr[2] >> rShBlue;
- v = r << lShRed;
- v |= (g << lShGreen);
- v |= (b << lShBlue);
+ dstPtr += 3;
+ srcPtr += 3;
+ }
+ }
+ } else {
+ for (y=__intVal(_INST(height)); y > 0; y--) {
+ for (x=w; x > 0; x--) {
+ unsigned r, g, b, v;
+
+ r = srcPtr[0] >> rShRed;
+ g = srcPtr[1] >> rShGreen;
+ b = srcPtr[2] >> rShBlue;
+ v = r << lShRed;
+ v |= (g << lShGreen);
+ v |= (b << lShBlue);
# ifdef __MSBFIRST
- dstPtr[0] = (v) & 0xFF;
- dstPtr[1] = (v>>8) & 0xFF;
- dstPtr[2] = (v>>16) & 0xFF;
+ dstPtr[0] = (v) & 0xFF;
+ dstPtr[1] = (v>>8) & 0xFF;
+ dstPtr[2] = (v>>16) & 0xFF;
# else /* not MSB */
- dstPtr[0] = (v>>16) & 0xFF;
- dstPtr[1] = (v>>8) & 0xFF;
- dstPtr[2] = (v) & 0xFF;
+ dstPtr[0] = (v>>16) & 0xFF;
+ dstPtr[1] = (v>>8) & 0xFF;
+ dstPtr[2] = (v) & 0xFF;
# endif /* not MSB */
- dstPtr += 3;
- srcPtr += 3;
- }
- }
- }
- }
+ dstPtr += 3;
+ srcPtr += 3;
+ }
+ }
+ }
+ }
%}.
- ]
+ ]
] ifFalse:[
- "/
- "/ 16 bit/pixel ...
- "/
- (usedDeviceBitsPerPixel == 16) ifTrue:[
- padd := width \\ (usedDevicePadding // 16).
- imageBits := ByteArray uninitializedNew:((width + padd) * height * 2).
-
- "/ now, walk over the image and compose 16bit values from the r/g/b triples
+ "/
+ "/ 16 bit/pixel ...
+ "/
+ (usedDeviceBitsPerPixel == 16) ifTrue:[
+ padd := width \\ (usedDevicePadding // 16).
+ imageBits := ByteArray uninitializedNew:((width + padd) * height * 2).
+
+ "/ now, walk over the image and compose 16bit values from the r/g/b triples
%{
- unsigned char *srcPtr = 0;
- unsigned char *dstPtr = 0;
-
- if (__isByteArray(bytes)) {
- srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
- } else {
- if (__isExternalBytesLike(bytes)) {
- srcPtr = __externalBytesAddress(bytes);
- }
- }
- if (__isByteArray(imageBits)) {
- dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
- } else {
- if (__isExternalBytesLike(imageBits)) {
- dstPtr = __externalBytesAddress(imageBits);
- }
- }
-
- if (__bothSmallInteger(_INST(height),_INST(width))
- && __bothSmallInteger(rightShiftR, shiftRed)
- && __bothSmallInteger(rightShiftG, shiftGreen)
- && __bothSmallInteger(rightShiftB, shiftBlue)
- && srcPtr
- && dstPtr) {
- int rShRed = __intVal(rightShiftR),
- rShGreen = __intVal(rightShiftG),
- rShBlue = __intVal(rightShiftB),
- lShRed = __intVal(shiftRed),
- lShGreen = __intVal(shiftGreen),
- lShBlue = __intVal(shiftBlue);
- int x, y, w;
- int p;
-
- w = __intVal(_INST(width));
- p = __intVal(padd) * 2;
-
- if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
- for (y=__intVal(_INST(height)); y > 0; y--) {
- for (x=w; x > 0; x--) {
- unsigned v;
-
- v = srcPtr[0] << lShRed;
- v |= (srcPtr[1] << lShGreen);
- v |= (srcPtr[2] << lShBlue);
+ unsigned char *srcPtr = 0;
+ unsigned char *dstPtr = 0;
+
+ if (__isByteArray(bytes)) {
+ srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
+ } else {
+ if (__isExternalBytesLike(bytes)) {
+ srcPtr = __externalBytesAddress(bytes);
+ }
+ }
+ if (__isByteArray(imageBits)) {
+ dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
+ } else {
+ if (__isExternalBytesLike(imageBits)) {
+ dstPtr = __externalBytesAddress(imageBits);
+ }
+ }
+
+ if (__bothSmallInteger(_INST(height),_INST(width))
+ && __bothSmallInteger(rightShiftR, shiftRed)
+ && __bothSmallInteger(rightShiftG, shiftGreen)
+ && __bothSmallInteger(rightShiftB, shiftBlue)
+ && srcPtr
+ && dstPtr) {
+ int rShRed = __intVal(rightShiftR),
+ rShGreen = __intVal(rightShiftG),
+ rShBlue = __intVal(rightShiftB),
+ lShRed = __intVal(shiftRed),
+ lShGreen = __intVal(shiftGreen),
+ lShBlue = __intVal(shiftBlue);
+ int x, y, w;
+ int p;
+
+ w = __intVal(_INST(width));
+ p = __intVal(padd) * 2;
+
+ if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
+ for (y=__intVal(_INST(height)); y > 0; y--) {
+ for (x=w; x > 0; x--) {
+ unsigned v;
+
+ v = srcPtr[0] << lShRed;
+ v |= (srcPtr[1] << lShGreen);
+ v |= (srcPtr[2] << lShBlue);
# ifdef __MSBFIRST
- ((short *)dstPtr)[0] = v;
+ ((short *)dstPtr)[0] = v;
# else /* not MSB */
- dstPtr[0] = (v>>8) & 0xFF;
- dstPtr[1] = (v) & 0xFF;
+ dstPtr[0] = (v>>8) & 0xFF;
+ dstPtr[1] = (v) & 0xFF;
# endif /* not MSB */
- dstPtr += 2;
- srcPtr += 3;
- }
- dstPtr += p;
- }
- } else {
- if (p == 0) {
- int n = __intVal(__INST(height)) * w;
-
- while (n >= 2) {
- unsigned w, r, g, b, v;
-
- n -= 2;
-
- r = srcPtr[0];
- g = srcPtr[1];
- b = srcPtr[2];
- v = (r >> rShRed) << lShRed;
- v |= ((g >> rShGreen) << lShGreen);
- v |= ((b >> rShBlue) << lShBlue);
+ dstPtr += 2;
+ srcPtr += 3;
+ }
+ dstPtr += p;
+ }
+ } else {
+ if (p == 0) {
+ int n = __intVal(__INST(height)) * w;
+
+ while (n >= 2) {
+ unsigned w, r, g, b, v;
+
+ n -= 2;
+
+ r = srcPtr[0];
+ g = srcPtr[1];
+ b = srcPtr[2];
+ v = (r >> rShRed) << lShRed;
+ v |= ((g >> rShGreen) << lShGreen);
+ v |= ((b >> rShBlue) << lShBlue);
# ifdef __MSBFIRST
- ((short *)dstPtr)[0] = v;
+ ((short *)dstPtr)[0] = v;
# else
- dstPtr[0] = (v>>8) & 0xFF;
- dstPtr[1] = (v) & 0xFF;
+ dstPtr[0] = (v>>8) & 0xFF;
+ dstPtr[1] = (v) & 0xFF;
# endif /* not MSB */
- r = srcPtr[3];
- g = srcPtr[4];
- b = srcPtr[5];
- v = (r >> rShRed) << lShRed;
- v |= ((g >> rShGreen) << lShGreen);
- v |= ((b >> rShBlue) << lShBlue);
+ r = srcPtr[3];
+ g = srcPtr[4];
+ b = srcPtr[5];
+ v = (r >> rShRed) << lShRed;
+ v |= ((g >> rShGreen) << lShGreen);
+ v |= ((b >> rShBlue) << lShBlue);
# ifdef __MSBFIRST
- ((short *)dstPtr)[1] = v;
+ ((short *)dstPtr)[1] = v;
# else
- dstPtr[2] = (v>>8) & 0xFF;
- dstPtr[3] = (v) & 0xFF;
+ dstPtr[2] = (v>>8) & 0xFF;
+ dstPtr[3] = (v) & 0xFF;
# endif /* not MSB */
- dstPtr += 4;
- srcPtr += 6;
- }
-
- while (n--) {
- unsigned r, g, b, v;
-
- r = srcPtr[0] >> rShRed;
- g = srcPtr[1] >> rShGreen;
- b = srcPtr[2] >> rShBlue;
- v = r << lShRed;
- v |= (g << lShGreen);
- v |= (b << lShBlue);
+ dstPtr += 4;
+ srcPtr += 6;
+ }
+
+ while (n--) {
+ unsigned r, g, b, v;
+
+ r = srcPtr[0] >> rShRed;
+ g = srcPtr[1] >> rShGreen;
+ b = srcPtr[2] >> rShBlue;
+ v = r << lShRed;
+ v |= (g << lShGreen);
+ v |= (b << lShBlue);
# ifdef __MSBFIRST
- ((short *)dstPtr)[0] = v;
+ ((short *)dstPtr)[0] = v;
# else /* not MSB */
- dstPtr[0] = (v>>8) & 0xFF;
- dstPtr[1] = (v) & 0xFF;
+ dstPtr[0] = (v>>8) & 0xFF;
+ dstPtr[1] = (v) & 0xFF;
# endif /* not MSB */
- dstPtr += 2;
- srcPtr += 3;
- }
- } else {
- for (y=__intVal(_INST(height)); y > 0; y--) {
- for (x=w; x > 0; x--) {
- unsigned r, g, b, v;
-
- r = srcPtr[0] >> rShRed;
- g = srcPtr[1] >> rShGreen;
- b = srcPtr[2] >> rShBlue;
- v = r << lShRed;
- v |= (g << lShGreen);
- v |= (b << lShBlue);
+ dstPtr += 2;
+ srcPtr += 3;
+ }
+ } else {
+ for (y=__intVal(_INST(height)); y > 0; y--) {
+ for (x=w; x > 0; x--) {
+ unsigned r, g, b, v;
+
+ r = srcPtr[0] >> rShRed;
+ g = srcPtr[1] >> rShGreen;
+ b = srcPtr[2] >> rShBlue;
+ v = r << lShRed;
+ v |= (g << lShGreen);
+ v |= (b << lShBlue);
# ifdef __MSBFIRST
- ((short *)dstPtr)[0] = v;
+ ((short *)dstPtr)[0] = v;
# else /* not MSB */
- dstPtr[0] = (v>>8) & 0xFF;
- dstPtr[1] = (v) & 0xFF;
+ dstPtr[0] = (v>>8) & 0xFF;
+ dstPtr[1] = (v) & 0xFF;
# endif /* not MSB */
- dstPtr += 2;
- srcPtr += 3;
- }
- dstPtr += p;
- }
- }
- }
- }
+ dstPtr += 2;
+ srcPtr += 3;
+ }
+ dstPtr += p;
+ }
+ }
+ }
+ }
%}.
- ] ifFalse:[
- "/
- "/ 32 bits/pixel ...
- "/
- (usedDeviceBitsPerPixel == 32) ifTrue:[
- usedDevicePadding := 8.
- imageBits := ByteArray uninitializedNew:(width * height * 4).
-
- "/ now, walk over the image and compose 32bit values from the r/g/b triples
-
-%{
- unsigned char *srcPtr = 0;
- unsigned char *dstPtr = 0;
-
- if (__isByteArray(bytes)) {
- srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
- } else {
- if (__isExternalBytesLike(bytes)) {
- srcPtr = __externalBytesAddress(bytes);
- }
- }
- if (__isByteArray(imageBits)) {
- dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
- } else {
- if (__isExternalBytesLike(imageBits)) {
- dstPtr = __externalBytesAddress(imageBits);
- }
- }
-
- if (__bothSmallInteger(_INST(height), _INST(width))
- && __bothSmallInteger(rightShiftR, shiftRed)
- && __bothSmallInteger(rightShiftG, shiftGreen)
- && __bothSmallInteger(rightShiftB, shiftBlue)
- && srcPtr
- && dstPtr) {
- int rShRed = __intVal(rightShiftR),
- rShGreen = __intVal(rightShiftG),
- rShBlue = __intVal(rightShiftB),
- lShRed = __intVal(shiftRed),
- lShGreen = __intVal(shiftGreen),
- lShBlue = __intVal(shiftBlue);
- int x, y, w;
-
- w = __intVal(_INST(width));
- if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
- for (y=__intVal(_INST(height)); y > 0; y--) {
- for (x=w; x > 0; x--) {
- unsigned v;
-
- v = srcPtr[0] << lShRed;
- v |= (srcPtr[1] << lShGreen);
- v |= (srcPtr[2] << lShBlue);
+ ] ifFalse:[
+ "/
+ "/ 32 bits/pixel ...
+ "/
+ (usedDeviceBitsPerPixel == 32) ifTrue:[
+ usedDevicePadding := 8.
+ imageBits := ByteArray uninitializedNew:(width * height * 4).
+
+ "/ now, walk over the image and compose 32bit values from the r/g/b triples
+
+%{
+ unsigned char *srcPtr = 0;
+ unsigned char *dstPtr = 0;
+
+ if (__isByteArray(bytes)) {
+ srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
+ } else {
+ if (__isExternalBytesLike(bytes)) {
+ srcPtr = __externalBytesAddress(bytes);
+ }
+ }
+ if (__isByteArray(imageBits)) {
+ dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
+ } else {
+ if (__isExternalBytesLike(imageBits)) {
+ dstPtr = __externalBytesAddress(imageBits);
+ }
+ }
+
+ if (__bothSmallInteger(_INST(height), _INST(width))
+ && __bothSmallInteger(rightShiftR, shiftRed)
+ && __bothSmallInteger(rightShiftG, shiftGreen)
+ && __bothSmallInteger(rightShiftB, shiftBlue)
+ && srcPtr
+ && dstPtr) {
+ int rShRed = __intVal(rightShiftR),
+ rShGreen = __intVal(rightShiftG),
+ rShBlue = __intVal(rightShiftB),
+ lShRed = __intVal(shiftRed),
+ lShGreen = __intVal(shiftGreen),
+ lShBlue = __intVal(shiftBlue);
+ int x, y, w;
+
+ w = __intVal(_INST(width));
+ if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
+ for (y=__intVal(_INST(height)); y > 0; y--) {
+ for (x=w; x > 0; x--) {
+ unsigned v;
+
+ v = srcPtr[0] << lShRed;
+ v |= (srcPtr[1] << lShGreen);
+ v |= (srcPtr[2] << lShBlue);
# ifdef __MSBFIRST
- ((int *)dstPtr)[0] = v;
+ ((int *)dstPtr)[0] = v;
# else /* not MSB */
- dstPtr[0] = (v>>24) & 0xFF;
- dstPtr[1] = (v>>16) & 0xFF;
- dstPtr[2] = (v>>8) & 0xFF;
- dstPtr[3] = (v) & 0xFF;
+ dstPtr[0] = (v>>24) & 0xFF;
+ dstPtr[1] = (v>>16) & 0xFF;
+ dstPtr[2] = (v>>8) & 0xFF;
+ dstPtr[3] = (v) & 0xFF;
# endif /* not MSB */
- dstPtr += 4;
- srcPtr += 3;
- }
- }
- } else {
- for (y=__intVal(_INST(height)); y > 0; y--) {
- for (x=w; x > 0; x--) {
- unsigned r, g, b, v;
-
- r = srcPtr[0] >> rShRed;
- g = srcPtr[1] >> rShGreen;
- b = srcPtr[2] >> rShBlue;
- v = r << lShRed;
- v |= (g << lShGreen);
- v |= (b << lShBlue);
+ dstPtr += 4;
+ srcPtr += 3;
+ }
+ }
+ } else {
+ for (y=__intVal(_INST(height)); y > 0; y--) {
+ for (x=w; x > 0; x--) {
+ unsigned r, g, b, v;
+
+ r = srcPtr[0] >> rShRed;
+ g = srcPtr[1] >> rShGreen;
+ b = srcPtr[2] >> rShBlue;
+ v = r << lShRed;
+ v |= (g << lShGreen);
+ v |= (b << lShBlue);
# ifdef __MSBFIRST
- ((int *)dstPtr)[0] = v;
+ ((int *)dstPtr)[0] = v;
# else /* not MSB */
- dstPtr[0] = (v>>24) & 0xFF;
- dstPtr[1] = (v>>16) & 0xFF;
- dstPtr[2] = (v>>8) & 0xFF;
- dstPtr[3] = (v) & 0xFF;
+ dstPtr[0] = (v>>24) & 0xFF;
+ dstPtr[1] = (v>>16) & 0xFF;
+ dstPtr[2] = (v>>8) & 0xFF;
+ dstPtr[3] = (v) & 0xFF;
# endif /* not MSB */
- dstPtr += 4;
- srcPtr += 3;
- }
- }
- }
- }
+ dstPtr += 4;
+ srcPtr += 3;
+ }
+ }
+ }
+ }
%}.
- ] ifFalse:[
- "/
- "/ 8 bits/pixel ...
- "/
- (usedDeviceBitsPerPixel == 8) ifTrue:[
- usedDevicePadding := 8.
- imageBits := ByteArray uninitializedNew:(width * height).
-
- "/ now, walk over the image and compose 8bit values from the r/g/b triples
-
-%{
- unsigned char *srcPtr = 0;
- unsigned char *dstPtr = 0;
-
- if (__isByteArray(bytes)) {
- srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
- } else {
- if (__isExternalBytesLike(bytes)) {
- srcPtr = __externalBytesAddress(bytes);
- }
- }
- if (__isByteArray(imageBits)) {
- dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
- } else {
- if (__isExternalBytesLike(imageBits)) {
- dstPtr = __externalBytesAddress(imageBits);
- }
- }
-
- if (__bothSmallInteger(_INST(height), _INST(width))
- && __bothSmallInteger(rightShiftR, shiftRed)
- && __bothSmallInteger(rightShiftG, shiftGreen)
- && __bothSmallInteger(rightShiftB, shiftBlue)
- && srcPtr
- && dstPtr) {
- int rShRed = __intVal(rightShiftR),
- rShGreen = __intVal(rightShiftG),
- rShBlue = __intVal(rightShiftB),
- lShRed = __intVal(shiftRed),
- lShGreen = __intVal(shiftGreen),
- lShBlue = __intVal(shiftBlue);
- int x, y, w;
-
- w = __intVal(_INST(width));
- if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
- for (y=__intVal(_INST(height)); y > 0; y--) {
- for (x=w; x > 0; x--) {
- unsigned v;
-
- v = srcPtr[0] << lShRed;
- v |= (srcPtr[1] << lShGreen);
- v |= (srcPtr[2] << lShBlue);
- dstPtr[0] = v;
-
- dstPtr += 1;
- srcPtr += 3;
- }
- }
- } else {
- for (y=__intVal(_INST(height)); y > 0; y--) {
- for (x=w; x > 0; x--) {
- unsigned r, g, b, v;
-
- r = srcPtr[0] >> rShRed;
- g = srcPtr[1] >> rShGreen;
- b = srcPtr[2] >> rShBlue;
- v = r << lShRed;
- v |= (g << lShGreen);
- v |= (b << lShBlue);
-
- dstPtr[0] = v;
-
- dstPtr += 1;
- srcPtr += 3;
- }
- }
- }
- }
+ ] ifFalse:[
+ "/
+ "/ 8 bits/pixel ...
+ "/
+ (usedDeviceBitsPerPixel == 8) ifTrue:[
+ usedDevicePadding := 8.
+ imageBits := ByteArray uninitializedNew:(width * height).
+
+ "/ now, walk over the image and compose 8bit values from the r/g/b triples
+
+%{
+ unsigned char *srcPtr = 0;
+ unsigned char *dstPtr = 0;
+
+ if (__isByteArray(bytes)) {
+ srcPtr = _ByteArrayInstPtr(bytes)->ba_element;
+ } else {
+ if (__isExternalBytesLike(bytes)) {
+ srcPtr = __externalBytesAddress(bytes);
+ }
+ }
+ if (__isByteArray(imageBits)) {
+ dstPtr = _ByteArrayInstPtr(imageBits)->ba_element;
+ } else {
+ if (__isExternalBytesLike(imageBits)) {
+ dstPtr = __externalBytesAddress(imageBits);
+ }
+ }
+
+ if (__bothSmallInteger(_INST(height), _INST(width))
+ && __bothSmallInteger(rightShiftR, shiftRed)
+ && __bothSmallInteger(rightShiftG, shiftGreen)
+ && __bothSmallInteger(rightShiftB, shiftBlue)
+ && srcPtr
+ && dstPtr) {
+ int rShRed = __intVal(rightShiftR),
+ rShGreen = __intVal(rightShiftG),
+ rShBlue = __intVal(rightShiftB),
+ lShRed = __intVal(shiftRed),
+ lShGreen = __intVal(shiftGreen),
+ lShBlue = __intVal(shiftBlue);
+ int x, y, w;
+
+ w = __intVal(_INST(width));
+ if ((rShRed == 0) && (rShGreen == 0) && (rShBlue == 0)) {
+ for (y=__intVal(_INST(height)); y > 0; y--) {
+ for (x=w; x > 0; x--) {
+ unsigned v;
+
+ v = srcPtr[0] << lShRed;
+ v |= (srcPtr[1] << lShGreen);
+ v |= (srcPtr[2] << lShBlue);
+ dstPtr[0] = v;
+
+ dstPtr += 1;
+ srcPtr += 3;
+ }
+ }
+ } else {
+ for (y=__intVal(_INST(height)); y > 0; y--) {
+ for (x=w; x > 0; x--) {
+ unsigned r, g, b, v;
+
+ r = srcPtr[0] >> rShRed;
+ g = srcPtr[1] >> rShGreen;
+ b = srcPtr[2] >> rShBlue;
+ v = r << lShRed;
+ v |= (g << lShGreen);
+ v |= (b << lShBlue);
+
+ dstPtr[0] = v;
+
+ dstPtr += 1;
+ srcPtr += 3;
+ }
+ }
+ }
+ }
%}.
- ]
- ].
- ]
+ ]
+ ].
+ ]
].
- imageBits isNil ifTrue:[
- 'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint.
- usedDeviceBitsPerPixel errorPrintCR.
- ^ self asMonochromeFormOn:aDevice
+ imageBits isNil ifTrue:[
+ 'IMAGE: unimplemented trueColor depth in #rgbImageAsTrueColorFormOn: ' errorPrint.
+ usedDeviceBitsPerPixel errorPrintCR.
+ ^ self asMonochromeFormOn:aDevice
].
form := Form width:width height:height depth:usedDeviceDepth on:aDevice.
form isNil ifTrue:[
- 'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
- ^ nil
+ 'Depth24Image [warning]: display bitmap creation failed' errorPrintCR.
+ ^ nil
].
form initGC.
- form
- copyBitsFrom:imageBits
- bitsPerPixel:usedDeviceBitsPerPixel
- depth:usedDeviceDepth
- padding:usedDevicePadding
- width:width height:height
- x:0 y:0 toX:0 y:0.
+ form
+ copyBitsFrom:imageBits
+ bitsPerPixel:usedDeviceBitsPerPixel
+ depth:usedDeviceDepth
+ padding:usedDevicePadding
+ width:width height:height
+ x:0 y:0 toX:0 y:0.
^ form
@@ -1525,11 +1525,11 @@
floydSteinbergDitheredDepth8BitsColors:colors map:aMapOrNil
"return a floyd-steinberg dithered bitmap from the receiver picture,
- which must be a depth-24 image.
+ which must be a depth-24 image.
This method expects an array of colors to be used for dithering
(which need not be a colorCubes colors)."
- |pseudoBits
+ |pseudoBits
ditherRGBBytes ditherColors
w "{Class: SmallInteger }"
h "{Class: SmallInteger }"
@@ -1542,61 +1542,61 @@
"/ collect valid ditherColors ...
aMapOrNil isNil ifTrue:[
- ditherColors := colors select:[:clr | clr notNil].
+ ditherColors := colors select:[:clr | clr notNil].
] ifFalse:[
- ditherColors := colors
+ ditherColors := colors
].
"/ ... and sort by manhatten distance from black
qScramble := #(
- "/ 2rX00X00X00X00
-
- 2r000000000000 "/ 0
- 2r000000000100 "/ 1
- 2r000000100000 "/ 2
- 2r000000100100 "/ 3
- 2r000100000000 "/ 4
- 2r000100000100 "/ 5
- 2r000100100000 "/ 6
- 2r000100100100 "/ 7
- 2r100000000000 "/ 8
- 2r100000000100 "/ 9
- 2r100000100000 "/ a
- 2r100000100100 "/ b
- 2r100100000000 "/ c
- 2r100100000100 "/ d
- 2r100100100000 "/ e
- 2r100100100100 "/ f
- ).
+ "/ 2rX00X00X00X00
+
+ 2r000000000000 "/ 0
+ 2r000000000100 "/ 1
+ 2r000000100000 "/ 2
+ 2r000000100100 "/ 3
+ 2r000100000000 "/ 4
+ 2r000100000100 "/ 5
+ 2r000100100000 "/ 6
+ 2r000100100100 "/ 7
+ 2r100000000000 "/ 8
+ 2r100000000100 "/ 9
+ 2r100000100000 "/ a
+ 2r100000100100 "/ b
+ 2r100100000000 "/ c
+ 2r100100000100 "/ d
+ 2r100100100000 "/ e
+ 2r100100100100 "/ f
+ ).
ditherColors := ditherColors sort:[:a :b |
- |cr "{Class: SmallInteger }"
- cg "{Class: SmallInteger }"
- cb "{Class: SmallInteger }"
- i1 "{Class: SmallInteger }"
- i2 "{Class: SmallInteger }"|
-
- cr := a redByte.
- cg := a greenByte.
- cb := a blueByte.
- i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
- i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
- i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
-
- cr := b redByte.
- cg := b greenByte.
- cb := b blueByte.
- i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
- i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
- i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
-
- i1 < i2
- ].
+ |cr "{Class: SmallInteger }"
+ cg "{Class: SmallInteger }"
+ cb "{Class: SmallInteger }"
+ i1 "{Class: SmallInteger }"
+ i2 "{Class: SmallInteger }"|
+
+ cr := a redByte.
+ cg := a greenByte.
+ cb := a blueByte.
+ i1 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
+ i1 := i1 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+ i1 := i1 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+
+ cr := b redByte.
+ cg := b greenByte.
+ cb := b blueByte.
+ i2 := qScramble at:((cr bitShift:-4) bitAnd:16r0F) + 1.
+ i2 := i2 + ((qScramble at:((cg bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+ i2 := i2 + ((qScramble at:((cb bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+
+ i1 < i2
+ ].
aMapOrNil isNil ifTrue:[
- ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
+ ditherIds := (ditherColors asArray collect:[:clr | clr colorId]) asByteArray.
] ifFalse:[
- ditherIds := aMapOrNil asByteArray
+ ditherIds := aMapOrNil asByteArray
].
"/ build an index table, for fast lookup from manhatten-r-g-b distance
@@ -1605,20 +1605,20 @@
clrLookup := ByteArray new:(4096).
index := 0.
ditherColors keysAndValuesDo:[:clrPosition :clr |
- |r g b i|
-
- r := clr redByte.
- g := clr greenByte.
- b := clr blueByte.
- i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
- i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
- i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
- lookupPos := i.
-
- [index < lookupPos] whileTrue:[
- clrLookup at:(index+1) put:(clrPosition-1-1).
- index := index + 1
- ]
+ |r g b i|
+
+ r := clr redByte.
+ g := clr greenByte.
+ b := clr blueByte.
+ i := qScramble at:((r bitShift:-4) bitAnd:16r0F) + 1.
+ i := i + ((qScramble at:((g bitShift:-4) bitAnd:16r0F) + 1) bitShift:-1).
+ i := i + ((qScramble at:((b bitShift:-4) bitAnd:16r0F) + 1) bitShift:-2).
+ lookupPos := i.
+
+ [index < lookupPos] whileTrue:[
+ clrLookup at:(index+1) put:(clrPosition-1-1).
+ index := index + 1
+ ]
].
clrLookup from:index+1 to:4096 put:(ditherColors size - 1).
@@ -1634,16 +1634,16 @@
ditherRGBBytes := ByteArray uninitializedNew:(lastColor * 3).
index := 1.
1 to:lastColor do:[:pix |
- clr := ditherColors at:pix.
- ditherRGBBytes at:index put:(clr redByte).
- ditherRGBBytes at:index+1 put:(clr greenByte).
- ditherRGBBytes at:index+2 put:(clr blueByte).
- aMapOrNil isNil ifTrue:[
- ditherIds at:pix put:clr colorId.
- ] ifFalse:[
- ditherIds at:pix put:(aMapOrNil at:pix).
- ].
- index := index + 3.
+ clr := ditherColors at:pix.
+ ditherRGBBytes at:index put:(clr redByte).
+ ditherRGBBytes at:index+1 put:(clr greenByte).
+ ditherRGBBytes at:index+2 put:(clr blueByte).
+ aMapOrNil isNil ifTrue:[
+ ditherIds at:pix put:clr colorId.
+ ] ifFalse:[
+ ditherIds at:pix put:(aMapOrNil at:pix).
+ ].
+ index := index + 3.
].
pseudoBits := ByteArray uninitializedNew:(width * height).
@@ -1665,23 +1665,23 @@
int __nColors = __intVal(lastColor);
int __wR = -1, __wG, __wB;
static int __qScramble[16] = {
- 0x000 /* 2r000000000000 0 */,
- 0x004 /* 2r000000000100 1 */,
- 0x020 /* 2r000000100000 2 */,
- 0x024 /* 2r000000100100 3 */,
- 0x100 /* 2r000100000000 4 */,
- 0x104 /* 2r000100000100 5 */,
- 0x120 /* 2r000100100000 6 */,
- 0x124 /* 2r000100100100 7 */,
- 0x800 /* 2r100000000000 8 */,
- 0x804 /* 2r100000000100 9 */,
- 0x820 /* 2r100000100000 a */,
- 0x824 /* 2r100000100100 b */,
- 0x900 /* 2r100100000000 c */,
- 0x904 /* 2r100100000100 d */,
- 0x920 /* 2r100100100000 e */,
- 0x924 /* 2r100100100100 f */,
- };
+ 0x000 /* 2r000000000000 0 */,
+ 0x004 /* 2r000000000100 1 */,
+ 0x020 /* 2r000000100000 2 */,
+ 0x024 /* 2r000000100100 3 */,
+ 0x100 /* 2r000100000000 4 */,
+ 0x104 /* 2r000100000100 5 */,
+ 0x120 /* 2r000100100000 6 */,
+ 0x124 /* 2r000100100100 7 */,
+ 0x800 /* 2r100000000000 8 */,
+ 0x804 /* 2r100000000100 9 */,
+ 0x820 /* 2r100000100000 a */,
+ 0x824 /* 2r100000100100 b */,
+ 0x900 /* 2r100100000000 c */,
+ 0x904 /* 2r100100000100 d */,
+ 0x920 /* 2r100100100000 e */,
+ 0x924 /* 2r100100100100 f */,
+ };
if (__isByteArray(__INST(bytes))
&& __isByteArray(pseudoBits)
@@ -1689,54 +1689,54 @@
&& __isByteArray(ditherIds)
&& __isByteArray(clrLookup)
&& __isByteArray(error)) {
- failed = false;
-
- srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
- dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
- idP = __ByteArrayInstPtr(ditherIds)->ba_element;
- __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
- errP = (short *) __ByteArrayInstPtr(error)->ba_element;
-
- /*
- * clear error accumulator
- */
- eP = errP;
- bzero(eP, (__w+2) * 2 * 3);
-
- for (__y=__h; __y>0; __y--) {
- unsigned char *dp;
- int __eR, __eG, __eB;
-
- __eR = __eG = __eB = 0;
-
- eP = &(errP[3]);
- __eR = eP[0];
- __eG = eP[1];
- __eB = eP[2];
-
- for (__x=__w; __x>0; __x--) {
- int __want;
- int pix;
- int __wantR, __wantG, __wantB;
- int idx;
- int tR, tG, tB;
- int nR, nG, nB;
- int dR, dG, dB;
- int minDelta, bestIdx;
- int cnt;
-
- __wantR = srcP[0];
- __wantG = srcP[1];
- __wantB = srcP[2];
- srcP += 3;
-
- /*
- * wI are the wanted r/g/b values;
- * eI are the error values;
- */
- __wantR = __wantR + __eR;
- __wantG = __wantG + __eG;
- __wantB = __wantB + __eB;
+ failed = false;
+
+ srcP = __ByteArrayInstPtr(_INST(bytes))->ba_element;
+ dstP = __ByteArrayInstPtr(pseudoBits)->ba_element;
+ idP = __ByteArrayInstPtr(ditherIds)->ba_element;
+ __clrLookup = __ByteArrayInstPtr(clrLookup)->ba_element;
+ errP = (short *) __ByteArrayInstPtr(error)->ba_element;
+
+ /*
+ * clear error accumulator
+ */
+ eP = errP;
+ bzero(eP, (__w+2) * 2 * 3);
+
+ for (__y=__h; __y>0; __y--) {
+ unsigned char *dp;
+ int __eR, __eG, __eB;
+
+ __eR = __eG = __eB = 0;
+
+ eP = &(errP[3]);
+ __eR = eP[0];
+ __eG = eP[1];
+ __eB = eP[2];
+
+ for (__x=__w; __x>0; __x--) {
+ int __want;
+ int pix;
+ int __wantR, __wantG, __wantB;
+ int idx;
+ int tR, tG, tB;
+ int nR, nG, nB;
+ int dR, dG, dB;
+ int minDelta, bestIdx;
+ int cnt;
+
+ __wantR = srcP[0];
+ __wantG = srcP[1];
+ __wantB = srcP[2];
+ srcP += 3;
+
+ /*
+ * wI are the wanted r/g/b values;
+ * eI are the error values;
+ */
+ __wantR = __wantR + __eR;
+ __wantG = __wantG + __eG;
+ __wantB = __wantB + __eB;
#define RED_SCALE 30
#define GREEN_SCALE 59
@@ -1748,237 +1748,237 @@
#define NPROBE 8
#ifndef FAST_LOOKUP
- if ((__wantR == __wR)
- && (__wantG == __wG)
- && (__wantB == __wB)) {
- /*
- * same color again - reuse last bestMatch
- */
- } else
+ if ((__wantR == __wR)
+ && (__wantG == __wG)
+ && (__wantB == __wB)) {
+ /*
+ * same color again - reuse last bestMatch
+ */
+ } else
#endif
- {
- __wR = __wantR;
- __wG = __wantG;
- __wB = __wantB;
+ {
+ __wR = __wantR;
+ __wG = __wantG;
+ __wB = __wantB;
#ifdef FAST_LOOKUP
- if(__wR > 255) __wR = 255;
- else if (__wR < 0) __wR = 0;
- if(__wG > 255) __wG = 255;
- else if (__wG < 0) __wG = 0;
- if(__wB > 255) __wB = 255;
- else if (__wB < 0) __wB = 0;
-
- {
- int lookupIndex;
- int idx, idx0;
- int d, delta;
- unsigned char *dp0;
-
- dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
- lookupIndex = __qScramble[((__wR & 0xF0)>>4)];
- lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1;
- lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2;
- idx = bestIdx =__clrLookup[lookupIndex];
- dp += (idx+idx+idx);
-
- /* try color at lookupIndex */
-
- d = dp[0];
- delta = (__wR - d) * RED_SCALE;
- if (delta < 0) delta = -delta;
-
- d = dp[1];
- if (__wG > d)
- delta += (__wG - d) * GREEN_SCALE;
- else
- delta += (d - __wG) * GREEN_SCALE;
- d = dp[2];
- if (__wB > d)
- delta += (__wB - d) * BLUE_SCALE;
- else
- delta += (d - __wB) * BLUE_SCALE;
-
- if (delta <= GOOD_DELTA) {
- goto foundBest;
- }
- minDelta = delta;
+ if(__wR > 255) __wR = 255;
+ else if (__wR < 0) __wR = 0;
+ if(__wG > 255) __wG = 255;
+ else if (__wG < 0) __wG = 0;
+ if(__wB > 255) __wB = 255;
+ else if (__wB < 0) __wB = 0;
+
+ {
+ int lookupIndex;
+ int idx, idx0;
+ int d, delta;
+ unsigned char *dp0;
+
+ dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+ lookupIndex = __qScramble[((__wR & 0xF0)>>4)];
+ lookupIndex |= __qScramble[((__wG & 0xF0)>>4)] >> 1;
+ lookupIndex |= __qScramble[((__wB & 0xF0)>>4)] >> 2;
+ idx = bestIdx =__clrLookup[lookupIndex];
+ dp += (idx+idx+idx);
+
+ /* try color at lookupIndex */
+
+ d = dp[0];
+ delta = (__wR - d) * RED_SCALE;
+ if (delta < 0) delta = -delta;
+
+ d = dp[1];
+ if (__wG > d)
+ delta += (__wG - d) * GREEN_SCALE;
+ else
+ delta += (d - __wG) * GREEN_SCALE;
+ d = dp[2];
+ if (__wB > d)
+ delta += (__wB - d) * BLUE_SCALE;
+ else
+ delta += (d - __wB) * BLUE_SCALE;
+
+ if (delta <= GOOD_DELTA) {
+ goto foundBest;
+ }
+ minDelta = delta;
# ifndef ONE_SHOT
- idx0 = idx; dp0 = dp;
- cnt = 0;
- while ((++cnt <= NPROBE) && (idx > 0)) {
- /* try previous color(s) */
-
- idx--; dp -= 3;
- d = dp[0];
- delta = (__wR - d) * RED_SCALE;
- if (delta < 0) delta = -delta;
- d = dp[1];
- if (__wG > d)
- delta += (__wG - d) * GREEN_SCALE;
- else
- delta += (d - __wG) * GREEN_SCALE;
- d = dp[2];
- if (__wB > d)
- delta += (__wB - d) * BLUE_SCALE;
- else
- delta += (d - __wB) * BLUE_SCALE;
-
- if (delta < minDelta) {
- bestIdx = idx;
- if (delta <= GOOD_DELTA) {
- goto foundBest;
- }
- minDelta = delta;
- }
- }
-
- idx = idx0; dp = dp0;
- cnt = 0;
- while ((++cnt <= NPROBE) && (++idx < __nColors)) {
- /* try next color */
-
- dp += 3;
- d = dp[0];
- delta = (__wR - d) * RED_SCALE;
- if (delta < 0) delta = -delta;
- d = dp[1];
- if (__wG > d)
- delta += (__wG - d) * GREEN_SCALE;
- else
- delta += (d - __wG) * GREEN_SCALE;
- d = dp[2];
- if (__wB > d)
- delta += (__wB - d) * BLUE_SCALE;
- else
- delta += (d - __wB) * BLUE_SCALE;
-
- if (delta < minDelta) {
- bestIdx = idx;
- if (delta <= GOOD_DELTA) {
- goto foundBest;
- }
- minDelta = delta;
- }
- }
+ idx0 = idx; dp0 = dp;
+ cnt = 0;
+ while ((++cnt <= NPROBE) && (idx > 0)) {
+ /* try previous color(s) */
+
+ idx--; dp -= 3;
+ d = dp[0];
+ delta = (__wR - d) * RED_SCALE;
+ if (delta < 0) delta = -delta;
+ d = dp[1];
+ if (__wG > d)
+ delta += (__wG - d) * GREEN_SCALE;
+ else
+ delta += (d - __wG) * GREEN_SCALE;
+ d = dp[2];
+ if (__wB > d)
+ delta += (__wB - d) * BLUE_SCALE;
+ else
+ delta += (d - __wB) * BLUE_SCALE;
+
+ if (delta < minDelta) {
+ bestIdx = idx;
+ if (delta <= GOOD_DELTA) {
+ goto foundBest;
+ }
+ minDelta = delta;
+ }
+ }
+
+ idx = idx0; dp = dp0;
+ cnt = 0;
+ while ((++cnt <= NPROBE) && (++idx < __nColors)) {
+ /* try next color */
+
+ dp += 3;
+ d = dp[0];
+ delta = (__wR - d) * RED_SCALE;
+ if (delta < 0) delta = -delta;
+ d = dp[1];
+ if (__wG > d)
+ delta += (__wG - d) * GREEN_SCALE;
+ else
+ delta += (d - __wG) * GREEN_SCALE;
+ d = dp[2];
+ if (__wB > d)
+ delta += (__wB - d) * BLUE_SCALE;
+ else
+ delta += (d - __wB) * BLUE_SCALE;
+
+ if (delta < minDelta) {
+ bestIdx = idx;
+ if (delta <= GOOD_DELTA) {
+ goto foundBest;
+ }
+ minDelta = delta;
+ }
+ }
# endif
- }
- foundBest: ;
+ }
+ foundBest: ;
#else
/*
- if(__wR > 255) __wR = 255;
- else if (__wR < 0) __wR = 0;
- if(__wG > 255) __wG = 255;
- else if (__wG < 0) __wG = 0;
- if(__wB > 255) __wB = 255;
- else if (__wB < 0) __wB = 0;
+ if(__wR > 255) __wR = 255;
+ else if (__wR < 0) __wR = 0;
+ if(__wG > 255) __wG = 255;
+ else if (__wG < 0) __wG = 0;
+ if(__wB > 255) __wB = 255;
+ else if (__wB < 0) __wB = 0;
*/
- /* find the best matching color */
-
- minDelta = 99999;
- bestIdx = -1;
- dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
- for (idx = 0; idx<__nColors; idx++) {
- int d, delta;
-
- d = dp[0];
- delta = (__wR - d) * RED_SCALE;
- if (delta < 0) delta = -delta;
- if (delta < minDelta) {
- d = dp[1];
- if (__wG > d)
- delta += (__wG - d) * GREEN_SCALE;
- else
- delta += (d - __wG) * GREEN_SCALE;
- if (delta < minDelta) {
- d = dp[2];
- if (__wB > d)
- delta += (__wB - d) * BLUE_SCALE;
- else
- delta += (d - __wB) * BLUE_SCALE;
-
- if (delta < minDelta) {
- bestIdx = idx;
- if (delta <= GOOD_DELTA) {
- break;
- }
- minDelta = delta;
- }
- }
- }
- dp += 3;
- }
+ /* find the best matching color */
+
+ minDelta = 99999;
+ bestIdx = -1;
+ dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+ for (idx = 0; idx<__nColors; idx++) {
+ int d, delta;
+
+ d = dp[0];
+ delta = (__wR - d) * RED_SCALE;
+ if (delta < 0) delta = -delta;
+ if (delta < minDelta) {
+ d = dp[1];
+ if (__wG > d)
+ delta += (__wG - d) * GREEN_SCALE;
+ else
+ delta += (d - __wG) * GREEN_SCALE;
+ if (delta < minDelta) {
+ d = dp[2];
+ if (__wB > d)
+ delta += (__wB - d) * BLUE_SCALE;
+ else
+ delta += (d - __wB) * BLUE_SCALE;
+
+ if (delta < minDelta) {
+ bestIdx = idx;
+ if (delta <= GOOD_DELTA) {
+ break;
+ }
+ minDelta = delta;
+ }
+ }
+ }
+ dp += 3;
+ }
#endif
- }
-
- dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
- dp += bestIdx * 3;
- dR = dp[0];
- dG = dp[1];
- dB = dp[2];
+ }
+
+ dp = __ByteArrayInstPtr(ditherRGBBytes)->ba_element;
+ dp += bestIdx * 3;
+ dR = dp[0];
+ dG = dp[1];
+ dB = dp[2];
/*
-printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
- __wantR, __wantG, __wantB,
- __wR, __wG, __wB,
- dR, dG, dB);
+console_printf("want: %d/%d/%d (%d/%d/%d) got: %d/%d/%d\n",
+ __wantR, __wantG, __wantB,
+ __wR, __wG, __wB,
+ dR, dG, dB);
*/
- /*
- * store the corresponding dither colors colorId
- */
- *dstP++ = idP[bestIdx];
-
- /*
- * the new error & distribute the error
- */
- __eR = __wantR - dR;
- if (__eR) {
- tR = __eR >> 4; /* 16th of error */
- nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
- eP[0] = tR*5; /* 5/16th for (x / y+1) */
- eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */
- eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */
- __eR = nR;
- } else {
- __eR = eP[3];
- eP[0] = eP[-3] = eP[3] = 0;
- }
-
- __eG = __wantG - dG;
- if (__eG) {
- tG = __eG >> 4;
- nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
- eP[1] = tG*5;
- eP[-2] = tG*3;
- eP[4] = __eG - (tG*15);
- __eG = nG;
- } else {
- __eG = eP[4];
- eP[1] = eP[-2] = eP[4] = 0;
- }
-
- __eB = __wantB - dB;
- if (__eB) {
- tB = __eB >> 4;
- nB = eP[5] + (tB * 7);
- eP[2] = tB*5;
- eP[-1] = tB*3;
- eP[5] = __eB - (tB*15);
- __eB = nB;
- } else {
- __eB = eP[5];
- eP[2] = eP[-1] = eP[5] = 0;
- }
-
- eP += 3;
- }
- }
+ /*
+ * store the corresponding dither colors colorId
+ */
+ *dstP++ = idP[bestIdx];
+
+ /*
+ * the new error & distribute the error
+ */
+ __eR = __wantR - dR;
+ if (__eR) {
+ tR = __eR >> 4; /* 16th of error */
+ nR = eP[3] + (tR * 7);/* from accu: error for (x+1 / y) */
+ eP[0] = tR*5; /* 5/16th for (x / y+1) */
+ eP[-3] = tR*3; /* 3/16th for (x-1 / y+1) */
+ eP[3] = __eR - (tR*15); /* 1/16th for (x+1 / y+1) */
+ __eR = nR;
+ } else {
+ __eR = eP[3];
+ eP[0] = eP[-3] = eP[3] = 0;
+ }
+
+ __eG = __wantG - dG;
+ if (__eG) {
+ tG = __eG >> 4;
+ nG = eP[4] + (tG * 7);/* plus 7/16'th of this error */
+ eP[1] = tG*5;
+ eP[-2] = tG*3;
+ eP[4] = __eG - (tG*15);
+ __eG = nG;
+ } else {
+ __eG = eP[4];
+ eP[1] = eP[-2] = eP[4] = 0;
+ }
+
+ __eB = __wantB - dB;
+ if (__eB) {
+ tB = __eB >> 4;
+ nB = eP[5] + (tB * 7);
+ eP[2] = tB*5;
+ eP[-1] = tB*3;
+ eP[5] = __eB - (tB*15);
+ __eB = nB;
+ } else {
+ __eB = eP[5];
+ eP[2] = eP[-1] = eP[5] = 0;
+ }
+
+ eP += 3;
+ }
+ }
}
%}.
failed ifTrue:[
- self primitiveFailed.
- ^ nil
+ self primitiveFailed.
+ ^ nil
].
^ pseudoBits
@@ -1992,21 +1992,21 @@
nextDst "{Class: SmallInteger }"
bytesPerRow "{Class: SmallInteger }"
bytesPerOutRow "{Class: SmallInteger }"
- outBits greyMap1 greyMap2 greyLevels
+ outBits greyMap1 greyMap2 greyLevels
errorArray
errorArray1
e t v
w "{Class: SmallInteger }"
h "{Class: SmallInteger }"
bitCnt "{Class: SmallInteger }"
- byte "{Class: SmallInteger }"
- grey dT
+ byte "{Class: SmallInteger }"
+ grey dT
eR eRB eB eLB bytes|
(samplesPerPixel ~~ 3
or:[bitsPerSample ~= #(8 8 8)
or:[depth > 8]]) ifTrue:[
- ^ super floydSteinbergDitheredGrayBitsDepth:depth
+ ^ super floydSteinbergDitheredGrayBitsDepth:depth
].
bytes := self bits.
@@ -2019,22 +2019,22 @@
outBits := ByteArray uninitializedNew:(bytesPerOutRow * h).
depth ~~ 8 ifTrue:[
- greyLevels := (1 bitShift:depth) - 1.
- greyMap1 := Array new:256.
- greyMap2 := Array new:256.
- 1 to:256 do:[:i |
- v := (greyLevels / 255 * (i-1)).
- greyMap1 at:i put:v.
- greyMap2 at:i put:v.
- ].
- greyMap1 := (greyMap1 collect:[:b | b truncated]) asByteArray.
-
- greyMap2 := (greyMap2 collect:[:el |
- ((el - el truncated) "/ the error (0..1)
- * 255) rounded]) asByteArray.
-
- errorArray := ByteArray new:(w + 2) * 2.
- errorArray1 := ByteArray new:(w + 2) * 2.
+ greyLevels := (1 bitShift:depth) - 1.
+ greyMap1 := Array new:256.
+ greyMap2 := Array new:256.
+ 1 to:256 do:[:i |
+ v := (greyLevels / 255 * (i-1)).
+ greyMap1 at:i put:v.
+ greyMap2 at:i put:v.
+ ].
+ greyMap1 := (greyMap1 collect:[:b | b truncated]) asByteArray.
+
+ greyMap2 := (greyMap2 collect:[:el |
+ ((el - el truncated) "/ the error (0..1)
+ * 255) rounded]) asByteArray.
+
+ errorArray := ByteArray new:(w + 2) * 2.
+ errorArray1 := ByteArray new:(w + 2) * 2.
].
%{
@@ -2065,90 +2065,90 @@
short *__t;
if (__depth == 8) {
- /*
- * special code for destination depth 8
- */
- for (__y=0; __y<__h; __y++) {
- __nextDst = __dstIdx + __bytesPerOutRow;
- __nextSrc = __srcIdx + __bytesPerRow;
- for (__x=0; __x<__w; __x++) {
- __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
- + (__bytes[__srcIdx+1] * 6)
- + __bytes[__srcIdx+2];
- __pixel = __grey / 10; /* 0 .. 255 */
-
- __srcIdx += 3;
- __outBits[__dstIdx] = __pixel;
- __dstIdx++;
- }
- __srcIdx = __nextSrc;
- __dstIdx = __nextDst;
- }
+ /*
+ * special code for destination depth 8
+ */
+ for (__y=0; __y<__h; __y++) {
+ __nextDst = __dstIdx + __bytesPerOutRow;
+ __nextSrc = __srcIdx + __bytesPerRow;
+ for (__x=0; __x<__w; __x++) {
+ __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
+ + (__bytes[__srcIdx+1] * 6)
+ + __bytes[__srcIdx+2];
+ __pixel = __grey / 10; /* 0 .. 255 */
+
+ __srcIdx += 3;
+ __outBits[__dstIdx] = __pixel;
+ __dstIdx++;
+ }
+ __srcIdx = __nextSrc;
+ __dstIdx = __nextDst;
+ }
} else {
- bzero(errorArray1, (__w+2) * 2);
-
- __bitCnt = 8;
- for (__y=0; __y<__h; __y++) {
- __nextDst = __dstIdx + __bytesPerOutRow;
- __nextSrc = __srcIdx + __bytesPerRow;
-
- __byte = 0;
-
- __t = __errorArray;
- __errorArray = __errorArray1;
- __errorArray1 = __t;
- bzero(errorArray1, (__w+2) * 2);
-
- for (__x=0; __x<__w; __x++) {
- __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
- + (__bytes[__srcIdx+1] * 6)
- + __bytes[__srcIdx+2];
- __grey = __grey / 10; /* 0 .. 255 */
-
- __pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */
- __err = __greyMap2[__grey]; /* 0.. 255 - error) */
- __err += __errorArray[__x+1];
-
- if (__err > 127) { /* dither says: next pixel */
- if ( __pixel != __greyLevels)
- __pixel++;
- __err = __err - 255;
- } else {
- }
- if (__err) {
- __e16 = __err >> 4;
- __eR = __e16 * 7; /* 7/16 -> right pixel */
- __eRB = __e16 * 1; /* 1/16 -> right below */
- __eB = __e16 * 5; /* 5/16 -> below */
- __eLB = __err - __eR - __eRB - __eB; /* 3/16 -> left below */
-
- __errorArray [__x+1+1] += __eR;
- __errorArray1[__x+1+1] += __eRB;
- __errorArray1[__x+1 ] += __eB;
- __errorArray1[__x+1-1] += __eLB;
- }
-
- __srcIdx += 3;
-
- __byte = (__byte << __depth) | __pixel;
-
- __bitCnt = __bitCnt - __depth;
- if (__bitCnt == 0) {
- __outBits[__dstIdx] = __byte;
- __dstIdx++;
- __byte = 0;
- __bitCnt = 8;
- }
- }
-
- if (__bitCnt != 8) {
- __byte = __byte << __bitCnt;
- __outBits[__dstIdx] = __byte;
- __bitCnt = 8;
- }
- __srcIdx = __nextSrc;
- __dstIdx = __nextDst;
- }
+ bzero(errorArray1, (__w+2) * 2);
+
+ __bitCnt = 8;
+ for (__y=0; __y<__h; __y++) {
+ __nextDst = __dstIdx + __bytesPerOutRow;
+ __nextSrc = __srcIdx + __bytesPerRow;
+
+ __byte = 0;
+
+ __t = __errorArray;
+ __errorArray = __errorArray1;
+ __errorArray1 = __t;
+ bzero(errorArray1, (__w+2) * 2);
+
+ for (__x=0; __x<__w; __x++) {
+ __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
+ + (__bytes[__srcIdx+1] * 6)
+ + __bytes[__srcIdx+2];
+ __grey = __grey / 10; /* 0 .. 255 */
+
+ __pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */
+ __err = __greyMap2[__grey]; /* 0.. 255 - error) */
+ __err += __errorArray[__x+1];
+
+ if (__err > 127) { /* dither says: next pixel */
+ if ( __pixel != __greyLevels)
+ __pixel++;
+ __err = __err - 255;
+ } else {
+ }
+ if (__err) {
+ __e16 = __err >> 4;
+ __eR = __e16 * 7; /* 7/16 -> right pixel */
+ __eRB = __e16 * 1; /* 1/16 -> right below */
+ __eB = __e16 * 5; /* 5/16 -> below */
+ __eLB = __err - __eR - __eRB - __eB; /* 3/16 -> left below */
+
+ __errorArray [__x+1+1] += __eR;
+ __errorArray1[__x+1+1] += __eRB;
+ __errorArray1[__x+1 ] += __eB;
+ __errorArray1[__x+1-1] += __eLB;
+ }
+
+ __srcIdx += 3;
+
+ __byte = (__byte << __depth) | __pixel;
+
+ __bitCnt = __bitCnt - __depth;
+ if (__bitCnt == 0) {
+ __outBits[__dstIdx] = __byte;
+ __dstIdx++;
+ __byte = 0;
+ __bitCnt = 8;
+ }
+ }
+
+ if (__bitCnt != 8) {
+ __byte = __byte << __bitCnt;
+ __outBits[__dstIdx] = __byte;
+ __bitCnt = 8;
+ }
+ __srcIdx = __nextSrc;
+ __dstIdx = __nextDst;
+ }
}
%}.
@@ -2173,7 +2173,7 @@
with a constant ditherMatrix, this can be used for thresholding.
Redefined to make use of knowing that pixels are 24-bit values."
- |dH nDither v range bytes
+ |dH nDither v range bytes
greyMap1 greyMap2 greyLevels outBits
bytesPerOutRow "{Class: SmallInteger }"
bytesPerRow "{Class: SmallInteger }"
@@ -2181,8 +2181,8 @@
h "{Class: SmallInteger }"|
photometric ~~ #rgb ifTrue:[
- self error:'invalid format'.
- ^ nil
+ self error:'invalid format'.
+ ^ nil
].
nDither := ditherMatrix size.
@@ -2203,25 +2203,25 @@
greyMap2 := Array new:256.
range := greyLevels-1.
1 to:256 do:[:i |
- v := (range / 255 * (i-1)).
- greyMap1 at:i put:v.
- greyMap2 at:i put:v.
+ v := (range / 255 * (i-1)).
+ greyMap1 at:i put:v.
+ greyMap2 at:i put:v.
].
greyMap1 := (greyMap1 collect:[:b | b isNil ifTrue:[
- 0
- ] ifFalse:[
- b truncated
- ]
- ]) asByteArray.
-
- greyMap2 := (greyMap2 collect:[:el |
- el isNil ifTrue:[
- 0
- ] ifFalse:[
- ((el - el truncated) "/ the error (0..1)
- * nDither) rounded
- ]]) asByteArray.
+ 0
+ ] ifFalse:[
+ b truncated
+ ]
+ ]) asByteArray.
+
+ greyMap2 := (greyMap2 collect:[:el |
+ el isNil ifTrue:[
+ 0
+ ] ifFalse:[
+ ((el - el truncated) "/ the error (0..1)
+ * nDither) rounded
+ ]]) asByteArray.
%{
int __dW = __intVal(dW);
int __dH = __intVal(dH);
@@ -2252,56 +2252,56 @@
__oY = __dY = 0;
for (__y=0; __y<__h; __y++) {
- __nextDst = __dstIdx + __bytesPerOutRow;
- __nextSrc = __srcIdx + __bytesPerRow;
-
- __byte = 0;
- __bitCnt = 8;
-
- __oX = 0;
-
- for (__x=0; __x<__w; __x++) {
- __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
- + (__bytes[__srcIdx+1] * 6)
- + __bytes[__srcIdx+2];
- __grey = __grey / 10; /* 0 .. 255 */
-
- __pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */
- __dO = __greyMap2[__grey]; /* 0.. nDither-1) */
- __dT = __ditherMatrix[__dY + __oX];
-
- if (__dO > __dT) /* dither says: next pixel */
- __pixel++;
-
- __srcIdx += 3;
-
- __oX++;
- if (__oX == __dW) __oX = 0;
-
- __byte = (__byte << __depth) | __pixel;
-
- __bitCnt = __bitCnt - __depth;
- if (__bitCnt == 0) {
- __outBits[__dstIdx] = __byte;
- __dstIdx++;
- __byte = 0;
- __bitCnt = 8;
- }
- }
-
- if (__bitCnt != 8) {
- __byte = __byte << __bitCnt;
- __outBits[__dstIdx] = __byte;
- }
-
- __oY++; __dY += __dW;
- if (__oY == __dH) {
- __oY = 0;
- __dY = 0;
- }
-
- __srcIdx = __nextSrc;
- __dstIdx = __nextDst;
+ __nextDst = __dstIdx + __bytesPerOutRow;
+ __nextSrc = __srcIdx + __bytesPerRow;
+
+ __byte = 0;
+ __bitCnt = 8;
+
+ __oX = 0;
+
+ for (__x=0; __x<__w; __x++) {
+ __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
+ + (__bytes[__srcIdx+1] * 6)
+ + __bytes[__srcIdx+2];
+ __grey = __grey / 10; /* 0 .. 255 */
+
+ __pixel = __greyMap1[__grey]; /* 0..(greyLevels-1) */
+ __dO = __greyMap2[__grey]; /* 0.. nDither-1) */
+ __dT = __ditherMatrix[__dY + __oX];
+
+ if (__dO > __dT) /* dither says: next pixel */
+ __pixel++;
+
+ __srcIdx += 3;
+
+ __oX++;
+ if (__oX == __dW) __oX = 0;
+
+ __byte = (__byte << __depth) | __pixel;
+
+ __bitCnt = __bitCnt - __depth;
+ if (__bitCnt == 0) {
+ __outBits[__dstIdx] = __byte;
+ __dstIdx++;
+ __byte = 0;
+ __bitCnt = 8;
+ }
+ }
+
+ if (__bitCnt != 8) {
+ __byte = __byte << __bitCnt;
+ __outBits[__dstIdx] = __byte;
+ }
+
+ __oY++; __dY += __dW;
+ if (__oY == __dH) {
+ __oY = 0;
+ __dY = 0;
+ }
+
+ __srcIdx = __nextSrc;
+ __dstIdx = __nextDst;
}
%}.
@@ -2326,7 +2326,7 @@
with a constant ditherMatrix, this can be used for thresholding.
Redefined to make use of knowing that pixels are 24-bit values."
- |dH nDither bytes
+ |dH nDither bytes
monoBits
bytesPerMonoRow "{Class: SmallInteger }"
bytesPerRow "{Class: SmallInteger }"
@@ -2334,8 +2334,8 @@
h "{Class: SmallInteger }"|
photometric ~~ #rgb ifTrue:[
- self error:'invalid format'.
- ^ nil
+ self error:'invalid format'.
+ ^ nil
].
nDither := ditherMatrix size.
@@ -2377,53 +2377,53 @@
__oY = __dY = 0;
for (__y=0; __y<__h; __y++) {
- __nextDst = __dstIdx + __bytesPerMonoRow;
- __nextSrc = __srcIdx + __bytesPerRow;
-
- __byte = 0;
- __bitCnt = 8;
-
- __oX = 0;
-
- for (__x=0; __x<__w; __x++) {
- __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
- + (__bytes[__srcIdx+1] * 6)
- + __bytes[__srcIdx+2];
- __grey = __grey * (__nDither+1) / 2550; /* 0 .. nDither+1 */
- __srcIdx += 3;
-
- __dT = __ditherMatrix[__dY + __oX];
-
- __oX++;
- if (__oX == __dW) __oX = 0;
-
- __byte = __byte << 1;
- if (__grey > __dT) {
- __byte = __byte | 1; /* white */
- }
-
- __bitCnt--;
- if (__bitCnt == 0) {
- __monoBits[__dstIdx] = __byte;
- __dstIdx++;
- __byte = 0;
- __bitCnt = 8;
- }
- }
-
- if (__bitCnt != 8) {
- __byte = __byte << __bitCnt;
- __monoBits[__dstIdx] = __byte;
- }
-
- __oY++; __dY += __dW;
- if (__oY == __dH) {
- __oY = 0;
- __dY = 0;
- }
-
- __srcIdx = __nextSrc;
- __dstIdx = __nextDst;
+ __nextDst = __dstIdx + __bytesPerMonoRow;
+ __nextSrc = __srcIdx + __bytesPerRow;
+
+ __byte = 0;
+ __bitCnt = 8;
+
+ __oX = 0;
+
+ for (__x=0; __x<__w; __x++) {
+ __grey = (__bytes[__srcIdx] * 3) /* 0.3*r + 0.6*g + b -> 0..2550 */
+ + (__bytes[__srcIdx+1] * 6)
+ + __bytes[__srcIdx+2];
+ __grey = __grey * (__nDither+1) / 2550; /* 0 .. nDither+1 */
+ __srcIdx += 3;
+
+ __dT = __ditherMatrix[__dY + __oX];
+
+ __oX++;
+ if (__oX == __dW) __oX = 0;
+
+ __byte = __byte << 1;
+ if (__grey > __dT) {
+ __byte = __byte | 1; /* white */
+ }
+
+ __bitCnt--;
+ if (__bitCnt == 0) {
+ __monoBits[__dstIdx] = __byte;
+ __dstIdx++;
+ __byte = 0;
+ __bitCnt = 8;
+ }
+ }
+
+ if (__bitCnt != 8) {
+ __byte = __byte << __bitCnt;
+ __monoBits[__dstIdx] = __byte;
+ }
+
+ __oY++; __dY += __dW;
+ if (__oY == __dH) {
+ __oY = 0;
+ __dY = 0;
+ }
+
+ __srcIdx = __nextSrc;
+ __dstIdx = __nextDst;
}
%}.
@@ -2494,7 +2494,7 @@
lastR lastG lastB lastColor bytes|
photometric ~~ #rgb ifTrue:[
- ^ super colorsAtY:y from:xLow to:xHigh do:aBlock.
+ ^ super colorsAtY:y from:xLow to:xHigh do:aBlock.
].
bytes := self bits.
@@ -2505,18 +2505,18 @@
srcIndex := 1 + (((width * y) + x1) * 3).
x1 to:x2 do:[:x |
- rVal := bytes at:(srcIndex).
- gVal := bytes at:(srcIndex + 1).
- bVal := bytes at:(srcIndex + 2).
- srcIndex := srcIndex + 3.
-
- (rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
- lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal.
- lastR := rVal.
- lastG := gVal.
- lastB := bVal.
- ].
- aBlock value:x value:lastColor
+ rVal := bytes at:(srcIndex).
+ gVal := bytes at:(srcIndex + 1).
+ bVal := bytes at:(srcIndex + 2).
+ srcIndex := srcIndex + 3.
+
+ (rVal == lastR and:[gVal == lastG and:[bVal == lastB]]) ifFalse:[
+ lastColor := Color redByte:rVal greenByte:gVal blueByte:bVal.
+ lastR := rVal.
+ lastG := gVal.
+ lastB := bVal.
+ ].
+ aBlock value:x value:lastColor
]
"Created: / 7.6.1996 / 19:12:28 / cg"
@@ -2548,11 +2548,11 @@
srcIndex := 1 + (((width * y) + x1) * 3).
x1 to:x2 do:[:x |
- r := bytes at:(srcIndex).
- g := bytes at:(srcIndex + 1).
- b := bytes at:(srcIndex + 2).
- srcIndex := srcIndex + 3.
- aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b)
+ r := bytes at:(srcIndex).
+ g := bytes at:(srcIndex + 1).
+ b := bytes at:(srcIndex + 2).
+ srcIndex := srcIndex + 3.
+ aBlock value:x value:(((r bitShift:16) bitOr:(g bitShift:8)) bitOr:b)
]
"Created: 7.6.1996 / 19:09:40 / cg"
@@ -2564,7 +2564,7 @@
|bytes index newImage newBytes nBytes r g b|
photometric ~~ #rgb ifTrue:[
- ^ super negative.
+ ^ super negative.
].
bytes := self bits.
@@ -2573,15 +2573,15 @@
newImage bits:(newBytes := ByteArray new:nBytes).
index := 1.
[index < nBytes] whileTrue:[
- r := bytes at:index.
- newBytes at:index put:(255-r).
- index := index + 1.
- g := bytes at:index.
- newBytes at:index put:(255-g).
- index := index + 1.
- b := bytes at:index.
- newBytes at:index put:(255-b).
- index := index + 1.
+ r := bytes at:index.
+ newBytes at:index put:(255-r).
+ index := index + 1.
+ g := bytes at:index.
+ newBytes at:index put:(255-g).
+ index := index + 1.
+ b := bytes at:index.
+ newBytes at:index put:(255-b).
+ index := index + 1.
].
^ newImage
@@ -2594,14 +2594,14 @@
"return a new image magnified by scalePoint, aPoint.
This interpolates pixels and is therefore slower."
- |mX
- mY
+ |mX
+ mY
newWidth "{ Class: SmallInteger }"
newHeight "{ Class: SmallInteger }"
w "{ Class: SmallInteger }"
h "{ Class: SmallInteger }"
newImage newBits bitsPerPixel newBytesPerRow newMask
- value
+ value
srcRow pixelArray|
mX := scalePoint x.
@@ -2625,12 +2625,12 @@
].
newImage := self species new.
- newImage
- width:newWidth
- height:newHeight
- photometric:photometric
- samplesPerPixel:samplesPerPixel
- bitsPerSample:bitsPerSample
+ newImage
+ width:newWidth
+ height:newHeight
+ photometric:photometric
+ samplesPerPixel:samplesPerPixel
+ bitsPerSample:bitsPerSample
colorMap:colorMap copy
bits:newBits
mask:newMask.
@@ -2676,7 +2676,7 @@
_sC = (int)_srcX;
_dX = _srcX - ((double)_sC);
sP = _srcRowP + (_sC * 3);
-
+
rHere = sP[0];
gHere = sP[1];
bHere = sP[2];
@@ -2784,12 +2784,12 @@
].
newImage := self species new.
- newImage
- width:newWidth
- height:newHeight
- photometric:photometric
- samplesPerPixel:samplesPerPixel
- bitsPerSample:#(8 8 8)
+ newImage
+ width:newWidth
+ height:newHeight
+ photometric:photometric
+ samplesPerPixel:samplesPerPixel
+ bitsPerSample:#(8 8 8)
colorMap:nil
bits:newBytes
mask:newMask.
@@ -2844,7 +2844,7 @@
!
magnifyRowFrom:srcBytes offset:srcStart
- into:dstBytes offset:dstStart factor:mX
+ into:dstBytes offset:dstStart factor:mX
"magnify a single pixel row - can only magnify by integer factors"
@@ -2859,29 +2859,29 @@
if (__bothSmallInteger(srcStart, dstStart)
&& __bothSmallInteger(w, mX)
&& __isByteArray(srcBytes) && __isByteArray(dstBytes)) {
- _mag = __intVal(mX);
- srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
- dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
- _pixels = __intVal(w);
-
- while (_pixels--) {
- byte1 = *srcP;
- byte2 = *(srcP+1);
- byte3 = *(srcP+2);
- srcP += 3;
- for (i=_mag; i>0; i--) {
- *dstP = byte1;
- *(dstP+1) = byte2;
- *(dstP+2) = byte3;
- dstP += 3;
- }
- }
- RETURN (self);
+ _mag = __intVal(mX);
+ srcP = __ByteArrayInstPtr(srcBytes)->ba_element - 1 + __intVal(srcStart);
+ dstP = __ByteArrayInstPtr(dstBytes)->ba_element - 1 + __intVal(dstStart);
+ _pixels = __intVal(w);
+
+ while (_pixels--) {
+ byte1 = *srcP;
+ byte2 = *(srcP+1);
+ byte3 = *(srcP+2);
+ srcP += 3;
+ for (i=_mag; i>0; i--) {
+ *dstP = byte1;
+ *(dstP+1) = byte2;
+ *(dstP+2) = byte3;
+ dstP += 3;
+ }
+ }
+ RETURN (self);
}
%}.
- super
- magnifyRowFrom:srcBytes offset:srcStart
- into:dstBytes offset:dstStart factor:mX
+ super
+ magnifyRowFrom:srcBytes offset:srcStart
+ into:dstBytes offset:dstStart factor:mX
! !
!Depth24Image methodsFor:'queries'!
@@ -3025,5 +3025,5 @@
!Depth24Image class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.83 2004-03-20 13:35:45 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libview/Depth24Image.st,v 1.84 2007-01-24 13:41:20 cg Exp $'
! !