Converting ozi explorer *.map and *.ozf2

Maps
2006-01-21
2013-04-17
  • Has somebody tried that to do this conversion ?
    I have read that
    ozf2 format uses 64x64 tiles compressed using
    deflate algorithm (the same as png).

     
    • Lance F.
      Lance F.
      2006-01-23

      Those maps would most likely not work well with the current version of qpeGPS; currently only one image (tile) is shown at a time, and hence you would be able to see one tiny portion of the screen at any time.

       
    • #include <stdio.h>
      #include <stdlib.h>
      #include <string.h>
      #include <sys/types.h>
      #include <sys/stat.h>
      #include <sys/mman.h>
      #include <fcntl.h>
      #include <unistd.h>
      #include <time.h>
      #include <math.h>

      #define DATA_OZF2_MAGIC    0x7778

      void *mapfile(const char *name, size_t *len, FILE **stream);
      void unmapfile(FILE *fp, void *ptr, size_t len);

      #pragma pack(1)
      typedef struct
      {
        int32_t width;
        int32_t height;
        int16_t xtiles;
        int16_t ytiles;

        int32_t dict[256];

        int32_t offset;

      } ozf2_imgEntry;

      typedef struct
      {
        int16_t    magic;
        int32_t    dummy1;
        int32_t    dummy2;
        int32_t    dummy3;
        int32_t    dummy4;

        int32_t    width;
        int32_t    height;

        int16_t    depth;
        int16_t    bpp;

        int32_t    dummy5;

        int32_t    memsiz;

        int32_t    dummy6;
        int32_t    dummy7;
        int32_t    dummy8;
        int32_t    version;

      } ozf2_Head __attribute__((packed));

      void * mapfile(const char *name, size_t *len, FILE **stream)
      {
      void        *ptr;
      int        fd;
      FILE        *fp=NULL;
      struct    stat    sbuf;

         
          if( access(name, F_OK) == 0 )
          {
               if( access(name, W_OK) == 0 )
                fp = fopen(name, "r+");
               else
           {
            fp = fopen(name, "r");
           }
          }
          else
          {
           fprintf(stderr,"no such file %s?\n",name);
           exit(1);
          }

          if (!fp)
          {
           fprintf(stderr,"no such file %s?\n",name);
           exit(1);
          }

          fd=fileno(fp);
          fstat(fd,&sbuf);
          *len=sbuf.st_size;

          ptr=mmap(NULL,*len,PROT_READ|PROT_WRITE,MAP_PRIVATE,fd,(off_t)0);
          if(ptr == MAP_FAILED)
          {
           fprintf(stderr,"FATAL: can't mmap file=%s len=%ld\n",name,*len);
           exit(1);
          }

          *stream=fp;
          return ptr;
      }

      void unmapfile(FILE *fp, void *ptr, size_t len)
      {
          if (!fp)
          {
           fprintf(stderr,"WARNING: fp=NULL\n");
          }
          else
           fclose(fp);

          if (!ptr)
          {
           fprintf(stderr,"WARNING: ptr=NULL\n");
          }
          else
           munmap(ptr,len);
      }

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

        void *scn;

        ozf2_Head *header_bin;
        ozf2_imgEntry *dir_bin;

        size_t binlen;
        FILE *fpbin;
        char *binnam;

        int *dir;
        int *ioff;
       
        int    img, numimg;
        ozf2_imgEntry *curr_img;

        if (argc != 2)
          {
            fprintf (stderr, "Usage: %s file.ozf2\n", argv[0]);
            exit (1);
          }

        binnam = argv[1];

        scn = (ozf2_Head *) mapfile (binnam, &binlen, &fpbin);
        header_bin = (ozf2_Head *) scn;

        fprintf (stdout,
             "read from ozf2:%s\n magic=%x (%x) depth=%d bpp=%d w=%d h=%d memsiz=%d del=%d version=%d\n"
             "dummies       : d1= %8x d2= %8x d3= %8x d4= %8x d5= %8x d6= %8x d7= %8x d8= %8x\n",
             binnam,
             header_bin->magic,
             DATA_OZF2_MAGIC,
             header_bin->depth,
             header_bin->bpp,
             header_bin->width,
             header_bin->height,
             header_bin->memsiz,
             header_bin->memsiz/(header_bin->width*header_bin->height),
             header_bin->version,
             header_bin->dummy1,
             header_bin->dummy2,
             header_bin->dummy3,
             header_bin->dummy4,
             header_bin->dummy5,
             header_bin->dummy6,
             header_bin->dummy7,
             header_bin->dummy8
             );

        dir = (int *) ((off_t) scn + binlen - sizeof(int));

        numimg= (binlen- (*dir) -4)/4;
       
        fprintf (stdout,
             "read from ozf2:\n diroff=%x/ %d (full=%x/ %ld) direntptr=%x numimg= %d\n",
             *dir, *dir, binlen, binlen, (int *)((off_t)scn+ *dir), numimg);

          ioff= (int *)((off_t)scn+(*dir));
          for (img=0;img<numimg-1;img++)
          {
               unsigned char *coff;
               int cnt, tot;

               curr_img= (ozf2_imgEntry *) ((off_t)scn+ioff[img]);
               coff=(unsigned char *)((off_t)scn+curr_img->offset);

               tot=0;
               for (cnt=0;cnt<ioff[img+1]-ioff[img];cnt++)
                if (coff[cnt] == 0x78 && coff[cnt+1] == 0xda)
                {
      /*           fprintf(stdout,"zlibsig found at %d\n",cnt);*/
                 tot++;
                }
               
               fprintf(stdout,"zlibele found %d for img=%d length=%d\n",tot,img,ioff[img+1]-ioff[img]);

          }

          for (img=0;img<numimg;img++)
          {
          
      /*     printf("dir=%x ioff=%x\n",*dir,ioff[img]);*/

      #if 1
               curr_img= (ozf2_imgEntry *) ((off_t)scn+ioff[img]);

               unsigned char *coff;
               unsigned int *coffi;
               coff=(unsigned char *)((off_t)scn+curr_img->offset);
               coffi=(unsigned int *)((off_t)scn+curr_img->offset+2);
        fprintf (stdout,
             "--ozf2:\n img= %2d imgw= %5d imgh= %5d xtiles= %3d(%3d) ytiles= %3d(%3d) ioff= %5d(%5ld) rawtile=%d(%2x|%2x|%8.8x)\n",
             img,
             curr_img->width,
             curr_img->height,
             curr_img->xtiles,(curr_img->width+64-1)/64,
             curr_img->ytiles,(curr_img->height+64-1)/64,
             ioff[img],ioff[img]+sizeof(ozf2_imgEntry),
             curr_img->offset,coff[0],coff[1],coffi[0]
             );
            
      #if 0
             int d;
             int *offti;
             offti=(int *)curr_img->offset;
             for(d=0;d<curr_img->xtiles*curr_img->ytiles;d++)
                  fprintf (stdout,
                "tileoff: %3d\n\t\t = %6.6x\n",d,offti[d]
              );
      #endif
      #if 0
             int d;
             for(d=0;d<256;d++)
                fprintf (stdout,
             "dict: %3d\n\t\t = %6.6x\n",d,curr_img->dict[d]
            );
      #endif
      #endif

          }

        exit (0);
      }

       
    • Thanks for the program!

      Would you also know how to decode .ozfx3 ?

       
    • I have found this link
      http://dns.fromru.com/ozf2img.rar

      but there is no source code included.