GP32 Trouble Loading Images From Zda


jlebrech

UFO Robot
Joined
Feb 25, 2003
Messages
899
Age
39
I've tryed to modify the mr mirko examples trying to put the sprite and zda examples together but no joy. could anyone see what the problem is with the code.

Code:
// written 2004 Mirko Roller   mirko@mirkoroller.de
// Example shows you how to use sprites, and clear the screen...
// The sprites are generated with: bmp2raw -x name.bmp name.raw


#include "gp32.h"
#include "fileio.h"
#include "zda.h"

//extern unsigned char modfile[];


u16 *framebuffer[2];

char swapper=0;
void swap_screen () {
   gp_setFramebuffer(framebuffer[swapper],1);
   swapper++; if (swapper == 2) swapper=0;
}

int main() {

  int spritex=-150;
  int x;
  int framerate=0;
  int refreshrate=0;
  char buffer[64]="Framerate:         ";
  framebuffer[0] = (u16*)  FRAMEBUFFER1;
  framebuffer[1] = (u16*)  FRAMEBUFFER2;
 

  gp_setCpuspeed(133);

  


   u16 *uncompressed;
   char header_12bytes[12];  // The ZDA header is always 12 Bytes big
   char *full_header;        // The full headersize depend on content
   char *compressed;
    
   int  real_headersize;
   int  usize,csize,offset,err;
   
   { 

     smc_read("dev0:\\GPMM\\data.zda",header_12bytes,0,12); // read in the 12 bytes header.
     real_headersize=gp_zda_headersize(header_12bytes);      // calculate the real headersize

     full_header = (char*) malloc(real_headersize);          // malloc space for full header
     smc_read("dev0:\\GPMM\\data.zda",full_header,0,real_headersize); // read in the full header

     csize  = gp_zda_csize (full_header, "garfield.raw");     // get compressed   size of file
     usize  = gp_zda_usize (full_header, "garfield.raw");     // get uncompressed size of file
     offset = gp_zda_offset(full_header, "garfield.raw");     // get the offset for file, counting from file beginning

     compressed   = (char*) malloc(csize);  // temp buffer for compressed file
     uncompressed = (char*) malloc(usize);  // buffer for uncompressed data
     err=smc_read("dev0:\\GPMM\\data.zda",compressed,offset,csize);  // read in the compressed data

  err = gp_uncompressZDA( (u8*)uncompressed, &usize, (u8*)compressed, &csize ); // uncompress


   }
  
  
  
  
  
  gp_initRTC();
  refreshrate=gp_initFramebuffer(framebuffer[0],16,85);
  gp_clearRTC();
  
 while (1) {

  // Drawing in Sprite header mode, only usefull if the sprite got a header.


  swap_screen();
    gp_clearFramebuffer16(framebuffer[swapper],0xffff); // very very fast asm, faster than memset

   gp_drawSpriteH  (uncompressed, 0, 0, framebuffer[swapper]);



  framerate++;
  if (gp_getRTC() > 63) {sprintf(buffer,"Zip: %d Unzip:%d    ",csize,usize);framerate=0;gp_clearRTC(); }
  gp_drawString(20,220,20,buffer,0xffff,framebuffer[swapper]);

  if (gp_getButton()&BUTTON_A) gp_Reset();
 }
 
 
 // free all memory
 free (full_header);
 free (compressed);
 free (uncompressed);
 
  
}

Thanks for looking


Updated to current code yet still no luck.
 

mr.mirko

Certified Guru
Joined
Nov 24, 2003
Messages
471
Location
Germany
Website
mirkoroller.de
jlebrech posted on Aug 21 2004 at 07:46 AM said:
I've tryed to modify the mr mirko examples trying to put the sprite and zda examples together but no joy. could anyone see what the problem is with the code.

Code:
#include "gp32.h"
#include "fileio.h"
#include "zda.h"

//extern unsigned char modfile[];


u16 *framebuffer[2];

char swapper=0;
void swap_screen () {
   gp_setFramebuffer(framebuffer[swapper],1);
   swapper++; if (swapper == 2) swapper=0;
}

