OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 6:02 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Tga image is green
PostPosted: Thu Feb 02, 2023 2:16 pm 
Offline

Joined: Sun Aug 22, 2021 3:11 pm
Posts: 17
Location: Germany
Hi, I have written a uefi application that loads a tga image, which works as far as it goes, but the image I want to load has a green stitch in it. I have already tried a few things but the result is always the same.

Image: https://imgur.com/a/CJDFN4G

Github: https://github.com/rxbin1201/Bootloader

I hope anyone can help me.


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Thu Feb 02, 2023 3:58 pm 
Offline
Member
Member

Joined: Sat Feb 04, 2012 5:03 pm
Posts: 111
At a quick glance, it appears the green value of every pixel is being set to the maximum.


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Thu Feb 02, 2023 4:20 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
You're probably shuffling bytes around in the wrong order.

I'm pretty sure the bytes are already in the correct order inside the TGA file. Call Blt() with your file buffer + 0x12 (to skip the TGA header) and see what you get.


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Fri Feb 03, 2023 9:49 am 
Offline

Joined: Sun Aug 22, 2021 3:11 pm
Posts: 17
Location: Germany
Octocontrabass wrote:
You're probably shuffling bytes around in the wrong order.

I'm pretty sure the bytes are already in the correct order inside the TGA file. Call Blt() with your file buffer + 0x12 (to skip the TGA header) and see what you get.



Unfortunately, the result is exactly the same.


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Fri Feb 03, 2023 10:13 am 
Offline
Member
Member

Joined: Fri Oct 04, 2019 10:10 am
Posts: 48
First 32 bytes of the TGA
Code:
000000 00 00 02 00 00 00 00 00 00 00 00 00 56 05 00 03
000010 20 08 11 0f 15 ff 13 12 18 ff 13 13 19 ff 14 15


0 image ID len
0 color map type (none)
2 image type (uncompressed RGB)
no color map
0 x origin
0 y origin
0x556 width
0x300 height
0x20 bpp (32 bit)
0x08 descriptor (8 bit attribute, origin in lower left, non-interleaved)
pixel data for the lower left is (11 0F 15 FF), in BGRA order

Somehow your parse is stuffing the alpha value into your green channel.

You really should look into using structs, rather than that sea of magic numbers. I think your bug is the + 18 in line 35 of tga.c, which seems to be trying to skip past the header, but m already includes that. Thus your parse code is starting 4.5 pixels into the array, which being BGRA, means your packing code is seeing RABG, albeit from two different pixels each time.


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Fri Feb 03, 2023 10:39 am 
Offline

Joined: Sun Aug 22, 2021 3:11 pm
Posts: 17
Location: Germany
reapersms wrote:
First 32 bytes of the TGA
Code:
000000 00 00 02 00 00 00 00 00 00 00 00 00 56 05 00 03
000010 20 08 11 0f 15 ff 13 12 18 ff 13 13 19 ff 14 15


0 image ID len
0 color map type (none)
2 image type (uncompressed RGB)
no color map
0 x origin
0 y origin
0x556 width
0x300 height
0x20 bpp (32 bit)
0x08 descriptor (8 bit attribute, origin in lower left, non-interleaved)
pixel data for the lower left is (11 0F 15 FF), in BGRA order

Somehow your parse is stuffing the alpha value into your green channel.

You really should look into using structs, rather than that sea of magic numbers. I think your bug is the + 18 in line 35 of tga.c, which seems to be trying to skip past the header, but m already includes that. Thus your parse code is starting 4.5 pixels into the array, which being BGRA, means your packing code is seeing RABG, albeit from two different pixels each time.


Thanks for this answer do you know a solution to fix this?


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Fri Feb 03, 2023 11:15 am 
Offline
Member
Member

Joined: Fri Oct 04, 2019 10:10 am
Posts: 48
Strike that, that bug only applies to types 1 and 9.

Oh, that code came from the wiki, and is broken as all hell. I take back everything nice I ever said about bzt.

I would suggest looking over http://www.paulbourke.net/dataformats/tga/ and writing your own, rather than continuing to use this broken pile of junk, but at the risk of encouraging the cargo cult:

Line 43:
Code:
j = ((!o?h-y-1:y)*w*(ptr[16]>>3)) + m;


I strongly suspect case 1, 9, and 10 of that switch are completely broken.


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Fri Feb 03, 2023 11:45 am 
Offline

Joined: Sun Aug 22, 2021 3:11 pm
Posts: 17
Location: Germany
reapersms wrote:
Strike that, that bug only applies to types 1 and 9.

Oh, that code came from the wiki, and is broken as all hell. I take back everything nice I ever said about bzt.

I would suggest looking over http://www.paulbourke.net/dataformats/tga/ and writing your own, rather than continuing to use this broken pile of junk, but at the risk of encouraging the cargo cult:

Line 43:
Code:
j = ((!o?h-y-1:y)*w*(ptr[16]>>3)) + m;


I strongly suspect case 1, 9, and 10 of that switch are completely broken.


I added + m at the end of the line and now it works fine. Thank you very much for your help.


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Fri Feb 03, 2023 2:01 pm 
Offline

Joined: Sun Aug 22, 2021 3:11 pm
Posts: 17
Location: Germany
robin1201 wrote:
reapersms wrote:
Strike that, that bug only applies to types 1 and 9.

Oh, that code came from the wiki, and is broken as all hell. I take back everything nice I ever said about bzt.

I would suggest looking over http://www.paulbourke.net/dataformats/tga/ and writing your own, rather than continuing to use this broken pile of junk, but at the risk of encouraging the cargo cult:

Line 43:
Code:
j = ((!o?h-y-1:y)*w*(ptr[16]>>3)) + m;


I strongly suspect case 1, 9, and 10 of that switch are completely broken.


I added + m at the end of the line and now it works fine. Thank you very much for your help.


I have to add that when I use an other tga image file the problem is with out the + m it works fine but when I use an other tga image it has the green stitch from before. My goal is it to make a menu to change the images. I also can't really fix the code for a png image either.


Top
 Profile  
 
 Post subject: Re: Tga image is green
PostPosted: Fri Feb 03, 2023 2:19 pm 
Offline
Member
Member

Joined: Fri Oct 04, 2019 10:10 am
Posts: 48
The other tga may have a different layout, image format, or a colormap. I would suggest writing new code from scratch for it rather than try to fix anything from the wiki.

Linking in a real image library is probably not feasible if you're targeting a bootloader environment, but you could also convert the image ahead of time into something easier for your bootloader to display.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 74 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group