16 bit textures

  • Thread starter Thread starter fuchisasquatch
  • Start date Start date
Status
Not open for further replies.
Ok well to get the value of the number in the range 0 to 31 you would do

Code: [Select]
Code:
texnum = bmpnum / (255 / 31)

then im not sure about delphi as i havent learnt anything bout that yet but can you reverse it like e.g

Code: [Select]
Code:
  r := 10 shr (rgb and $7C00);   g := 5 shr (rgb and $3E0);   b := (rgb and $1F);

or something like that... Just muck around with calculations and see what you can come up with.
[/code]
 
But, here's another problem: Now I want to do whole proccess backwards, so I can convert BMP to TEX. I have 3 color values: r,g and b. How can I make 2 byte 15 bit color from them ?
This or something similair should work:
Code: [Select]
Code:
mul = ( 255 / 31 );rgb = (( r / mul ) shl 10 ) +       (( g / mul ) shl 5 ) +       ( b / mul ) ;
 
I ended up with this code:

Code: [Select]
Code:
        texfs.Read(kolor, sizeof(kolor));        r := (kolor and $7C00) shr 10;        g := (kolor and $3E0) shr 5;        b := (kolor and $1F);        r := Round(r * (255 / 31));        g := Round(g * (255 / 31));        b := Round(b * (255 / 31));        destfs.Write(r, sizeof(r));        destfs.Write(g, sizeof(g));        destfs.Write(b, sizeof(b));

And it seems to be working fine :). Thank you guys. You can find program on my new site.

Link: MaV's Page
 
Please write some comment it you've been there, you  can do it on main page.
 
I did it! :D

But, here's another problem: Now I want to do whole proccess backwards, so I can convert BMP to TEX. I have 3 color values: r,g and b. How can I make 2 byte 15 bit color from them ? :P
C/C++
Code: [Select]
Code:
unsigned short RGB;RGB = (R & 0xFC) <<8;RGB|= (G & 0xFC) <<2;RGB|= (B & 0xFC) >> 3;

Delphi
Code: [Select]
Code:
RGB := ( R and $FC) shl 8;RGB := RGB or ((G and $FC) shl 2);RGB := RGB or ((B and $FC) shr 3);

That should pack things correctly for you.

Cyb
 
Well, to convert them back, you would do the colors in reverse, like this:

fiveBitR = eightBitR * (31/255)
 
Well, to convert them back, you would do the colors in reverse, like this:

fiveBitR = eightBitR * (31/255)
hmmm I'm not sure you understand the problem you are creating by doing it this way let me explain (knowing a fair amount about compilors).

if you want to use only integer math this is much better Code: [Select]
Code:
(R8 * 31)/255
, this results in taking the integer multiplying it by 31 then deviding the result by 255. Otherwise the compilor will do this instead, 31/255 result is < 1, thus it will create the floating point constant of 31/255. Then it will convert your R8 value to floating point (at runtime) multiply it by the 31/255 constant and convert the result back to an integer and store that integer as the result.  The difference is this has quite a few more operations involved and also involves 3 floating point operations.  If he wants to do it fast, it's definately not the fast way to do it.

Of course we could then discuse doing this using mmx instructions which is much faster, however It's not really that important to go on and on about how to make the code faster. :lol:

This is so you know that you need to consider what it is you are doing carefully, if you don't wish to have unintended consequences in your code.

Cyb
 
man what the hell sfx1000

Well, to convert them back, you would do the colors in reverse, like this:

fiveBitR = eightBitR * (31/255)

thats exactly the same friggen thing i wrote....

Ok well to get the value of the number in the range 0 to 31 you would do

Code:
texnum = bmpnum / (255 / 31)

* (31 / 255) is the same thing as / (255 / 31) and why are you guys posting crap when he already said he got it to work..
 
man what the hell sfx1000

Well, to convert them back, you would do the colors in reverse, like this:

fiveBitR = eightBitR * (31/255)

thats exactly the same friggen thing i wrote....

It is not the same what are you talking about. Look at this:

(255) * (31/255) = ~31
(255) * (255/31) = ~2097

If you are accusing me of stealing your idea, I didn't. I got the value 8.23 by taking 255 and dividing it by 31. Look:

255/31 = 8.2258064516129032258064516129032

Also, I just realized you don't need parentheses for that. So this would work:

y = x * 31 / 255
x = y * 255 / 31

Ok well to get the value of the number in the range 0 to 31 you would do

Code:
texnum = bmpnum / (255 / 31)

* (31 / 255) is the same thing as / (255 / 31) and why are you guys posting crap when he already said he got it to work..

Because he said he did not know how to convert back.

Cyberman: why does he need speed? If he is making a renderer it can be done before anything is drawn and if it is plain old converter, then it wouldn't even take a second.
 
Woah woah...

Read it again

It is not the same what are you talking about. Look at this:

(255) * (31/255) = ~31
(255) * (255/31) = ~2097

i was comparing

* (31/255) and / (255/31)

Not what you wrote there..and im not accusing you of stealing my idea i just think its pointless to write the same thing.

I already gave the conversion [ / (255 / 31)] and then you posted practically the same thing.

And yeah i agree with you and that speed thing.

Ok well to get the value of the number in the range 0 to 31 you would do

Code:
texnum = bmpnum / (255 / 31)


* (31 / 255) is the same thing as / (255 / 31) and why are you guys posting crap when he already said he got it to work..

Because he said he did not know how to convert back.

he already figured it out without using that..look here

I ended up with this code:

Code: [Select]
Code:
        texfs.Read(kolor, sizeof(kolor));         r := (kolor and $7C00) shr 10;         g := (kolor and $3E0) shr 5;         b := (kolor and $1F);         r := Round(r * (255 / 31));         g := Round(g * (255 / 31));         b := Round(b * (255 / 31));         destfs.Write(r, sizeof(r));         destfs.Write(g, sizeof(g));         destfs.Write(b, sizeof(b));

And it seems to be working fine . Thank you guys. You can find program on my new site.

Link: MaV's Page

Ok? So you understand what im saying now..?
 
Guys, guys, don't argue :). Problem is over, solution is above, so there's no need to argue ;).
 
Guys, guys, don't argue :). Problem is over, solution is above, so there's no need to argue ;).
So how are you doing? is your project mostly functional? no smoke let out of you brain :D

Cyb
 
Yes, it's functional (sorry for long respond, I've been on vacation). You can find it on my page (www button :)).
 
Status
Not open for further replies.
Back
Top