int main() {

  int spritex=-150;
  int x;
  int framerate=0;
  int refreshrate=0;
  char buffer[64]="Framerate:         ";
  framebuffer[0] = (u16*)  FRAMEBUFFER1;
  framebuffer[1] = (u16*)  FRAMEBUFFER2;
 

  gp_setCpuspeed(133);

  


   u16 *uncompressed;
   char header_12bytes[12];  // The ZDA header is always 12 Bytes big
   char *full_header;        // The full headersize depend on content
   char *compressed;
    
   int  real_headersize;
   int  usize,csize,offset,err;
   
   { 

     smc_read("dev0:\\GPMM\\data.zda",header_12bytes,0,12); // read in the 12 bytes header.
     real_headersize=gp_zda_headersize(header_12bytes);      // calculate the real headersize

     full_header = (char*) malloc(real_headersize);          // malloc space for full header
     smc_read("dev0:\\GPMM\\data.zda",full_header,0,real_headersize); // read in the full header

     csize  = gp_zda_csize (full_header, "garfield.raw");     // get compressed   size of file
     usize  = gp_zda_usize (full_header, "garfield.raw");     // get uncompressed size of file
     offset = gp_zda_offset(full_header, "garfield.raw");     // get the offset for file, counting from file beginning

     compressed   = (char*) malloc(csize);  // temp buffer for compressed file
     uncompressed = (char*) malloc(usize);  // buffer for uncompressed data
     err=smc_read("dev0:\\GPMM\\data.zda",compressed,offset,csize);  // read in the compressed data


     err = gp_uncompressZDA( (u16*)uncompressed, &usize, (u16*)compressed, csize ); // uncompress



   }
  
  
  
  
  
  gp_initRTC();
  refreshrate=gp_initFramebuffer(framebuffer[0],16,85);
  gp_clearRTC();
  
 while (1) {

  // Drawing in Sprite header mode, only usefull if the sprite got a header.


  swap_screen();
    gp_clearFramebuffer16(framebuffer[swapper],0xffff); // very very fast asm, faster than memset

   gp_drawSpriteH  (uncompressed, 0, 0, framebuffer[swapper]);



  framerate++;
  if (gp_getRTC() > 63) {sprintf(buffer,"Framerate: %d,%d    ",framerate,refreshrate);framerate=0;gp_clearRTC(); }
  gp_drawString(20,220,20,buffer,0x0000,framebuffer[swapper]);

  if (gp_getButton()&BUTTON_A) gp_Reset();
 }
 
 
 // free all memory
 free (full_header);
 free (compressed);
 free (uncompressed);
 
  
}

Thanks for looking
smc_read("dev0:\\GPMM\\data.zda",header_12bytes,0,12); // read in the 12 bytes header.
real_headersize=gp_zda_headersize(header_12bytes); // calculate the real headersize

Are you shure you used the right zda_compressor V1.0 to compress your ZDA file ?
It will generate two files
data.zda and
data_with_header.zda

in youre case you must use the generated data_with_header.zda file
 
Last edited by a moderator:

jlebrech

UFO Robot
Joined
Feb 25, 2003
Messages
899
Age
39
I recon i have the wrong compressor, where do i get the newest compiled one for windows?

while i wait ill try to just load .raw files by themselves, it should work.
 

mr.mirko

Certified Guru
Joined
Nov 24, 2003
Messages
471
Location
Germany
Website
mirkoroller.de
jlebrech posted on Aug 21 2004 at 06:22 PM said:
I recon i have the wrong compressor, where do i get the newest compiled one for windows?

while i wait ill try to just load .raw files by themselves, it should work.
this is a good qestion ... If someone here with windows, can compile it ??
 
Last edited by a moderator:

Dalto

Certified Guru
Joined
Jun 13, 2004
Messages
266
Location
Just north of Mexico
Website
Visit site
mr.mirko posted on Aug 21 2004 at 09:50 PM said:
jlebrech posted on Aug 21 2004 at 06:22 PM said:
I recon i have the wrong compressor, where do i get the newest compiled one for windows?

while i wait ill try to just load .raw files by themselves, it should work.
this is a good qestion ... If someone here with windows, can compile it ??
Here you go.

Compiled from Mr. Mirko's SDK version 0.86

http://www.gp32.us/zda_compressor.exe
 
Last edited by a moderator:

jlebrech

UFO Robot
Joined
Feb 25, 2003
Messages
899
Age
39
Thanks for the compressor!!! :D


Ive updated it in the first post, but it still doesnt work.

i output the csize and usize, but zipped its 11409 and unzipped its 397

im sure unzipped should be bigger :angry:

i added a & to
Code:
err = gp_uncompressZDA( (u8*)uncompressed, &usize, (u8*)compressed, csize ); // uncompress

also at the csize bit.
 

mr.mirko

Certified Guru
Joined
Nov 24, 2003
Messages
471
Location
Germany
Website
mirkoroller.de
Dalto posted on Aug 24 2004 at 03:41 AM said:
Dalto posted on Aug 23 2004 at 05:13 PM said:
That's because the zda_compressor still does not work....fixing now.
It's back now. It works and has been tested by me.

http://www.gp32.us/zda_compressor.exe

EDIT: Updated source here.
I wrote a little ZDA tester, use it, to test your zda files.

Code:
/*
 * ZDA content tester V1.0 - zda_tester.c
 *
 * Copyright (C) 2003,2004 Mirko Roller <mirko@mirkoroller.de>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * Changelog:
 *
 *  21 Aug 2004 - Mirko Roller <mirko@mirkoroller.de>
 *   first release
 *
 */


// 52 byte header for each file
typedef struct {
   char filename[40];
   int  size_uncompressed;
   int  size_compressed;
   int  start_offset;
} ZDAHEADER;

// 12 bytes index
typedef struct {
   char name[4];
   int  records;
   int  size;
} HEAD;

