# HG changeset patch # User Claus Gittinger # Date 1437736405 -7200 # Node ID 98a659b6bd106d45f9116889be4c5258e9eb6939 # Parent 38d493fcc782dfd67e815a67f2910486c513d769 class: ImageEditor changed: #sortColorMapWith: diff -r 38d493fcc782 -r 98a659b6bd10 ImageEditor.st --- a/ImageEditor.st Tue Jul 07 12:42:46 2015 +0200 +++ b/ImageEditor.st Fri Jul 24 13:13:25 2015 +0200 @@ -6184,14 +6184,16 @@ sortColorMapWith:sortBlock "calculates a new color map for the image, sorting colors" - |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits| + |depth newColorMap newImage oldImage usedColors oldToNew oldBits newBits tmpBits + expectedSize w h| oldImage := self image. depth := oldImage depth. + w := oldImage width. + h := oldImage height. usedColors := oldImage realColorMap. - "/ translation table oldToNew := ByteArray new:(1 bitShift:depth). newColorMap := usedColors asArray. @@ -6207,35 +6209,37 @@ ]. oldBits := oldImage bits. + "/ sanity check... + expectedSize := ((w * h * depth + 7) // 8). + (oldBits size < expectedSize) ifTrue:[ + self halt:'incorrect pixeldata size'. + oldBits := (ByteArray new:expectedSize) replaceFrom:1 with:oldBits; yourself. + ]. newBits := ByteArray new:(oldBits size). depth ~~ 8 ifTrue:[ + "/ expand/compress can only handle 8bits - tmpBits := ByteArray uninitializedNew:(oldImage width*oldImage height). + tmpBits := ByteArray uninitializedNew:(w*h). oldBits expandPixels:depth - width:oldImage width - height:oldImage height + width:w height:h into:tmpBits mapping:oldToNew. tmpBits compressPixels:depth - width:oldImage width - height:oldImage height + width:w height:h into:newBits mapping:nil ] ifFalse:[ oldBits expandPixels:depth - width:oldImage width - height:oldImage height + width:w height:h into:newBits mapping:oldToNew. ]. newImage := oldImage species new - width:oldImage width - height:oldImage height - depth:depth + width:w height:h depth:depth fromArray:newBits. newImage colorMap:newColorMap.