home *** CD-ROM | disk | FTP | other *** search
/ Fun CD 26 / OTACD26.ISO / archive / game / kaqcut / kaqcut.lzh / KAQCUT.C next >
C/C++ Source or Header  |  1997-09-20  |  3KB  |  95 lines

  1. /*---------------------------------------------------
  2.  
  3.   SS 下級生 BMP.ARC 分割プログラム
  4.                               ver 0.00 1997/09/17
  5.                               By 浦木 コウ
  6.  
  7. ----------------------------------------------------*/
  8.  
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12.  
  13. #define BMP_HEADER_SIZE 0x436L /* パレットとヘッダを足したサイズ */
  14. #define MAX_FILE        94    /* 分割後のファイルの数 */
  15.  
  16. main(int ac, char **av)
  17. {
  18.   long offsets[]={0x0,0x4000,0x8000,0xC000,0x10000,0x14000,0x18000,0x1C000,
  19.                 0xA2800,0xE9000,0xED000,0xF1000,0xF5000,0xF9000,0xFD000,
  20.                 0x101000,0x153000,0x176800,0x1E7000,0x226000,0x265000,0x294800,
  21.                 0x323800,0x327800,0x32B800,0x32F800,0x333800,0x337800,0x33B800,
  22.                 0x33F800,0x343800,0x347800,0x34B800,0x34F800,0x353800,0x357800,
  23.                 0x35B800,0x35F800,0x363800,0x367800,0x36B800,0x36F800,0x373800,
  24.                 0x377800,0x37B800,0x37F800,0x383800,0x387800,0x3C6800,0x3CA800,
  25.                 0x3CE800,0x3D2800,0x3D6800,0x3DA800,0x3DE800,0x3E2800,0x3E6800,
  26.                 0x3EA800,0x3EE800,0x3F2800,0x3F6800,0x3FA800,0x3FE800,0x402800,
  27.                 0x406800,0x40A800,0x40E800,0x412800,0x416800,0x41A800,0x41E800,
  28.                 0x422800,0x426800,0x42A800,0x42E800,0x432800,0x436800,0x43A800,
  29.                 0x43E800,0x442800,0x446800,0x44A800,0x44E800,0x48D800,0x491800,
  30.                 0x495800,0x499800,0x49D800,0x4A1800,0x4C5000,0x4E8800,0x4EC800,
  31.                 0x52B800,0x56A800};
  32.   long fsize;
  33.   unsigned char hbuf[BMP_HEADER_SIZE], lbuf[640], fname[100], *ext=".BMP";
  34.   int i, j, w, h, h2;
  35.   FILE *fp1, *fp2;
  36.   
  37.   printf("SS 下級生 'BMP.ARC' 分割プログラム ver 0.00\n"
  38.          "\t\t\tBy 浦木 コウ\n");
  39.   
  40.   if(ac<2)
  41.   {
  42.     printf("    usage:kaqcut [origin file]\n");
  43.     return 0;
  44.   }
  45.   
  46.   
  47.   fp1=fopen(av[1],"rb"); /* 元ファイルオープン */
  48.   if(fp1==NULL)
  49.   {
  50.     printf("not found:%s\n",av[1]);
  51.     return -1;
  52.   }
  53.   
  54.   for(i=0;i<MAX_FILE;i++) /* ファイル書き込み */
  55.   {
  56.     itoa(i+1,fname,10); /* ファイルネーム作成 */
  57.     strcat(fname,ext);
  58.     fp2=fopen(fname,"wb");
  59.     if(fp2==NULL)
  60.     {
  61.       printf("file open error:%s\n",fname);
  62.       fclose(fp1);
  63.       return -1;
  64.     }
  65.     
  66.     fseek(fp1,offsets[i],SEEK_SET);
  67.     fread(hbuf,BMP_HEADER_SIZE,sizeof(unsigned char),fp1);
  68.     w=hbuf[0x12]+hbuf[0x13]*0x100; /* 幅取得 */
  69.     h=hbuf[0x16]+hbuf[0x17]*0x100; /* 高さ取得 */
  70.     
  71.     h2=h*2; /* 高さを2倍にして、ファイルサイズ再計算 */
  72.     fsize=BMP_HEADER_SIZE+(long)w*(long)h2;
  73.     
  74.     hbuf[0x16]=h2%0x100; /* 高さデータ変更 */
  75.     hbuf[0x17]=h2/0x100;
  76.     
  77.     hbuf[2]=fsize%0x100L; /* ファイルサイズ変更 */
  78.     hbuf[3]=(fsize%0x10000L)/0x100L;
  79.     hbuf[4]=fsize/0x10000L;
  80.     
  81.     fwrite(hbuf,BMP_HEADER_SIZE,sizeof(unsigned char),fp2); /*ヘッダ書き込み*/
  82.     
  83.     for(j=0;j<h;j++)
  84.     {
  85.       fread(lbuf,w,sizeof(unsigned char),fp1);
  86.       
  87.       fwrite(lbuf,w,sizeof(unsigned char),fp2); /* 2ライン書き込む */
  88.       fwrite(lbuf,w,sizeof(unsigned char),fp2);
  89.     }
  90.     fclose(fp2);
  91.   }
  92.   fclose(fp1);
  93.   return 1;
  94. }
  95.