DCEmulation

dreamcast development • homebrew software • hardware hacking • indie games • emulators • and more!
Back to main site
It is currently Sat Oct 01, 2016 1:41 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun Sep 06, 2015 2:18 am 
Offline
Developer/Wiki Editor
Developer/Wiki Editor
User avatar

Joined: Sun Apr 20, 2014 7:45 am
Posts: 355
I've tried to allow non-square textures in vqenc, but I seem to output garbage for some reason.
I run "vqenc file.png", file.png is of dimensions 1024x512. No twiddle, no mipmap, just VQ compression.
My program shows a proper texture with "texconv -c -i image.png -o image.vq -f RGB565" (ignoring the first 16 bytes, they're the DTEX header).
Any obvious mistakes? I didn't grasp the whole program quite yet.

Code:
diff --git a/utils/vqenc/vqenc.c b/utils/vqenc/vqenc.c
index bf07146..a72663e 100644
--- a/utils/vqenc/vqenc.c
+++ b/utils/vqenc/vqenc.c
@@ -741,13 +741,13 @@ static int encode(const char *infile) {
         return -EINVAL;
     } */
 
-    if(image.w != image.h) {
-        fprintf(stderr, "%s is not a square image\n", infile);
+    if((use_twiddle || use_mipmap) && image.w != image.h) {
+        fprintf(stderr, "%s is not a square image, it cannot be twiddled or mipmapped\n", infile);
         destroy_image(&image);
         return -EINVAL;
     }
 
-    if(valid_size(image.w) == 0) {
+    if(valid_size(image.w) == 0 || valid_size(image.h) == 0) {
         fprintf(stderr, "image dimensions for %s are not valid, see manual\n", infile);
         destroy_image(&image);
         return -EINVAL;

_________________
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


Top
 Profile  
Reply with quote  
PostPosted: Fri Sep 18, 2015 8:14 pm 
Offline
DC Developer
DC Developer
User avatar

Joined: Fri Jun 18, 2010 7:29 pm
Posts: 563
Out of curiosity, yesterday I decided to start writing a VQ compression routine, based on the PVR VQ format.

Basically, there is a 2048 byte codebook, or palette, that stores the pixels, the actual texture is encoded as 8 bit indices into the palette.

The complex part is constructing the codebook.
My algorithm, using plain c and no external libs, stores the source pixels in a sorted array, discarding duplicate pixels.
From the sorted array, the pixels are averaged until they fit into the codebook.

Results are surprisingly good! In almost all cases, my VQ compression algorithm beats the downsampled texture, with better compression!

The Left Texture is uncompressed. Middle Texture is 1/2 resolution. Right Texture is VQ compressed:

Image

Image

Image

Image

Image


Top
 Profile  
Reply with quote  
PostPosted: Thu Sep 24, 2015 8:59 am 
Offline
Developer/Wiki Editor
Developer/Wiki Editor
User avatar

Joined: Sun Apr 20, 2014 7:45 am
Posts: 355
Hehe, I hope you had fun playing around with that :)
The choice of codebook is indeed "complex", in fact it is NP-hard: http://www.mqasem.net/vectorquantization/vq.html
That said I don't know how much quality can be gained by implementing a more complex converter compared to the simple solution you chose.

_________________
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


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

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bouz and 2 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