LibTsunami Displaying JPEG Incorrectly

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
KingCrazy
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 33
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sat Aug 04, 2018 11:36 am
Has thanked: 2 times
Been thanked: 7 times

LibTsunami Displaying JPEG Incorrectly

Post by KingCrazy »

Hello!

I decided to try my hand at working with some 2D stuff, to contrast my earlier jumping into the deep end with OpenGL! I was reading some people highly suggest Parallax and subsequently Tsunami over the Dreamcast port of SDL, so I figured when I'd get some free time I'd learn how to use Tsunami!

The Banner example was quite helpful, and everything was going well until I stumbled into one puzzling issue: whenever I try to load a JPEG, it seems as though it only ever wants to load part of the image.
Image

Upon saving the image as a PNG, making the appropriate adjustments in the code and recompiling, the same image displays properly.
Image

I'm aware that Tsunami is a wrapper over a wrapper. I tried to dig down the rabbit hole but got sort of lost along the way, otherwise I'd have a suggestion as to what to do to fix the problem.
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 134
Joined: Sun Nov 01, 2015 8:25 pm
Has thanked: 2 times
Been thanked: 19 times

Re: LibTsunami Displaying JPEG Incorrectly

Post by lerabot »

I would honestly check out GLdc or Simulant if you don't want to deal with PVR stuff. Simply because you'll get WAY more support from active devs.

Check out the simulant discord -> https://discordapp.com/invite/TRx94EV . We're helping each other and working on DC project on a daily basis.
KingCrazy
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 33
Joined: Sat Aug 04, 2018 11:36 am
Has thanked: 2 times
Been thanked: 7 times

Re: LibTsunami Displaying JPEG Incorrectly

Post by KingCrazy »

I was working with GLdc for a bit! But it started getting to be a bit too advanced for me. Writing my own model loader was a bit of a stretch for me at the time, and I'd like to ease myself into working with the Dreamcast before I overwhelm myself. Jumping straight into GLdc gave me a ton of headaches, quite honestly haha. Better to get accustomed to the development environment first before tackling that again.

I have no problem with dealing with PVR stuff through wrappers like Tsunami! I'm just sort of reporting a bug, I guess! Loading a PNG works perfectly! There's just something in KOS that seems to not be too happy with jpegs, at least with how Tsunami is loading them.
User avatar
Protofall
DCEmu Freak
DCEmu Freak
Posts: 78
Joined: Sun Jan 14, 2018 8:03 pm
Location: Emu land
Has thanked: 21 times
Been thanked: 18 times
Contact:

Re: LibTsunami Displaying JPEG Incorrectly

Post by Protofall »

I've never used jpeg source files, so I can't comment on that. However I personally recommend not using jpegs or pngs because the Dreamcast has to convert them to its native texture format at runtime, instead its better to use something like tvspelsfreak's texconv program to convert pngs into "dtex" files which are the native Dreamcast format and allow for faster load times generally. You can find an example of it here: https://dcemulation.org/index.php?title ... ritesheets

My personal graphics library is based off this example, although its got a lot more functionality over the years. Eventually my library will be open source, but its changing too much right now for me to justify a public release. It will probably be a few years before it is release so don't bother waiting for me.

Ian Michael uses SDL though so its not all bad (You can find him on the Simulant Discord channel)
Moving Day: A clone of Dr Mario with 8-player support <https://dcemulation.org/phpBB/viewtopic ... 4&t=105389>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>

Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
KingCrazy
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 33
Joined: Sat Aug 04, 2018 11:36 am
Has thanked: 2 times
Been thanked: 7 times

Re: LibTsunami Displaying JPEG Incorrectly

Post by KingCrazy »

Protofall wrote: Sun Sep 08, 2019 7:42 am I've never used jpeg source files, so I can't comment on that. However I personally recommend not using jpegs or pngs because the Dreamcast has to convert them to its native texture format at runtime,
That's only the case when loading the texture, right? Once it's loaded in memory it shouldn't really matter what format it was in, because the conversion has already taken place it should just be sitting there ready to use -- unless I'm mistaken, which I very well might be when it comes to this kind of stuff!

People seem to make a very big deal about using dtex files, but don't really seem to explain it much (e.g. does it just increase load times? Does it use more RAM? VRAM? Just less efficient in general? Etc... I can't seem to find anything on the subject, anyway).

The reason I'm presenting this issue with Libtsunami is less about efficiency and more about the sake of functionality. I feel as though if a feature is able to be used by developers it should be working properly -- regardless of whether or not I should be using the file format, if that makes sense!
Protofall wrote: Sun Sep 08, 2019 7:42 am Ian Michael uses SDL though so its not all bad (You can find him on the Simulant Discord channel)
That's odd, every other post I find on these forums seems to suggest that running SDL is highly discouraged... But I'm not sure! Maybe things have changed since these posts were made!