#include <stdio.h>
//#include <zlib.h>
#include <string.h>
#include <stdlib.h>



int main(int argc, char *argv[]) {

    FILE *fp;
    ZDAHEADER *zdaheader;
    HEAD *head;
    int size,err,loop;
    unsigned int dlen;
    unsigned char *filein;
    unsigned char *compressed;
    unsigned char *uncompr;

    if (argc == 1 ) {printf ("zda_tester V1.0\nusage: ./zda_tester zda_with_header.zda \n");exit(0);}

    filein = malloc(5000000);
    uncompr= malloc(5000000);

    // Read in the zda_with_header file
    fp=fopen (argv[1],"r");
    size = fread(filein, 1, 5000000, fp);
    fclose(fp);

    head = (HEAD*) filein;
    printf ("ZDA Name    : %s  \n",head->name);
    printf ("ZDA records : %i  \n",head->records);
    printf ("ZDA size    : %i  \n",head->size);

    for (loop=0;loop<head->records;loop++) {

      zdaheader = (ZDAHEADER*) (filein+12+(52*loop));
      printf ("filename    : %s  \n",zdaheader->filename);
      printf ("uncompressed: %i  \n",zdaheader->size_uncompressed);
      printf ("compressed  : %i  \n",zdaheader->size_compressed);
      printf ("offset      : %i  \n",zdaheader->start_offset);

      compressed = (filein+head->size+(zdaheader->start_offset));

      dlen=5000000;
      err = uncompress (uncompr, &dlen,compressed,zdaheader->size_compressed);
      printf ("error       :%i \n",err);

      //if (err == 0) {
      //  fp=fopen(zdaheader->filename,"w");
      //  fwrite(uncompr,1,dlen,fp);
      //  fclose(fp);
      //}

    }

    free (filein);
    free (uncompr);

exit(0);
}
 
Last edited by a moderator:

jlebrech

UFO Robot
Joined
Feb 25, 2003
Messages
899
Age
39
Thanks guys it working good now :D

heres my sample code, its the sprite and zda example combined

Code:
#include "gp32.h"
#include "fileio.h"
#include "zda.h"

//extern unsigned char modfile[];


u16 *framebuffer[2];

char swapper=0;
void swap_screen () {
   gp_setFramebuffer(framebuffer[swapper],1);
   swapper++; if (swapper == 2) swapper=0;
}

int main() {

  int spritex=-150;
  int x;
  int framerate=0;
  int refreshrate=0;
  char buffer[64]="Framerate:         ";
  framebuffer[0] = (u16*)  FRAMEBUFFER1;
  framebuffer[1] = (u16*)  FRAMEBUFFER2;
 

  gp_setCpuspeed(133);

  


   char *uncompressed;
   char header_12bytes[12];  // The ZDA header is always 12 Bytes big
   char *full_header;        // The full headersize depend on content
   char *compressed;
    
   int  real_headersize;
   int  usize,csize,offset,err;
   
   { 

     smc_read("dev0:\\GPMM\\data.zda",header_12bytes,0,12); // read in the 12 bytes header.
     real_headersize=gp_zda_headersize(header_12bytes);      // calculate the real headersize

     full_header = (char*) malloc(real_headersize);          // malloc space for full header
     smc_read("dev0:\\GPMM\\data.zda",full_header,0,real_headersize); // read in the full header

     csize  = gp_zda_csize (full_header, "garfield.raw");     // get compressed   size of file
     usize  = gp_zda_usize (full_header, "garfield.raw");     // get uncompressed size of file
     offset = gp_zda_offset(full_header, "garfield.raw");     // get the offset for file, counting from file beginning

     compressed   = (char*) malloc(csize);  // temp buffer for compressed file
     uncompressed = (char*) malloc(usize);  // buffer for uncompressed data
     err=smc_read("dev0:\\GPMM\\data.zda",compressed,offset,csize);  // read in the compressed data

  err = gp_uncompressZDA( (u8*)uncompressed, &usize, (u8*)compressed, csize ); // uncompress


   }
  
  
  
  
  
  gp_initRTC();
  refreshrate=gp_initFramebuffer(framebuffer[0],16,85);
  gp_clearRTC();
  
 while (1) {

  // Drawing in Sprite header mode, only usefull if the sprite got a header.


  swap_screen();
    gp_clearFramebuffer16(framebuffer[swapper],0xffff); // very very fast asm, faster than memset

   gp_drawSpriteH  (uncompressed, 0, 0, framebuffer[swapper]);



  framerate++;
  if (gp_getRTC() > 63) {sprintf(buffer,"Zip: %d Unzip:%d    ",csize,usize);framerate=0;gp_clearRTC(); }
  gp_drawString(20,220,20,buffer,0xffff,framebuffer[swapper]);

  if (gp_getButton()&BUTTON_A) gp_Reset();
 }
 
 
 // free all memory
 free (full_header);
 free (compressed);
 free (uncompressed);
 
  
}
 
Top