texconv compress data

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
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has liked: 0
Been liked: 0

texconv compress data

Post by tonma » Mon Aug 27, 2018 4:35 am

Hi,

I use texconv to create my 8bit/4bit palette file. But I can't draw them with the "-c --compress" option.
I use a 512x512 pixels images in 4bit. I have a size of 128ko and when I use "-c", only 20ko.
You can see on this picture : the original non compressed on left and compressed on right. The preview file works well.
Image

texconv command :
/usr/bin/texconv.exe -i romdisk_boot/damier.png -o romdisk_boot/damier4bit.dtex -f PAL4BPP
/usr/bin/texconv.exe -c -p romdisk_boot/preview.png -i romdisk_boot/damier.png -o romdisk_boot/damier4bitc.dtex -f PAL4BPP
I use this for kos :
pvr_poly_cxt_txr(&cxt, PVR_LIST_PT_POLY, PVR_TXRFMT_PAL4BPP | PVR_TXRFMT_4BPP_PAL(numPal), texwidth, texheight, nomTex, PVR_FILTER_NONE);
I certainly need to decompress the file before, when I fread the file.
I use the wiki example :
image_file   = fopen("/rd/damier4bit.dtex",   "rb");
fread(&dtex_header, sizeof(dtex_header), 1, image_file);
memcmp(dtex_header.magic, "DTEX", 4);	
fread(MyTexture, dtex_header.size, 1, image_file);
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5389
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 1 time
Been liked: 12 times
Contact:

Re: texconv compress data

Post by BlueCrab » Mon Aug 27, 2018 9:04 am

When you create a compressed texture with that tool, you don't need to decompress it before displaying it -- you just need to set the correct flags on the polygon header to say that you're using a compressed texture. Use this instead of what you're currently using for creating the polygon header context:

Code: Select all

pvr_poly_cxt_txr(&cxt, PVR_LIST_PT_POLY, PVR_TXRFMT_PAL4BPP | PVR_TXRFMT_4BPP_PAL(numPal) | PVR_TXRFMT_VQ_ENABLE, texwidth, texheight, nomTex, PVR_FILTER_NONE);
The compression that texconv (and the similar tools included with KOS) uses is the one that the PVR actually supports internally, so it doesn't need to be decompressed ahead of time.
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has liked: 0
Been liked: 0

Re: texconv compress data

Post by tonma » Mon Aug 27, 2018 11:05 am

Thanks. That's a good news.

I tried with the VQ flag without success. I have the same result.
I tried with a new fresh compilation of texconv with linux, the hex file is identical and it doesn't work. :-(
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has liked: 0
Been liked: 0

Re: texconv compress data

Post by tonma » Mon Aug 27, 2018 12:22 pm

I post my project with only the "load / draw" image part.

I use this for converting :
texconv.exe -c -p romdisk_boot/preview.png -i romdisk_boot/damier.png -o romdisk_boot/damier4bitc.dtex -f PAL4BPP
https://www.dropbox.com/s/ry276pr79hvmp ... it.7z?dl=0
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has liked: 0
Been liked: 0

Re: texconv compress data

Post by tonma » Tue Aug 28, 2018 5:15 am

I have made others tests with a rgb565 texture.
texconv.exe -i romdisk_boot/damier.png -o romdisk_boot/damier.dtex -f RGB565
I use this code to load texture in pvr :
unsigned short * image_data;
pvr_ptr_t texture_pointer;
int width, height;
FILE *image_file       = NULL;

image_file   = fopen("/rd/damier.dtex",   "rb");
image_data = (unsigned short *)malloc(512 * 512 * 2);
width = 512;
height = 512;
	
texture_pointer = pvr_mem_malloc(512 * 512 * 2);
fread(&dtex_header, sizeof(dtex_header), 1, image_file);	
fread(image_data, dtex_header.size, 1, image_file);
	
printf("Texture: %s %d %d %lu %d\n", dtex_header.magic, (int)dtex_header.width, (int)dtex_header.height, dtex_header.type, (int)dtex_header.size);
pvr_txr_load_ex(image_data, texture_pointer, width, height, PVR_TXRLOAD_16BPP);

free(image_data);
fclose(image_file);
For drawing:
pvr_poly_cxt_txr(&cxt, PVR_LIST_PT_POLY, PVR_TXRFMT_RGB565, width, height, texture_pointer, PVR_FILTER_NONE);
The header is ok : DTEX, width=512, height=512, size = 524280 but the image is bad.
Image

I have checked the type of the header to see the format of the conversion (certainly bad way):
printf("Types : TWI %lu, STR %lu, VQ %lu\n", dtex_header.type & (1 << 26), dtex_header.type & (1 << 21), dtex_header.type & (1 << 30));
TWIDDLED = 0; STRIDE = 0; VQ_ENABLE = 0;
I also check the format and i have PVR_TXRFMT_RGB565 (1 << 27)