Regardless, it might be worth looking into in order to see if there's been any development with SDL for DC. I'll also look into the dtex file format.
Thanks very much!
User avatar
Protofall
DCEmu Freak
DCEmu Freak
Posts: 78
Joined: Sun Jan 14, 2018 8:03 pm
Location: Emu land
Has thanked: 21 times
Been thanked: 18 times
Contact:

Re: LibTsunami Displaying JPEG Incorrectly

Post by Protofall »

With image type, the process is this: 1. Load the texture into memory (If its a png/jpeg it will generally load slightly faster than a dtex file since most dtex files aren't compressed) 2. If its not a native Dreamcast format, convert it to the native format (Takes some time, but only done once) 3. Once the texture is in vram its in the native format (So if it was a jpeg/png, you won't be losing any more computation time/efficiency over this). This is only really an issue when you're loading multiple assets at once and hence have a very long loading screen if using png/jpeg due to that conversion time. Ultimately in the end both methods use the same amount of vram. There are retail DC games that use png textures so its not a huge deal.

One of the big advantages about dtex textures is that they provide a few more texture options that png/jpegs don't provide such as palettes and the native compression (Which doesn't impact performance at all and *can* be loss-less). Also once you've made a dtex file, you can use a program to view it so you can see how it would render on a Dreamcast. I've got some extra notes on the format here: https://github.com/Protofall/Crayon-Uti ... ormat-info.

Someone else confirm or deny this, but I've got no idea if the png/jpeg loaders *twiddles* your image for you (aka Stride-d/Scanline order). If not then the texture will be the same size, but it will take longer to render, for smaller test projects this isn't too important though.

I've never really used Libtsunami so I can't compare which is easier to use, this jpeg issue is a weird one though. Can you post the jpeg version code and we can try to figure out whats going on.

Regarding SDL: I hear there's multiple versions made by different people. I think the one Ian uses is fine, but others floating around have multiple issues.
Moving Day: A clone of Dr Mario with 8-player support <https://dcemulation.org/phpBB/viewtopic ... 4&t=105389>
A recreation of Minesweeper for the Dreamcast <viewtopic.php?f=34&t=104820>

Twitter <https://twitter.com/ProfessorToffal>
YouTube (Not much there, but there are a few things) <https://www.youtube.com/user/TrueMenfa>
KingCrazy
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 33
Joined: Sat Aug 04, 2018 11:36 am
Has thanked: 2 times
Been thanked: 7 times

Re: LibTsunami Displaying JPEG Incorrectly

Post by KingCrazy »

Protofall wrote: Sun Sep 08, 2019 8:17 pm With image type, the process is this: 1. Load the texture into memory (If its a png/jpeg it will generally load slightly faster than a dtex file since most dtex files aren't compressed) 2. If its not a native Dreamcast format, convert it to the native format (Takes some time, but only done once) 3. Once the texture is in vram its in the native format (So if it was a jpeg/png, you won't be losing any more computation time/efficiency over this). This is only really an issue when you're loading multiple assets at once and hence have a very long loading screen if using png/jpeg due to that conversion time. Ultimately in the end both methods use the same amount of vram. There are retail DC games that use png textures so its not a huge deal.

One of the big advantages about dtex textures is that they provide a few more texture options that png/jpegs don't provide such as palettes and the native compression (Which doesn't impact performance at all and *can* be loss-less). Also once you've made a dtex file, you can use a program to view it so you can see how it would render on a Dreamcast. I've got some extra notes on the format here: https://github.com/Protofall/Crayon-Uti ... ormat-info.
Okay, thank you! That clears up my questions regarding the format. I'll definitely give them a look and consider using them in future projects when I'm more comfortable with the workflow!
Protofall wrote: Sun Sep 08, 2019 8:17 pm I've never really used Libtsunami so I can't compare which is easier to use, this jpeg issue is a weird one though. Can you post the jpeg version code and we can try to figure out whats going on.
I'm fairly certain the issue lies within libjpeg, since the difference between this:
Image

and this:
Image

Is the difference between:

Code: Select all

Texture* tex = new Texture("/rd/kc.jpg", false);
Banner* banner = new Banner(PVR_LIST_OP_POLY,tex);
banner->setTranslate(Vector(SCREEN_W/2.0f,SCREEN_H/2.0f,10.0f));
and

Code: Select all

Texture* tex = new Texture("/rd/kc.png", false);
Banner* banner = new Banner(PVR_LIST_OP_POLY,tex);
banner->setTranslate(Vector(SCREEN_W/2.0f,SCREEN_H/2.0f,10.0f));
Respectively.

I know Tsunami uses libjpeg to load in the jpeg images, but I'm not really the best when it comes to digging into lower-level code -- I tend to get lost pretty easily! Like you mentioned, it's not ideal to use jpegs, but I just wanted to inform people that there's a bug somewhere in the code that loads in jpegs!

(Also for future reference to anyone who might be viewing this thread in search of information: the SDL version that was recommended was the one found here. Though I was warned about the addons having memory leak issues.)
These users thanked the author KingCrazy for the post:
Protofall
Post Reply