1. Help needed with C stuff again
- Posted by Mark Brown <mabrown at SENET.COM.AU> Nov 19, 2000
- 388 views
- Last edited Nov 20, 2000
------=_NextPart_000_0007_01C05261.CF874CF0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi everyone. I have a simple 'C' Morfit example I am trying to convert to Euphoria. The example in C has the following.... BYTE *pixels=3DMorfit_bitmap_get_memory(bitmap_handle); WORD *palette=3DMorfit_bitmap_get_palette(bitmap_handle); The returns are pointers to memory that hold a bitmap and a palette. Also the following.... WORD color16=3Dpalette[pixels[y*width+x]]; The line above has me a bit stumped. It seems to be using one pointer as an index to another? It is in a pair of nested for loops, = incrementing x and y. My wrap of the two functions just returns the pointers (the same as with = C) The result is passed to the following function.... Morfit_utilities_rgb16_to_rgb24(color16, (BYTE *)&red, (BYTE *)&green, = (BYTE *)&blue); Any help with wrapping that line would be greatly appreciated! Thanks Mark ------=_NextPart_000_0007_01C05261.CF874CF0 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi everyone.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>I have a simple 'C' Morfit example I am = trying to=20 convert to Euphoria.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>The example in C has the = following....</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>BYTE=20 <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>The returns are pointers to memory that = hold a=20 bitmap and</FONT></DIV> <DIV><FONT face=3DArial size=3D2>a palette.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Also the following....</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>WORD=20 <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>The line above has me a bit stumped. It = seems to be=20 using one pointer</FONT></DIV> <DIV><FONT face=3DArial size=3D2>as an index to another? It is in a pair = of nested=20 for loops, incrementing</FONT></DIV> <DIV><FONT face=3DArial size=3D2>x and y.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>My wrap of the two functions just = returns the=20 pointers (the same as with </FONT></DIV> <DIV><FONT face=3DArial size=3D2>C)</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>The result is passed to the following=20 function....</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial = size=3D2>Morfit_utilities_rgb16_to_rgb24(color16, (BYTE=20 *)&red, (BYTE *)&green, (BYTE *)&blue);</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Any help with wrapping that line would = be greatly=20 appreciated!</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Thanks</FONT></DIV> <DIV> </DIV> ------=_NextPart_000_0007_01C05261.CF874CF0--
2. Re: Help needed with C stuff again
- Posted by Mark Brown <mabrown at SENET.COM.AU> Nov 19, 2000
- 373 views
- Last edited Nov 20, 2000
------=_NextPart_000_0025_01C05267.89A2A260 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Hi again Just realised my mail was terrible. To save you guys unnecessary work I only need help to understand WORD color16=3Dpalette[pixels[y*width+x]]; Many thanks Mark ------=_NextPart_000_0025_01C05267.89A2A260 charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML><HEAD> <META content=3D"text/html; charset=3Diso-8859-1" = http-equiv=3DContent-Type> <META content=3D"MSHTML 5.00.2920.0" name=3DGENERATOR> <STYLE></STYLE> </HEAD> <BODY bgColor=3D#ffffff> <DIV><FONT face=3DArial size=3D2>Hi again</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>Just realised my mail was = terrible.</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2>To save you guys unnecessary work I = only need help=20 to understand</FONT></DIV> <DIV> </DIV> <DIV><FONT face=3DArial size=3D2> <DIV><FONT face=3DArial size=3D2>WORD=20 <DIV> </DIV> <DIV> </DIV> <DIV>Many thanks</DIV> <DIV> </DIV> ------=_NextPart_000_0025_01C05267.89A2A260--
3. Re: Help needed with C stuff again
- Posted by David Cuny <dcuny at LANSET.COM> Nov 19, 2000
- 388 views
Mark Brown wrote: > WORD color16=palette[pixels[y*width+x]]; Here's an example: imagine that you wanted to store all the pixels on the screen in a 1 dimensional array. For simplicity, imagine that the screen was 5x5: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 Since most of the computing world starts counting from zero, I've also done so in the example. The first pixel on the second line is #05, the second pixel on the third line is #11, and so on. The general formula for finding the index of a given pixel is: ( y * screenWidth ) + x That obviously corresponds to the formula: y*width+x So what's actually *stored* in that pixel's location? Color information, of course. The actual color isn't stored there, it's just an index to the palette. For example, here's a box drawn on our example screen. The box's edges are color #1, and it's filled with color #2, and everything else is color 0: 1 1 1 1 0 1 2 2 1 0 1 2 2 1 0 1 1 1 1 0 0 0 0 0 0 Internally, this looks like this: pixel[00] = 1 -- (0,0) pixel[01] = 1 -- (1,0) pixel[02] = 1 -- (2,0) pixel[03] = 1 -- (3,0) pixel[04] = 0 -- (4,0) pixel[05] = 1 -- (0,1) pixel[06] = 2 -- (1,1) pixel[07] = 2 -- (2,1) pixel[08] = 1 -- (3,1) pixel[09] = 0 -- (4,1) pixel[10] = 1 -- (0,2) pixel[11] = 2 -- (1,2) pixel[12] = 2 -- (2,2) pixel[13] = 1 -- (3,2) pixel[14] = 0 -- (4,2) pixel[15] = 1 -- (0,3) pixel[16] = 1 -- (1,3) pixel[17] = 1 -- (2,3) pixel[18] = 1 -- (3,3) pixel[19] = 0 -- (4,3) pixel[20] = 0 -- (0,4) pixel[21] = 0 -- (1,4) pixel[22] = 0 -- (2,4) pixel[23] = 0 -- (3,4) pixel[24] = 0 -- (4,4) So you can get the index of the color for a pixel by writing: pixels[y*width+x] That's fine and good, but what color is color #1? To find that out, you need to look in the palette: palette[1] -> color #1, in color16 format What's color16 format? I don't know, but a color component is typically made up of some mixture of red, green and blue. If you have 16 bits to use over three color elements, that's five bits per color element. So you can have 2^5 (or 2^4, it's late and I can't remember) shades of each color component to mix together. To recap, to figure out what color is being displayed at a given pixel location: y*width+x gets the offset to a particular pixel; pixels[y*width+x] retrieves the index into the palette of the color that's set for that pixel; palette[pixels[y*width+x]] retrieves the color16 value from the palette. As I mentioned, I don't have enough information available to decode the color16 value. I hope this helps! -- David Cuny
4. Re: Help needed with C stuff again
- Posted by Mark Brown <mabrown at SENET.COM.AU> Nov 20, 2000
- 390 views
- Last edited Nov 21, 2000
I just wrote! (but it seems to have disappeared out there in email land...) >Hi David. >Thanks for the excellent answer. >I think I understand. I peek a WORD from "pixels+(y*width+x)" to get >the index into the palette and then I peek a WORD from "pallette + index" >to get the actual 16-bit RGB value? >Now if only I could work out why all 4 wheels in Landrover6 are spinning >around each other insted of each wheel spinning on its own axis! >Examples 1 to 5 worked so well. Sigh..... >All the best. OOPS. I would peek a byte not a word from "pixels+(y*width+x)" because pixels is a BYTE* right? Gives me a BYTE sized index?? I think I hate C. Mark : )
5. Re: Help needed with C stuff again
- Posted by Mark Brown <mabrown at SENET.COM.AU> Nov 20, 2000
- 385 views
- Last edited Nov 21, 2000
Hi David. Thanks for the excellent answer. I think I understand. I peek a WORD from "pixels+(y*width+x)" to get the index into the palette and then I peek a WORD from "pallette + index" to get the actual 16-bit RGB value? Now if only I could work out why all 4 wheels in Landrover6 are spinning around each other insted of each wheel spinning on its own axis! Examples 1 to 5 worked so well. Sigh..... All the best. Mark ----- Original Message ----- From: "David Cuny" <dcuny at LANSET.COM> To: <EUPHORIA at LISTSERV.MUOHIO.EDU> Sent: Sunday, November 19, 2000 9:04 PM Subject: Re: Help needed with C stuff again > Mark Brown wrote: > > > WORD color16=palette[pixels[y*width+x]]; > > Here's an example: imagine that you wanted to store all the pixels on the > screen in a 1 dimensional array. For simplicity, imagine that the screen was > 5x5: > > 00 01 02 03 04 > 05 06 07 08 09 > 10 11 12 13 14 > 15 16 17 18 19 > 20 21 22 23 24 > > Since most of the computing world starts counting from zero, I've also done > so in the example. > The first pixel on the second line is #05, the second pixel on the third > line is #11, and so on. The general formula for finding the index of a given > pixel is: > > ( y * screenWidth ) + x > > That obviously corresponds to the formula: > > y*width+x > > So what's actually *stored* in that pixel's location? Color information, of > course. The actual color isn't stored there, it's just an index to the > palette. For example, here's a box drawn on our example screen. The box's > edges are color #1, and it's filled with color #2, and everything else is > color 0: > > 1 1 1 1 0 > 1 2 2 1 0 > 1 2 2 1 0 > 1 1 1 1 0 > 0 0 0 0 0 > > Internally, this looks like this: > > pixel[00] = 1 -- (0,0) > pixel[01] = 1 -- (1,0) > pixel[02] = 1 -- (2,0) > pixel[03] = 1 -- (3,0) > pixel[04] = 0 -- (4,0) > pixel[05] = 1 -- (0,1) > pixel[06] = 2 -- (1,1) > pixel[07] = 2 -- (2,1) > pixel[08] = 1 -- (3,1) > pixel[09] = 0 -- (4,1) > pixel[10] = 1 -- (0,2) > pixel[11] = 2 -- (1,2) > pixel[12] = 2 -- (2,2) > pixel[13] = 1 -- (3,2) > pixel[14] = 0 -- (4,2) > pixel[15] = 1 -- (0,3) > pixel[16] = 1 -- (1,3) > pixel[17] = 1 -- (2,3) > pixel[18] = 1 -- (3,3) > pixel[19] = 0 -- (4,3) > pixel[20] = 0 -- (0,4) > pixel[21] = 0 -- (1,4) > pixel[22] = 0 -- (2,4) > pixel[23] = 0 -- (3,4) > pixel[24] = 0 -- (4,4) > > So you can get the index of the color for a pixel by writing: > > pixels[y*width+x] > > That's fine and good, but what color is color #1? To find that out, you need > to look in the palette: > > palette[1] -> color #1, in color16 format > > What's color16 format? I don't know, but a color component is typically made > up of some mixture of red, green and blue. If you have 16 bits to use over > three color elements, that's five bits per color element. So you can have > 2^5 (or 2^4, it's late and I can't remember) shades of each color component > to mix together. > > To recap, to figure out what color is being displayed at a given pixel > location: > > y*width+x > > gets the offset to a particular pixel; > > pixels[y*width+x] > > retrieves the index into the palette of the color that's set for that pixel; > > palette[pixels[y*width+x]] > > retrieves the color16 value from the palette. As I mentioned, I don't have > enough information available to decode the color16 value. > > I hope this helps! > > -- David Cuny
6. Re: Help needed with C stuff again
- Posted by Mark Brown <mabrown at SENET.COM.AU> Nov 20, 2000
- 426 views
- Last edited Nov 21, 2000
Thanks again David. The example is working fine now. All the best Mark