I tried to Stride (with -s) because texconv doesn't have twiddled function and it's works:
pvr_poly_cxt_txr(&cxt, PVR_LIST_PT_POLY, PVR_TXRFMT_RGB565, width, height, texture_pointer, PVR_FILTER_NONE);
texconv.exe -s -i romdisk_boot/damier.png -o romdisk_boot/damier.dtex -f RGB565
I have as header : 0xE000010
1110 00000000 00000000 00010000b
So I have : PVR_TXRFMT_RGB565 (1 << 27) and PVR_TXRFMT_NONTWIDDLED (1 << 26) But why this : <<25 equal the palette selector
Image

So it's works this way. My code load the image and show it. But I can"t compress a Stride images.
When I use : texconv -c my picture doesn't works.

I tried again with
texconv.exe -c -i romdisk_boot/damier.png -o romdisk_boot/damier.dtex -f RGB565
The Hex header = 0x48000000 <=> 1001000 00000000 00000000 00000000
27 = 1 = RGB565
30 = 1 = PVR_TXRFMT_VQ_ENABLE

Doesn't works :( :
pvr_poly_cxt_txr(&cxt, PVR_LIST_PT_POLY, PVR_TXRFMT_RGB565|PVR_TXRFMT_VQ_ENABLE, width, height, texture_pointer, PVR_FILTER_NONE);
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5389
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has liked: 1 time
Been liked: 12 times
Contact:

Re: texconv compress data

Post by BlueCrab » Tue Aug 28, 2018 8:50 am

I've never used texconv, so I can't really explain what it is doing.

That said, certain parts of the polygon header data overlap other parts (like the palette/twiddled bits). That's normal and expected, based on how the hardware works with those features.
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has liked: 0
Been liked: 0

Re: texconv compress data

Post by tonma » Tue Aug 28, 2018 9:15 am

OK, what software do you use for compress your pictures and does your software can compress 4bit files ?
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has liked: 0
Been liked: 0

Re: texconv compress data

Post by tonma » Mon Sep 03, 2018 8:27 am

I have tried a another code found here (https://github.com/Light-Dark/dcvqtex/t ... spelsfreak) and I have the same error.
Maybe that comes from my executable version of texconv.

Can commercial version of texture packer (https://www.codeandweb.com/texturepacker) compress palette file for Dreamcast (VQ) ?

Can someone send me a compress palette example image file to test ? I use
/usr/bin/texconv -i damier.png -o damier4bit.dtex -f PAL4BPP -c -v
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 119
Joined: Sun Nov 01, 2015 8:25 pm
Has liked: 0
Been liked: 1 time

Re: texconv compress data

Post by lerabot » Mon Sep 03, 2018 9:02 am

Send me the image I'll try it out.

I also have texture packer. You can export in .PVR
tonma
DCEmu Freak
DCEmu Freak
Posts: 82
Joined: Thu Mar 10, 2016 7:14 am
Has liked: 0
Been liked: 0

Re: texconv compress data

Post by tonma » Tue Sep 04, 2018 4:02 am

Thanks, I tried with this picture. 16 colors png.
texconv -i damier.png -o damier4bit.dtex -f PAL4BPP -c -v
With the verbose, I have :
Loaded image "damier.png"
Palette contains 16 colors
RLE completed in 3 ms
RLE result: 16384 => 338
Split 1 done. Codes: 2
Split 2 done. Codes: 4
Split 3 done. Codes: 8
Removed 2 unused codes
Split 4 done. Codes: 14
Removed 2 unused codes
Split 5 done. Codes: 26
Removed 3 unused codes
Split 6 done. Codes: 49
Removed 7 unused codes
Split 7 done. Codes: 89
Removed 19 unused codes
Split 8 done. Codes: 154
Removed 4 unused codes
Repair 1 done. Codes: 239
Repair 2 done. Codes: 256
Compression completed in 68 ms
Saved texture "damier4bit.dtex"
For the format .PVR, Someone on this forum tell we must avoid this format. Use png / kmg.
I'll tried kmg as it seems we can use 4bpp/8bpp.
Attachments
damier.png
damier.png (5.57 KiB) Viewed 970 times
User avatar
bogglez
Moderator
Moderator
Posts: 576
Joined: Sun Apr 20, 2014 9:45 am
Has liked: 0
Been liked: 0

Re: texconv compress data

Post by bogglez » Sat Sep 08, 2018 4:20 am

lerabot wrote:
Mon Sep 03, 2018 9:02 am
I also have texture packer. You can export in .PVR
Are you sure that texture packer's .pvr is really the format of the Dreamcast? Maybe it's some compression format of more modern PVR chips?
Wiki & tutorials: http://dcemulation.org/?title=Development
Wiki feedback: viewtopic.php?f=29&t=103940
My libgl playground (not for production): https://bitbucket.org/bogglez/libgl15
My lxdream fork (with small fixes): https://bitbucket.org/bogglez/lxdream
User avatar
lerabot
Insane DCEmu
Insane DCEmu
Posts: 119
Joined: Sun Nov 01, 2015 8:25 pm
Has liked: 0
Been liked: 1 time

Re: texconv compress data

Post by lerabot » Sat Sep 08, 2018 2:11 pm

I remember doibg some test a while ago. I'd need to test it again. There are some "legacy" pvr format
Post Reply