home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff397.lzh / DKBTrace / DKBSource.LZH / Dump2Raw.c < prev    next >
C/C++ Source or Header  |  1990-08-26  |  4KB  |  191 lines

  1. /**********************************************************
  2.  
  3. DUMP2RAW.C  - Converts a DKB/QRT "Dump" format raw file to
  4.           PICLAB's "raw" format, which is 3 files of
  5.           8-Bit pixel data named .R8, .B8, and .G8.
  6.           On the Amiga, names are .red, .grn, and .blu.
  7.           By Aaron A. Collins, written on 6/30/90
  8.  
  9.           This file is released to the Public Domain.
  10.  
  11.           PICLAB is a trademark of The Stone Soup Group.
  12.       
  13.  ***********************************************************/
  14.  
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include "config.h"
  18.  
  19. #ifndef TRUE
  20. #define TRUE 1
  21. #define FALSE 0
  22. #endif
  23.  
  24. /* #define IBM TRUE */
  25.  
  26. #define Amiga TRUE
  27.  
  28. #define MAXXRES 2048   /* huge max x resolution allowable, infinite y res. */
  29.  
  30. unsigned char linbuf[MAXXRES * 3];
  31.  
  32. void main(argc,argv)
  33. int argc;
  34. char *argv[];
  35. {
  36.     int xres, yres, xhi, yhi, noext = FALSE;
  37.     register int x, y;
  38.     char inname[80], rname[80], bname[80], gname[80], tmpname[80];
  39.     FILE *in, *rout, *bout, *gout;
  40.  
  41.     printf("\n\nDKB/QRT Image File to Raw R-G-B Files Converter\n");
  42.     printf("By Aaron A. Collins.  Written 6/30/90\n\n");
  43.  
  44.     if (argc < 2)
  45.     {
  46.         printf("Usage: %s InFile[.DIS]\n\n",argv[0]);
  47.         exit(1);
  48.     }
  49.  
  50.     strcpy(inname, argv[1]);      /* get input filename */
  51.  
  52.     strcpy(tmpname, inname);
  53.     strupr(tmpname);        /* Cvt to uppercase */
  54.     if (!strstr(tmpname, ".DIS"))    /* if user didn't supply .DIS ext, */
  55.         if (!strchr(tmpname, '.'))  /* AND didn't supply ANY ext */
  56.         {
  57.             noext = TRUE;
  58.             strcat(inname, ".DIS");
  59.         }
  60.  
  61.     if ((in = fopen(inname, "rb")) == NULL)  /* try w/supplied ext. */
  62.     {
  63.         printf("ERROR - Couldn't open file %s\n", inname);
  64.         exit(1);
  65.     }
  66.  
  67.     if (noext)
  68.     {
  69.         strcpy(rname, argv[1]);        /* copy name w/no extension */
  70.         strcpy(gname, argv[1]);
  71.         strcpy(bname, argv[1]);
  72.     }
  73.     else
  74.     {
  75.         strcpy(tmpname, argv[1]);    /* Get Input Filename */
  76.         strupr(tmpname);        /* Cvt to uppercase */
  77.         *strchr(tmpname, '.') = '\0';    /* Find the Dot + Truncate */
  78.         strcpy(rname, tmpname);        /* copy name w/no extension */
  79.         strcpy(gname, tmpname);
  80.         strcpy(bname, tmpname);
  81.     }
  82. #ifdef IBM
  83.     strcat(rname, ".R8");
  84.     strcat(gname, ".G8");
  85.     strcat(bname, ".B8");
  86. #endif
  87.  
  88. #ifdef Amiga
  89.     strcat(rname, ".red");
  90.     strcat(gname, ".grn");
  91.     strcat(bname, ".blu");
  92. #endif
  93.     
  94.     if ((rout = fopen(rname, "wb")) == NULL)
  95.     {
  96.         printf("ERROR - Couldn't create file %s\n", rname);
  97.         fclose(in);
  98.         exit(1);
  99.     }
  100.  
  101.     if ((gout = fopen(gname, "wb")) == NULL)
  102.     {
  103.         printf("ERROR - Couldn't create file %s\n", gname);
  104.         fclose(in);
  105.         fclose(rout);
  106.         exit(1);
  107.     }
  108.  
  109.     if ((bout = fopen(bname, "wb")) == NULL)
  110.     {
  111.         printf("ERROR - Couldn't create file %s\n", bname);
  112.         fclose(in);
  113.         fclose(rout);
  114.         fclose(gout);
  115.         exit(1);
  116.     }
  117.  
  118.     /** load x and y resolution from input DUMP file **/
  119.  
  120.     xres = fgetc(in);            /* lo order */
  121.     xhi = fgetc(in);            /* hi order */
  122.     xres += ((unsigned int) xhi) << 8;
  123.     
  124.     if (xres > MAXXRES)            /* too big? */
  125.     {
  126.         printf("ERROR - X res. of %s (%d) exceeds maximum (%d)!\n", inname, xres, MAXXRES);
  127.         fclose(in);            /* close all files */
  128.         fclose(rout);
  129.         fclose(gout);
  130.         fclose(bout);
  131.         unlink(rname);        /* delete empty out files */
  132.         unlink(gname);
  133.         unlink(bname);
  134.         exit(1);
  135.     }
  136.  
  137.     yres = fgetc(in);            /* now do yres the same... */
  138.     yhi = fgetc(in);
  139.     yres += ((unsigned int) yhi) << 8;
  140.  
  141.     printf("Input file         = %s\n", inname);    /* show stats */
  142.     printf("Output files       = %s\n", rname);
  143.     printf("                     %s\n", gname);
  144.     printf("                     %s\n\n", bname);
  145.     printf("Image X resolution = %d\n", xres);
  146.     printf("Image Y resolution = %d\n", yres);
  147.  
  148.     printf("\nProcessing Line:   0");
  149.  
  150.     for (y = 0; y < yres; y++)    /* for every line in the old file */
  151.     {
  152.  
  153.         printf("\b\b\b%3d", y);        /* disp. current line # */
  154.  
  155.         fread(linbuf, 1, 2, in);    /* read in line number */
  156.  
  157.         if (feof(in))            /* stop if file truncated */
  158.             break;
  159.  
  160.         for (x = 0; x < 3; x++)
  161.         {
  162.             fread(linbuf, 1, xres, in); /* read a line's data */
  163.  
  164.             if (feof(in))        /* stop if file truncated */
  165.                 break;
  166.  
  167.             switch (x)
  168.             {
  169.                 case 0:
  170.                     fwrite(linbuf, 1, xres, rout);
  171.                     break;
  172.                 case 1:
  173.                     fwrite(linbuf, 1, xres, gout);
  174.                     break;
  175.                 case 2:
  176.                     fwrite(linbuf, 1, xres, bout);
  177.                     break;
  178.             }
  179.         }
  180.     }
  181.     printf("\n");
  182.     fclose(in);                                 /* close all files */
  183.     fflush(rout);
  184.     fflush(gout);
  185.     fflush(bout);
  186.     fclose(rout);
  187.     fclose(gout);
  188.     fclose(bout);
  189.     exit(0);
  190. }
  191.