Raydium 3D Game Engine

Official forum for everything about Raydium, ManiaDrive, MeMak, ...
It is currently Tue Apr 16, 2024 11:48 am

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Tga file flip
PostPosted: Thu Oct 16, 2008 5:42 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

Raydium can now read compressed Tga (Rev 794).

There is still a problem with vertical flipped tga file.

It seem's that all original raydium tga texture file are flipped whatever the header bit indicate in the tga file.

Here is a patch to clean up (i hope) tga flip handling.

Can you test it on your media files a report bug s and others.

http://ftp.cqfd-corp.org/tga_flip_path.patch

Some day we have to clean up verticla flip bit from files in the repository.

And thus handle all tga file and flipped bit correctly.

Hope it is not mismatch from my files.

Have a nice day
Ouille.


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Thu Oct 16, 2008 7:10 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Well, it looks correct to me ... I've checked most of my applications (including webcam stuffs full of OSD hacks), and nothing wrong to report. But ... cursors ! :) (all of them are flipped)


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sat Oct 18, 2008 2:15 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

It is impossible :roll: !!!!!

Cursor here is ok, and it can't be plateform specific !

Cursor have a strange behavior it is marked as y flipped, but it isn't (from my point of view).

Who can make some tests and report texture,cursor,fonts, ... are flipped or not.

I'll clean up my media files to test from fresh files from repository.

Have a nice day
Ouille.


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sat Oct 18, 2008 10:10 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello

Here is my work in progress:

It seems that texture for skybox(s) and cursor does not respect all others textures format.

Here is a new and simpliest patch.
http://ftp.cqfd-corp.org/raydium_tga_flip_patch2.patch

This patch use standart tga file reading (raw and rle compressed), and manage on the "right" :?: way the mirror information bits from the header.
Doing this exhibit two problems :( : cursor and skybox.
I change the way for cursor and skybox drawing (glTexCoord2f), like this thoses specific flipped texture will be correctly drawn.
But any new design of cursor or skybox, need to be flipped verticaly.

I've tested this patch with all the raydium examples :P , there is still two problems:
radiosity texture for camplay et kinghill. :x
Thoses texture are also flipped verticaly. Importing the scene with blender doesn't show good results.

Xfennec can you confirm that thoses texture were manualy flipped ? :?:

So: using this patch, allow natural handling of all texture file, except:
skybox and cursor wich are handled directly by the patch.
3 radiosity texture need to be corrected in the repository.

Tests welcomes and bugs reports ...

Last did we apply this patch to the trunk ?
Don't we need to correct cursor and skybox repository files to have normal tga file handling ?

Have a nice day
Ouille.


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sun Oct 19, 2008 7:35 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
There's one strange point I don't understand here: when I open BOXmania_cursor.tga and BOXcursor.tga in Gimp, Electric Eyes or ImageMagick, the display is correct, not flipped.
It means, whatever the y-flipped flag is set or not, that these textures are "correct". So why are we struggling to get a correct behavior then ?

(Or perhaps none of these programs take care of that flag ?)


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sun Oct 19, 2008 8:32 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

I'm very very ennoyed. :oops:

File are correct here too. They are not marked as flipped, in the tga header.

The only solution to have all "old" raydium tga file ok is to force y-flip, whatever this flag is, except for cursor.
If i do this, all compressed "new" texture are y-flipped as blender doesn't save with this bit set.

Here are the fact:

1) Originaly all texture where loaded y-flipped
Code:
k= (ty-j-1)*tx ...


2) About radiosity : direct import with blender exhibit texture verticaly flipped, on your models to (output.tri for example).

3) Flipped handling was limited to the cursor, i don't know why .


Look at my code, there is no trick. The only possible bug are:
- inverted X and Y flip.
- inverted bit management.

For X/Y i'm quite sure and tests i've done seem's ok.

inverted bit management, never solve for all media files. (good becomes bad and bas becomes good).

Blender script only load image file, doesn't touch anything about flip (image or uv).


Use of only one program wich doesn't handle thoses bit correctly is perhaps the clue ?

Do you have to flip tga files sometimes ?

Can you have a deeper look at my code, i don't want to make a very stupid mistake (forgotten somthing or misunderstanding).

Try to import output.tri with blender.

Have a nice day.
Ouille


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sun Oct 19, 2008 9:33 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Please note that, since ages, Raydium used to do not care about "flip-flag". Vicente starts adding support somewhere around commit 661, so all this is very new.

Reading the TGA spec*, it seems to me that there's perhaps another thing to look at about TGA loading : fields 5.1 and 5.2: X-Origin and Y-Origin of the image. Perhaps some applications use the field 5.2 instead of 5.6 to deal with the upside down trouble when writing TGA files to disc ... Even if it's not the case, if we support the 5.6 field, we must anyway support the 5.2, just in case ... :/

* http://www.dca.fee.unicamp.br/~martino/ ... tgaffs.pdf


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sun Oct 19, 2008 10:55 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
(seems to be a dead-end: just scanned my 734 TGA files, none of them use an origin != 0 ... Same applies for 401 TGA from the official repository)


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sun Oct 19, 2008 11:10 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

I understand like this:

5.1 and 5.2 are absolut origin of the lower left corner of the image. It allow displacement of the image, or offset i don't see how it can handle flip of the image.
Missuse of thoses fields leads in mis aligned texture (or no texture at all), but it can't be corrected just flipping verticaly the texture.

5.5 bit 4 and 5 are organisation of pixel in memory.

So what do you propose ?

On one hand: have a full tga read support seem good, but leads problem.
Vincente cal3d apps raise some flipped texture problems. As this texture seem's ok.

I Just found this:
Here is the cal3d tga flipping code handling. As you can see , if texture is 24bpp it is not flipped.
It look like a bug (?)

