Author Topic: 16 bit textures  (Read 18883 times)

mav

  • *
  • Posts: 239
  • The Sauce team
    • View Profile
16 bit textures
« Reply #25 on: 2004-08-18 08:58:28 »
Yep, dark colors would be lighter.

fuchisasquatch

  • *
  • Posts: 111
    • View Profile
    • http://aa.1asphost.com/sasquatch/
16 bit textures
« Reply #26 on: 2004-08-18 08:59:50 »
oh no woops it would work

eg.

(31 + 1) * 8 = 256

and max color range for BMP is 255..so yeah

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
16 bit textures
« Reply #27 on: 2004-08-18 10:34:06 »
also black will be grayish (0+1) * 8 = dark gray

fuchisasquatch

  • *
  • Posts: 111
    • View Profile
    • http://aa.1asphost.com/sasquatch/
16 bit textures
« Reply #28 on: 2004-08-18 10:43:06 »
Yeah it would be. I was thinking bout this for ages and trying all this crap. Weird its confusing. I also searched around and couldnt find anything. But id suggest saving as 24bit BMP anyway since you dont require a palette. But the conversion between ARGB1555 to RGB888 still needs to be worked on.

sfx1999

  • *
  • Posts: 1142
    • View Profile
16 bit textures
« Reply #29 on: 2004-08-18 15:20:34 »
What if you multiplied by 8.23 instead?


31 * 8.23 = 255.14

mav

  • *
  • Posts: 239
  • The Sauce team
    • View Profile
16 bit textures
« Reply #30 on: 2004-08-18 18:22:47 »
Mirex, can't you post source code from Biturn that handles conversion of 16 bit TEX files to BMP ?

sfx1999

  • *
  • Posts: 1142
    • View Profile
16 bit textures
« Reply #31 on: 2004-08-18 19:38:00 »
Do what I said and make a lookup table like this:

00000 00000000
00001 00001000
00010 00010000
...
...
11110 11110111
11111 11111111

Basically multiply the first number by 8.23 to make a table.

fuchisasquatch

  • *
  • Posts: 111
    • View Profile
    • http://aa.1asphost.com/sasquatch/
16 bit textures
« Reply #32 on: 2004-08-19 07:29:36 »
hmm i was thinking and i though would this work

use delphi's round function or similar to do something like

newcolval = Round(colorval * (255 / 31))

i dunno if thats sure to work..but give it a try..

EDIT: oh woops thats kinda similar to what sfx1999 said..but i guess that the above way is more accurate even though the rounding off would give the same or very similar answer..

mav

  • *
  • Posts: 239
  • The Sauce team
    • View Profile
16 bit textures
« Reply #33 on: 2004-08-19 07:37:24 »
It works :o.
Thanks fuchisquatch :).

Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
var rgb: word;
r,g,b: byte;
fs: tfilestream;
begin
  rgb := $6339;
  r := (rgb and $7C00) shr 10;
  g := (rgb and $3E0) shr 5;
  b := (rgb and $1F);
  r := Round(r * (255 / 31));
  g := Round(g * (255 / 31));
  b := Round(b * (255 / 31));
  fs := tfilestream.Create('test', fmCreate);
  fs.Write(b, sizeof(b));
  fs.Write(g, sizeof(g));
  fs.Write(r, sizeof(r));
end;


*runs Delphi*
Now I can implement this to my prog :).

fuchisasquatch

  • *
  • Posts: 111
    • View Profile
    • http://aa.1asphost.com/sasquatch/
16 bit textures
« Reply #34 on: 2004-08-19 07:46:03 »
Oh cool  :D

Man im downloading delphi right now.

I use VB and i can do almost whatever i want and can do with it..but it just pisses me off sometimes..

It doesnt support signed/unsigned longs..and dont even think about quads and floats.. (I needed signed longs in the texture reading program for the 32bit data)

And also the support files you need to distribute with your applications or have a VB run time pack that really annoys me..so yeah im making a switch.

Its good that delphi looks really simple and maybe just as easy as VB. Hmm i would use C/C++ and even learnt everything there is to know about console programming, but when i went into Win32 applications or tried MFC it was just so friggen complicated and at that time i didnt really see a need for C/C++ anyway.

mav

  • *
  • Posts: 239
  • The Sauce team
    • View Profile
16 bit textures
« Reply #35 on: 2004-08-19 07:51:19 »
I downloaded an addon for Delphi called Castalia 2 yesterday. It's great because it helps you write code while you're writing it, and not as default - when you compile it. For example:



