Possible fix for Form>>bmpColorsFrom:count:depth:

Kevin Fisher kfisher at rim.net
Wed Feb 3 12:10:03 UTC 1999


Ah, even better. :)  Your fix saves a few iterations over mine, that's for sure.
I wasn't certain whether or not the colourmap size should be used to create
the colourmap array or not, that's why I left it be... I noticed at least one
method in ColorForm that used 'colors size' and the colors variable
in seperate ways and I wasn't sure if changing the max. size of the colourmap
array would adversely affect anything. :)  Everything seems to work
okay though!


On Tue, 02 Feb 1999, Maurice Rabb wrote:
>>'From Squeak 2.3 of January 14, 1999 on 2 February 1999 at 1:37:04 pm'!
>>
>>!Form class methodsFor: 'BMP file reading' stamp: 'kgf 2/1/1999 16:04'!
>>bmpColorsFrom: aBinaryStream count: colorCount depth: depth
>>	"Read colorCount BMP color map entries from the given binary
>>stream. Answer an array of Colors."
>>
>>	| maxLevel colors b g r |
>>	colorCount = 0 ifTrue: [  "this BMP file does not have a color
>map"
>>		"default monochrome color map"
>>		depth = 1 ifTrue: [^ Array with: Color white with: Color
>>black].
>>		"default gray-scale color map"
>>		maxLevel _ (2 raisedTo: depth) - 1.
>>		^ (0 to: maxLevel) collect: [:level | Color gray: (level
>>asFloat / maxLevel)]].
>>
>>
>>	colors _ Array new: (2 raisedTo: depth).
>>	1 to: colorCount do: [:i |
>>		b _ aBinaryStream next.
>>		g _ aBinaryStream next.
>>		r _ aBinaryStream next.
>>		aBinaryStream skip: 1.
>>		colors at: i put: (Color r: r g: g b: b range: 255)].
>>	colorCount to: (colors size) do: [:i |
>>		colors at: i put: (Color r: 0 g: 0 b: 0 range: 255)].
>>	^ colors
>>! !
>
>Kevin--
>
>While your fix is correct, I think it is over kill.
>
>Look at: ColorForm>>#colors:.  It expects a list of colors.  If the list
>is
>of size less than the number of slots in the color table, it fills the
>rest
>with 0's (Color transparent).  So you don't think you need to build the
>extra color yourself.  See the code below.
>
>I think this will work.
>
>Happy Squeaking!
>
>--Maurice
>
>
>!Form class methodsFor: 'BMP file reading' stamp: 'm3r 2/1/1999 14:20'!
>bmpColorsFrom: aBinaryStream count: colorCount depth: depth
>	"Read colorCount BMP color map entries from the given binary
>stream. Answer an array of Colors."
>
>	| maxLevel colors b g r |
>	colorCount = 0 ifTrue: [  "this BMP file does not have a color
>map"
>		"default monochrome color map"
>		depth = 1 ifTrue: [^ Array with: Color white with: Color
>black].
>		"default gray-scale color map"
>		maxLevel _ (2 raisedTo: depth) - 1.
>		^ (0 to: maxLevel) collect: [:level | Color gray: (level
>asFloat / maxLevel)]].
>
>	colors _ Array new: colorCount.
>	1 to: colorCount do: [:i |
>		b _ aBinaryStream next.
>		g _ aBinaryStream next.
>		r _ aBinaryStream next.
>		aBinaryStream skip: 1.
>		colors at: i put: (Color r: r g: g b: b range: 255)].
>	^ colors
>! !
>
>------------------------------------------------------------------------
>---
>  Maurice Rabb    773.281.6003    Stono Technologies, LLC    Chicago,
>USA





More information about the Squeak-dev mailing list