Form manipulation from a Plugin
diegogomezdeck at consultar.com
diegogomezdeck at consultar.com
Mon Apr 7 14:36:23 UTC 2003
Thank you very much for you answer, it help me a lot! I just included all
these sanity checks to my code.
But I still don't find the way to get the alpha part of pixel. With this
alpha := (pixel bitAnd: 16rFF000000) >> 24.
alpha is always 0. Is It the way to get the alpha part for pixels in 32
The other 3 bytes hold the RGB triplet and I can access them without
> There are actually various problems in the code you're quoting. A safe
> way to deal with this is along the following lines:
> | formOop bitsOop bitsPtr |
> self var: #bitsPtr type: 'unsigned int*'.
> "... grab other stuff before..."
> bitsOop := interpreterProxy fetchPointer: 0 ofObject: formOop.
> "first test if bitsOop is really what we're expecting"
> ((interpreterProxy isInteger: bitsOop) or:[
> (interpreterProxy isWords: bitsOop) not])
> ifTrue:[^interpreterProxy primitiveFail].
> [note: those tests above *MUST* be done as it is quite possible that
> forms contain either integers (surface references) or byte arrays
> (hibernated). Not testing for this will hose your system].
> "now test if the length of the bitmap is right"
> (interpreterProxy slotSizeOf: bitsOop) = expectedSize
> ifFalse:[^interpreterProxy primitiveFail]
> [again, this test is needed if for some reason the format of the form
> has been screwed up. the expectedSize here is whatever the number of
> words for a form of that size/depth is expected to be; e.g., for a
> 32bpp form just width*height]
> "now grab the pointer to the bits"
> bitsPtr := interpreterProxy firstIndexableField: bitsOop.
> [At this point you have a C 'unsigned int *' pointer to those bits. If
> you wanted to work on a byte pointer instead you could just change the
> declaration to be 'unsigned char *' but watch the indexing!]
> 0 to: expectedSize-1 do:[:i| "for all words..."
> pixel := bitsPtr at: i.
> ... etc ...
> You should be pretty safe doing it the above way as it will ensure all
> of the invariants are checked.
> - Andreas
>> -----Original Message-----
>> From: squeak-dev-bounces at lists.squeakfoundation.org
>> [mailto:squeak-dev-bounces at lists.squeakfoundation.org] On
>> Behalf Of diegogomezdeck at consultar.com
>> Sent: Monday, April 07, 2003 3:58 PM
>> To: squeak-dev at lists.squeakfoundation.org
>> Subject: Form manipulation from a Plugin
>> Hi list...
>> I'm processing a 32 bits Form in a slang-plugin.
>> The method receive the Form as a parameter:
>> formOop := interpreterProxy stackObjectValue: 1.
>> Then I ask for widht, height and a pointer to bits:
>> bits := interpreterProxy fetchPointer: 0 ofObject: formOop.
>> width := self fetchIntOrFloat: 1 ofObject: formOop.
>> height := self fetchIntOrFloat: 2 ofObject: formOop.
>> Then I iterate over the bits:
>> to: bits + (height - 1 * (width * 4))
>> by: 4
>> do: [:pos |
>> pixel := interpreterProxy longAt: pos.
>> alpha := (pixel bitAnd: 16rFF000000) >> 24.
>> <some other stuff>
>> The problem I have is the following: The alpha part of pixel
>> is always 0.
>> (I don't need to say that the form has not transparent colors)
>> Any idea of my problem?
>> Diego Gomez Deck
More information about the Squeak-dev