Normally you don't see these colour lines, but they help.

Link: Castalia 2.5

Btw: I didn't even bother what means signed and unsigned, but I see this is some important stuff... Can someone explain this to me ?

fuchisasquatch

  • *
  • Posts: 111
    • View Profile
    • http://aa.1asphost.com/sasquatch/
16 bit textures
« Reply #36 on: 2004-08-19 08:00:30 »
Oh right.

Well signed numbers range from a negative value to a positive value where unsigned numbers range from 0 to a higher postive value.

Normally you wouldnt really need to use unsigned numbers unless your involving some advanced calculation and you would use signed numbers for reading data that has no chance of being negative (e.g. file sizes, image widths, ect.)

Unsigned and signed numbers have the same number of bytes so for example:

Signed bytes range from the value -128 to 127
Unsinged bytes range from the value 0 to 255

So you see that if you add 128 to 127 you get 255..and as you can see by that they have the same range ammount.

EDIT: Can i ask what version of delphi your running. Im trying to download "Borland Delphi v7 Studio Enterprise" is that any good..?

mav

  • *
  • Posts: 239
  • The Sauce team
    • View Profile
16 bit textures
« Reply #37 on: 2004-08-19 08:04:14 »
Now I get it, thanks ;).

I'm using Delphi v7 Personal Enterprise, about 160 Megs, works well :).

fuchisasquatch

  • *
  • Posts: 111
    • View Profile
    • http://aa.1asphost.com/sasquatch/
16 bit textures
« Reply #38 on: 2004-08-19 08:07:37 »
Oh alright then yeah i guess what im downloading is not bad then. Its 135 MB..and i hope its the real thing cause you cant really trust KaZaA.

mav

  • *
  • Posts: 239
  • The Sauce team
    • View Profile
16 bit textures
« Reply #39 on: 2004-08-19 08:34:43 »
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

fuchisasquatch

  • *
  • Posts: 111
    • View Profile
    • http://aa.1asphost.com/sasquatch/
16 bit textures
« Reply #40 on: 2004-08-19 08:46:20 »
Ok well to get the value of the number in the range 0 to 31 you would do

Code: [Select]
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]

  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]

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
16 bit textures
« Reply #41 on: 2004-08-19 09:22:57 »
Quote
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]
mul = ( 255 / 31 );
rgb = (( r / mul ) shl 10 ) +
      (( g / mul ) shl 5 ) +
      ( b / mul ) ;

mav

  • *
  • Posts: 239
  • The Sauce team
    • View Profile
16 bit textures
« Reply #42 on: 2004-08-19 09:59:32 »
I ended up with this code:

Code: [Select]
       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

mirex

  • *
  • Posts: 1645
    • View Profile
    • http://mirex.mypage.sk
16 bit textures
« Reply #43 on: 2004-08-19 10:18:55 »
hey nice homepage

mav

  • *
  • Posts: 239
  • The Sauce team
    • View Profile
16 bit textures
« Reply #44 on: 2004-08-19 10:29:17 »
Please write some comment it you've been there, you  can do it on main page.

Cyberman

  • *
  • Posts: 1572
    • View Profile
16 bit textures
« Reply #45 on: 2004-08-19 17:09:09 »
Quote from: M4v3R
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]
unsigned short RGB;
RGB = (R & 0xFC) <<8;
RGB|= (G & 0xFC) <<2;
RGB|= (B & 0xFC) >> 3;


Delphi
Code: [Select]
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

sfx1999

  • *
  • Posts: 1142
    • View Profile
16 bit textures
« Reply #46 on: 2004-08-19 19:10:14 »
Well, to convert them back, you would do the colors in reverse, like this:

fiveBitR = eightBitR * (31/255)

Cyberman

  • *
  • Posts: 1572
    • View Profile
16 bit textures
« Reply #47 on: 2004-08-19 22:22:25 »
Quote from: sfx1999
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]
(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

fuchisasquatch

  • *
  • Posts: 111
    • View Profile
    • http://aa.1asphost.com/sasquatch/
16 bit textures
« Reply #48 on: 2004-08-20 02:28:30 »
man what the hell sfx1000

Quote

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....

Quote

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..

sfx1999

  • *
  • Posts: 1142
    • View Profile
16 bit textures
« Reply #49 on: 2004-08-20 04:34:24 »
Quote from: fuchisasquatch
man what the hell sfx1000

Quote

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

Quote
Quote

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.