Hi all:
I'm just toying around with some of the system morphs. I've been trying to evaluate the following snippet in a workspace:
| syswin button frm |
frm _ Form fromBMPFileNamed: 'close.bmp'. syswin _ SystemWindow labelled: 'test'. button _ ThreePhaseButtonMorph new. button offImage: frm. button extent: 16@16. syswin addMorph: button.
syswin openInWorld.
.....where close.bmp is a little 16x16 BMP file.
However, when I evaluate this, I get a LOT of debugger popup windows which seem to be complaining about ColorForm>>colormapIfNeededForDepth. As far as I can tell it seems that the message pixelValueForDepth is being sent to 'nil' in:
1 to: colors size do: [:i | newMap at: i put: ((colors at: i) pixelValueForDepth: destDepth)].
When I inspect 'colors' it contains many values, but has a large section at the end filled with 'nil'...looks like the 'nil's shouldn't be there. Upon further inspection it seems that the 'nil's are coming right from the Form object, specifically in what gets read by fromBMPFileNamed.
So, inspection of Form>>bmpColorsFrom:count:depth: revealed:
| 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)]. ^ colors
How I read this is that a generic color map is created based upon the depth. The colors are translated from the BMP file into the map using the colorCount as an index. This leaves the remainder of the map unassigned (set to nil).
So, my question to someone who understands BMP's in the scheme of Squeak is...should the unfilled sections of the colour map be set to 'nil' (meaning the pixelValueForDepth method has the bugs) or, should the unfilled sections be set to black or some other generic colour (meaning the bmpColorsFrom method is the culprit)?
squeak-dev@lists.squeakfoundation.org