Code:
        for(int y=0;y<TgaHeader.SizeY;y++)
        {
            for(int x=0;x<TgaHeader.SizeX;x++)
            {
                if(m_Bpp==8)
                {
                    r=tmp[x+(TgaHeader.SizeY-y-1)*TgaHeader.SizeX];
                    m_dest[x+y*TgaHeader.SizeX]=r;
                }
                if(m_Bpp==32)
                {
                    r=tmp[(x+(TgaHeader.SizeY-y-1)*TgaHeader.SizeX)*4];
                    g=tmp[(x+(TgaHeader.SizeY-y-1)*TgaHeader.SizeX)*4+1];
                    b=tmp[(x+(TgaHeader.SizeY-y-1)*TgaHeader.SizeX)*4+2];
                    a=tmp[(x+(TgaHeader.SizeY-y-1)*TgaHeader.SizeX)*4+3];
                    m_dest[(x+y*TgaHeader.SizeX)*4]=r;
                    m_dest[(x+y*TgaHeader.SizeX)*4+1]=g;
                    m_dest[(x+y*TgaHeader.SizeX)*4+2]=b;
                    m_dest[(x+y*TgaHeader.SizeX)*4+3]=a;


                }
            }

        }


And thus, this correct (i hope so) tga flip handling will probably have to flip files on file by file basis (i can do a very small app to toggle this bit only).
Blender tga support will be full.

On an other hand, we can keep old tga code handling, and old raydium flip bit handling (ignore ;o) . This will be simple and keep compatibility.

I prefer first solution, event if it involve repository update.

I let you the final decison !

Have a nice night !
Ouille


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sun Oct 19, 2008 11:30 pm 
Offline
User avatar

Joined: Sun Mar 16, 2003 2:53 am
Posts: 2591
Location: gnniiiii (Scrat)
Well, I just said somewhere else than one of the main idea of Raydium is to handle as few file formats as possible, but to handle it well, so introducing a compatibility break here is not absolutely unacceptable.

But we must really take care of a such change. It's not just a repository problem: I've scanned my main "private" data directory, and ~10% of my TGA files have "bottom left" tag set (that's Gimp default). It's pretty reasonable to think that the average Raydium user have the same amount of "broken" textures. Some ManiaDrive textures are concerned, too, it seems. I'm just thinking about the terrible consequences it can have for the game since some Linux distro are packaging Raydium as a separate library (Fedora do this), if ManiaDrive data package is not updated at the very same time ... Brrr.

Let me take some time to test a few things and think about the best way to minimize the effect of a such change...

Any idea is welcome.


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sun Oct 19, 2008 11:39 pm 
Offline
User avatar

Joined: Thu Sep 29, 2005 2:59 pm
Posts: 828
Just an idea:
raydium_texture_load checks if texture is incorrect.
If not correct, raydium should backup that file as oldname_backup.tga and overwrite the file fixed (reconstructing the TGA).
So:
1- no extra work for anyone
2-If someone has its source files inverted, this system will fix the resulting tga as many times as needed.


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Sun Oct 19, 2008 11:49 pm 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

Yes Vincente, but really hard:

Old raydium texture need to be flipped whatever the value of the bit.

New ones will handle bit correctly.

So we will install a name list of concerned files, i don't see an other way to detect bad flip.

But the idea is cool.

Have a nice day
Ouille


Top
 Profile  
 
 Post subject: Re: Tga file flip
PostPosted: Mon Oct 20, 2008 12:09 am 
Offline

Joined: Sun Oct 09, 2005 10:46 pm
Posts: 759
Hello,

This is a small program:

run with tga file as parameter.
It give information about flip (x and y) x,y offset too.

you can set or clear y flip bit.

Using my tga file read patch, it can solve all problems.

Waiting for feedback.

It is quite portable i hope.

Ouille

Code:
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char ** argv)
{
FILE *f;
char c;
unsigned char head[18];
    if (argc<2){
        printf("Need tga filename parameter. %d",argc);
        exit(-1);
    }
    f = fopen (argv[1],"rb");
    fread(head,18,1,f);
    fclose(f);
    printf ("Id Length %d\n",head[0]);
   
    if (head[1]==0)
        printf ("No Color Map\n");
    if (head[1]==1)
        printf ("Color Map Present\n");
    if (head[1]>1)
        printf("Color Map Invalid\n");
   
    switch (head[2]){
        case 0: printf ("No Image Data\n");
                break;
        case 1: printf ("Uncompressed Color Mapped\n");
                break;
        case 2: printf ("Uncompressed True Color\n");
                break;
    }
    printf ("Offset X %d\n",head[9]*256+head[8]);
    printf ("Offset Y %d\n",head[11]*256+head[10]);
    printf ("Size X %d\n",head[13]*256+head[12]);
    printf ("Size Y %d\n",head[15]*256+head[14]);
    printf ("Bpp:%d\n",head[16]);
    printf ("FileSpecs:%02X %s %s\n",head[17],((head[17]&0x10)?"Flip X":""),((head[17]&0x20)?"Flip Y":""));
    printf ("Press 'x' to toggle X flip bit, 'y' to toggle Y flip bit\n");
    printf ("Press 's' to save file, 'q' to quit\n");
   
    while ((c=getch())!='q'){
        if (c=='x')
            head[17]^=0x10;
        if (c=='y')
            head[17]^=0x20;
        printf ("New Spec:%02X %s %s\n",head[17],((head[17]&0x10)?"Flip X":""),((head[17]&0x20)?"Flip Y":""));
        if (c=='s'){
            f = fopen (argv[1],"rb+");
            fwrite (head,18,1,f);
            fclose(f);
            printf ("Saved.\n");
            break;
        }
           
    }
    return 0;
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 17 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group