home *** CD-ROM | disk | FTP | other *** search
/ hobbes.nmsu.edu 2008 / 2008-06-02_hobbes.nmsu.edu.zip / new / scummc-0.2.0-os2.zip / ScummC / src / rd.c < prev    next >
Encoding:
C/C++ Source or Header  |  2006-11-28  |  5.2 KB  |  210 lines

  1. /* ScummC
  2.  * Copyright (C) 2004-2006  Alban Bedel
  3.  *
  4.  * This program is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU General Public License
  6.  * as published by the Free Software Foundation; either version 2
  7.  * of the License, or (at your option) any later version.
  8.  
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * GNU General Public License for more details.
  13.  
  14.  * You should have received a copy of the GNU General Public License
  15.  * along with this program; if not, write to the Free Software
  16.  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  17.  *
  18.  */
  19.  
  20. /**
  21.  * @file rd.c
  22.  * @brief Experiment playground, currently dump SCUMM files.
  23.  */
  24.  
  25. #include "config.h"
  26.  
  27. #include <sys/types.h>
  28. #include <sys/stat.h>
  29. #include <fcntl.h>
  30. #include <inttypes.h>
  31. #include <stdlib.h>
  32. #include <unistd.h>
  33. #include <stdio.h>
  34. #include <errno.h>
  35. #include <string.h>
  36.  
  37. #include "scc_fd.h"
  38. #include "scc_util.h"
  39. #include "scc_cost.h"
  40. #include "scc_codec.h"
  41. #include "scc.h"
  42.  
  43. int scc_image_2_rgb(uint8_t* dst,int dst_stride,
  44.             uint8_t* src, int src_stride,
  45.             int width,int height,
  46.             scc_pal_t* pal) {
  47.   int r,c;
  48.  
  49.   for(r = 0 ; r < height ; r++) {
  50.     for(c = 0 ; c < width ; c++) {
  51.       dst[3*c+0] = pal->r[src[c]];
  52.       dst[3*c+1] = pal->g[src[c]];
  53.       dst[3*c+2] = pal->b[src[c]];
  54.     }
  55.     src += src_stride;
  56.     dst += dst_stride;
  57.   }
  58.   return 1;
  59. }
  60.  
  61.  
  62. int main(int argc,char** argv) {
  63.   scc_fd_t* fd2,*fd = new_scc_fd("TENTACLE.000",O_RDONLY,0x69);
  64.   scc_res_idx_t* idx;
  65.   scc_res_t* res;
  66.   int i,len;
  67.   scc_lfl_t* lfl;
  68.   scc_res_list_t *d;
  69.  
  70.   if(!fd) {
  71.     printf("Failed to open index :((\n");
  72.     return -1;
  73.   }
  74.  
  75.   idx = scc_read_res_idx(fd);
  76.   d = idx->scr_list;
  77.  
  78.   //for(i = 0 ; i < d->size ; i++)
  79.   //  printf("%d ==> ROOM %d: %d\n",i,d->room_no[i],d->room_off[i]);
  80.  
  81.   //return 0;
  82.   //  fd2 = new_scc_fd("dump.000",O_WRONLY|O_CREAT,0x69);
  83.   //  scc_write_res_idx(fd2,idx);
  84.   //  return 0;
  85.  
  86.  
  87.   fd2 = new_scc_fd("TENTACLE.001",O_RDONLY,0x69); 
  88.   res = scc_parse_res(fd2,idx);
  89.  
  90.   scc_dump_res(res);
  91.   return 0;
  92.  
  93.     scc_fd_close(fd2);
  94.   fd2 = new_scc_fd("copy.001",O_WRONLY|O_CREAT,0x69);
  95.   scc_write_lecf(fd2,res);
  96.  
  97.   return 0;
  98.  
  99.   for(lfl = res->lfl ; lfl ; lfl = lfl->next) {
  100.     scc_room_t* r = &lfl->room;
  101.     uint8_t* img8 = calloc(r->width,r->height+5);
  102.     uint8_t* img24 = malloc(r->width*r->height*3);
  103.     int w,i,c = 0;
  104.     char name[1024];
  105.     scc_obim_t* ob;
  106.     scc_imnn_t* im;
  107.     uint8_t* smap;
  108.     uint32_t smap_len;
  109.  
  110.     if(r->rmim->num_z_buf < 1) continue;
  111.  
  112.     printf("ROOM %d has %d zbuf\n",r->idx,r->rmim->num_z_buf);
  113.  
  114.     for(i = 1 ; i <= r->rmim->num_z_buf ; i++) {
  115.       scc_decode_zbuf(img8,r->width/8,
  116.               r->width,r->height,
  117.               r->rmim->z_buf[i],
  118.               r->rmim->z_buf_size[i],0);
  119.       smap_len = scc_code_zbuf(img8,r->width/8,
  120.                    r->width,r->height,
  121.                    &smap);
  122.       if(smap_len != r->rmim->z_buf_size[i]) printf("ZMAP size mismatch %d != %d !!!\n",smap_len,r->rmim->z_buf_size[i]);
  123.       if(!smap) { printf("Failed to code ???\n"); continue; }
  124.  
  125.       scc_decode_zbuf(img24,r->width/8,
  126.               r->width,r->height,
  127.               smap,
  128.               smap_len,0);
  129.       free(smap);
  130.  
  131.       for(w = 0 ; w < r->width/8*r->height ; w++) {
  132.     if(img24[w] != img8[w]) { 
  133.       printf("Mismatch at 0x%x/0x%x : 0x%x 0x%x\n",
  134.          i,r->width/8*r->height,img24[w],img8[w]);
  135.       printf("Ref data: %0x %0x %0x %0x\n",img8[w-1],img8[w],img8[w+1],img8[w+230]);
  136.       printf("Our data: %0x %0x %0x %0x\n",img24[w-1],img24[w],img24[w+1],img24[w+2]);
  137.       break;
  138.     }
  139.       }       
  140.  
  141.     }
  142. #if 0
  143.     scc_code_image(img8,r->width,
  144.            r->width,r->height,r->transp,
  145.            &smap,&smap_len);
  146.     scc_decode_image(img24,r->width,
  147.              r->width,r->height,
  148.              smap,
  149.              smap_len,-1);
  150.  
  151.     for(i = 0 ; i < r->width*r->height ; i++) {
  152.       if(img24[i] != img8[i]) { 
  153.     printf("Mismatch at 0x%x/0x%x : 0x%x 0x%x\n",
  154.            i,r->width*r->height,img24[i],img8[i]);
  155.     printf("Ref data: %0x %0x %0x %0x\n",img8[i-1],img8[i],img8[i+1],img8[i+230]);
  156.     printf("Our data: %0x %0x %0x %0x\n",img24[i-1],img24[i],img24[i+1],img24[i+2]);
  157.     break;
  158.       }
  159.     }       
  160.            
  161.  
  162.     scc_image_2_rgb(img24,r->width*3,img8,r->width,
  163.             r->width,r->height,
  164.             r->pals);
  165.     sprintf(name,"rmim.%3.3d-%dx%d.raw",r->idx,r->width,r->height);
  166.     fd2 = new_scc_fd(name,O_WRONLY|O_CREAT,0);
  167.     while(c < r->width*r->height*3) {
  168.       w = scc_fd_write(fd2,img24+c,r->width*r->height*3-c);
  169.       if(c < 0) {
  170.     printf("Write error\n");
  171.     return -1;
  172.       }
  173.       c += w;
  174.     }
  175.  
  176.     for(ob = r->obim ; ob ; ob = ob->next) {
  177.  
  178.       for(im = ob->img ; im ; im = im->next) {
  179.     printf("Parsing images of %d: %d\n",ob->idx,im->idx);
  180.     img8 = realloc(img8,ob->width*ob->height);
  181.     scc_decode_image(img8,ob->width,
  182.              ob->width,ob->height,
  183.              im->smap,
  184.              im->smap_size,-1);
  185.       }
  186.       printf("\n");
  187.     }
  188. #endif
  189.     free(img8);
  190.     free(img24);
  191.   }
  192.  
  193.   return 0;
  194.  
  195.   res = scc_open_res_file(fd2,idx);
  196.  
  197.   scc_dump_res(res);
  198.   return 0;
  199.  
  200.   len = scc_res_find(res,MKID('S','C','R','P'),55);
  201.   if(len < 0) {
  202.     fprintf(stderr,"Failed to find script 55 (0x%x)\n",MKID('D','S','C','R'));
  203.   } else {
  204.     fprintf(stderr,"Script 55: %d bytes\n",len);
  205.   }
  206.  
  207.   return 0;
  208. }
  209.  
  210.