annotate system/file.cc @ 55:f1a27ee7e03c

* started the same changes on scn2k_text.cc * handle opcodes childObj*. In fact, it was handled (in a strange way, but it worked) before the previous changeset
author thib
date Wed, 22 Apr 2009 15:01:42 +0000
parents ddbcbd000206
children 4416cfac86ae
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
223b71206888 Initial import
thib
parents:
diff changeset
1 bool init_end=false;
223b71206888 Initial import
thib
parents:
diff changeset
2 /* file.cc : KANON ¤Î°µ½Ì¥Õ¥¡¥¤¥ë¡¦PDT ¥Õ¥¡¥¤¥ë¡Ê²èÁü¥Õ¥¡¥¤¥ë¡Ë¤ÎŸ³«¤Î
223b71206888 Initial import
thib
parents:
diff changeset
3 * ¤¿¤á¤Î¥á¥½¥Ã¥É
223b71206888 Initial import
thib
parents:
diff changeset
4 * class ARCFILE : ½ñ¸Ë¥Õ¥¡¥¤¥ëÁ´ÂΤò°·¤¦¥¯¥é¥¹
223b71206888 Initial import
thib
parents:
diff changeset
5 * class ARCINFO : ½ñ¸Ë¥Õ¥¡¥¤¥ë¤ÎÃæ¤Î£±¤Ä¤Î¥Õ¥¡¥¤¥ë¤ò°·¤¦¥¯¥é¥¹
223b71206888 Initial import
thib
parents:
diff changeset
6 * class PDTCONV : PDT ¥Õ¥¡¥¤¥ë¤ÎŸ³«¤ò¹Ô¤¦¡£
223b71206888 Initial import
thib
parents:
diff changeset
7 *
223b71206888 Initial import
thib
parents:
diff changeset
8 */
223b71206888 Initial import
thib
parents:
diff changeset
9
223b71206888 Initial import
thib
parents:
diff changeset
10 /*
223b71206888 Initial import
thib
parents:
diff changeset
11 *
223b71206888 Initial import
thib
parents:
diff changeset
12 * Copyright (C) 2000- Kazunori Ueno(JAGARL) <jagarl@creator.club.ne.jp>
223b71206888 Initial import
thib
parents:
diff changeset
13 *
223b71206888 Initial import
thib
parents:
diff changeset
14 * This program is free software; you can redistribute it and/or modify
223b71206888 Initial import
thib
parents:
diff changeset
15 * it under the terms of the GNU General Public License as published by
223b71206888 Initial import
thib
parents:
diff changeset
16 * the Free Software Foundation; either version 2 of the License, or
223b71206888 Initial import
thib
parents:
diff changeset
17 * (at your option) any later version.
223b71206888 Initial import
thib
parents:
diff changeset
18 *
223b71206888 Initial import
thib
parents:
diff changeset
19 * This program is distributed in the hope that it will be useful,
223b71206888 Initial import
thib
parents:
diff changeset
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
223b71206888 Initial import
thib
parents:
diff changeset
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
223b71206888 Initial import
thib
parents:
diff changeset
22 * GNU General Public License for more details.
223b71206888 Initial import
thib
parents:
diff changeset
23 *
27
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 9
diff changeset
24 * You should have received a copy of the GNU General Public License along
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 9
diff changeset
25 * with this program; if not, write to the Free Software Foundation, Inc.,
3a6aaeab7b4e * Fixed a typo in Jagarl's name
thib
parents: 9
diff changeset
26 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0
223b71206888 Initial import
thib
parents:
diff changeset
27 *
223b71206888 Initial import
thib
parents:
diff changeset
28 */
223b71206888 Initial import
thib
parents:
diff changeset
29
223b71206888 Initial import
thib
parents:
diff changeset
30 #ifdef HAVE_CONFIG_H
223b71206888 Initial import
thib
parents:
diff changeset
31 # include "config.h"
223b71206888 Initial import
thib
parents:
diff changeset
32 #endif
223b71206888 Initial import
thib
parents:
diff changeset
33
223b71206888 Initial import
thib
parents:
diff changeset
34 #ifdef HAVE_MMAP
223b71206888 Initial import
thib
parents:
diff changeset
35 # ifdef MACOSX
223b71206888 Initial import
thib
parents:
diff changeset
36 # undef HAVE_MMAP
223b71206888 Initial import
thib
parents:
diff changeset
37 # endif /* MACOSX */
223b71206888 Initial import
thib
parents:
diff changeset
38 #endif /* HAVE_MMAP */
223b71206888 Initial import
thib
parents:
diff changeset
39
223b71206888 Initial import
thib
parents:
diff changeset
40 #include <ctype.h>
223b71206888 Initial import
thib
parents:
diff changeset
41 #include <fcntl.h>
223b71206888 Initial import
thib
parents:
diff changeset
42 #include <unistd.h>
223b71206888 Initial import
thib
parents:
diff changeset
43 #include <stdlib.h>
223b71206888 Initial import
thib
parents:
diff changeset
44 #include <stdio.h>
223b71206888 Initial import
thib
parents:
diff changeset
45 #include <sys/types.h>
223b71206888 Initial import
thib
parents:
diff changeset
46 #include <sys/stat.h>
223b71206888 Initial import
thib
parents:
diff changeset
47 #include <vector>
223b71206888 Initial import
thib
parents:
diff changeset
48 #include <algorithm>
223b71206888 Initial import
thib
parents:
diff changeset
49 #if HAVE_MMAP
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
50 #include <sys/mman.h>
0
223b71206888 Initial import
thib
parents:
diff changeset
51 #endif /* HAVE_MMAP */
223b71206888 Initial import
thib
parents:
diff changeset
52 #if HAVE_DIRENT_H
223b71206888 Initial import
thib
parents:
diff changeset
53 # include <dirent.h>
223b71206888 Initial import
thib
parents:
diff changeset
54 # define NAMLEN(dirent) strlen((dirent)->d_name)
223b71206888 Initial import
thib
parents:
diff changeset
55 #else
223b71206888 Initial import
thib
parents:
diff changeset
56 # define dirent direct
223b71206888 Initial import
thib
parents:
diff changeset
57 # define NAMLEN(dirent) (dirent)->d_namlen
223b71206888 Initial import
thib
parents:
diff changeset
58 # if HAVE_SYS_NDIR_H
223b71206888 Initial import
thib
parents:
diff changeset
59 # include <sys/ndir.h>
223b71206888 Initial import
thib
parents:
diff changeset
60 # endif
223b71206888 Initial import
thib
parents:
diff changeset
61 # if HAVE_SYS_DIR_H
223b71206888 Initial import
thib
parents:
diff changeset
62 # include <sys/dir.h>
223b71206888 Initial import
thib
parents:
diff changeset
63 # endif
223b71206888 Initial import
thib
parents:
diff changeset
64 # if HAVE_NDIR_H
223b71206888 Initial import
thib
parents:
diff changeset
65 # include <ndir.h>
223b71206888 Initial import
thib
parents:
diff changeset
66 # endif
223b71206888 Initial import
thib
parents:
diff changeset
67 #endif
223b71206888 Initial import
thib
parents:
diff changeset
68
223b71206888 Initial import
thib
parents:
diff changeset
69 #if HAVE_LIBZ
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
70 #include <zlib.h>
0
223b71206888 Initial import
thib
parents:
diff changeset
71 #endif
223b71206888 Initial import
thib
parents:
diff changeset
72 #if HAVE_LIBPNG
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
73 #include <png.h>
0
223b71206888 Initial import
thib
parents:
diff changeset
74 #endif
223b71206888 Initial import
thib
parents:
diff changeset
75 #if HAVE_LIBJPEG
223b71206888 Initial import
thib
parents:
diff changeset
76 extern "C" {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
77 #include <jpeglib.h>
0
223b71206888 Initial import
thib
parents:
diff changeset
78 }
223b71206888 Initial import
thib
parents:
diff changeset
79 #endif
223b71206888 Initial import
thib
parents:
diff changeset
80
223b71206888 Initial import
thib
parents:
diff changeset
81 #include "file.h"
223b71206888 Initial import
thib
parents:
diff changeset
82 #include "file_impl.h"
223b71206888 Initial import
thib
parents:
diff changeset
83
223b71206888 Initial import
thib
parents:
diff changeset
84 using namespace std;
223b71206888 Initial import
thib
parents:
diff changeset
85
223b71206888 Initial import
thib
parents:
diff changeset
86 // #define delete fprintf(stderr,"file.cc: %d.",__LINE__), delete
223b71206888 Initial import
thib
parents:
diff changeset
87
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
88 /* FileSearcher class ¤Î default ¤Î¿¶¤ëÉñ¤¤ */
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
89 FileSearcher *FileSearcher::_singleton = NULL;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
90 FileSearcher::ARCTYPE FileSearcher::default_is_archived[TYPEMAX] = {
0
223b71206888 Initial import
thib
parents:
diff changeset
91 ATYPE_DIR, ATYPE_DIR, ATYPE_DIR, ATYPE_DIR,
223b71206888 Initial import
thib
parents:
diff changeset
92 ATYPE_ARC, ATYPE_ARC, ATYPE_ARC, ATYPE_ARC,
223b71206888 Initial import
thib
parents:
diff changeset
93 ATYPE_DIR, ATYPE_DIR, ATYPE_DIR, ATYPE_DIR,
223b71206888 Initial import
thib
parents:
diff changeset
94 ATYPE_DIR, ATYPE_DIR
223b71206888 Initial import
thib
parents:
diff changeset
95 };
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
96 const char* FileSearcher::default_dirnames[TYPEMAX] = {
0
223b71206888 Initial import
thib
parents:
diff changeset
97 0, 0, "", "pdt",
223b71206888 Initial import
thib
parents:
diff changeset
98 "seen.txt", "allanm.anl", "allard.ard", "allcur.cur",
223b71206888 Initial import
thib
parents:
diff changeset
99 0, 0, "koe", "bgm", "mov", "gan"};
223b71206888 Initial import
thib
parents:
diff changeset
100
223b71206888 Initial import
thib
parents:
diff changeset
101 /*********************************************
223b71206888 Initial import
thib
parents:
diff changeset
102 ** ARCFILE / DIRFILE:
223b71206888 Initial import
thib
parents:
diff changeset
103 ** ½ñ¸Ë¥Õ¥¡¥¤¥ë¡¢¤¢¤ë¤¤¤Ï¥Ç¥£¥ì¥¯¥È¥ê¤Î
223b71206888 Initial import
thib
parents:
diff changeset
104 ** Á´ÂΤò´ÉÍý¤¹¤ë¥¯¥é¥¹
223b71206888 Initial import
thib
parents:
diff changeset
105 **
223b71206888 Initial import
thib
parents:
diff changeset
106 ** ½ñ¸Ë¥Õ¥¡¥¤¥ë¤«¤é¥Õ¥¡¥¤¥ë¤ÎÈ´¤­½Ð¤·¤ÏFind()
223b71206888 Initial import
thib
parents:
diff changeset
107 ** Find ¤·¤¿¤â¤Î¤òRead¤¹¤ë¤ÈÆâÍƤ¬ÆÀ¤é¤ì¤ë¡£
223b71206888 Initial import
thib
parents:
diff changeset
108 */
223b71206888 Initial import
thib
parents:
diff changeset
109
47
5f548e5957a8 * get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents: 43
diff changeset
110 ARCFILE::ARCFILE(const char* aname) {
0
223b71206888 Initial import
thib
parents:
diff changeset
111 struct stat sb;
223b71206888 Initial import
thib
parents:
diff changeset
112 /* ÊÑ¿ô½é´ü²½ */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
113 arcname = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
114 list_point = 0;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
115 filenames_orig = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
116 next = NULL;
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
117 if (aname[0] == '\0') {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
118 arcname = new char[1];
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
119 arcname[0]='\0';
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
120 return;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
121 } // NULFILE
0
223b71206888 Initial import
thib
parents:
diff changeset
122 /* ¥Ç¥£¥ì¥¯¥È¥ê¤«Èݤ«¤Î¥Á¥§¥Ã¥¯ */
223b71206888 Initial import
thib
parents:
diff changeset
123 if (stat(aname,&sb) == -1) { /* error */
223b71206888 Initial import
thib
parents:
diff changeset
124 perror("stat");
223b71206888 Initial import
thib
parents:
diff changeset
125 }
223b71206888 Initial import
thib
parents:
diff changeset
126 if ( (sb.st_mode&S_IFMT) == S_IFDIR) {
223b71206888 Initial import
thib
parents:
diff changeset
127 int l = strlen(aname);
223b71206888 Initial import
thib
parents:
diff changeset
128 arcname = new char[l+2]; strcpy(arcname, aname);
223b71206888 Initial import
thib
parents:
diff changeset
129 if (arcname[l-1] != DIR_SPLIT) {
223b71206888 Initial import
thib
parents:
diff changeset
130 arcname[l] = DIR_SPLIT;
223b71206888 Initial import
thib
parents:
diff changeset
131 arcname[l+1] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
132 }
223b71206888 Initial import
thib
parents:
diff changeset
133 } else if ( (sb.st_mode&S_IFMT) == S_IFREG) {
223b71206888 Initial import
thib
parents:
diff changeset
134 arcname = new char[strlen(aname)+1];
223b71206888 Initial import
thib
parents:
diff changeset
135 strcpy(arcname,aname);
223b71206888 Initial import
thib
parents:
diff changeset
136 if (arcname[strlen(arcname)-1] == DIR_SPLIT)
223b71206888 Initial import
thib
parents:
diff changeset
137 arcname[strlen(arcname)-1] = '\0';
223b71206888 Initial import
thib
parents:
diff changeset
138 }
223b71206888 Initial import
thib
parents:
diff changeset
139 }
223b71206888 Initial import
thib
parents:
diff changeset
140
223b71206888 Initial import
thib
parents:
diff changeset
141 void ARCFILE::Init(void) {
223b71206888 Initial import
thib
parents:
diff changeset
142 if (! arc_atom.empty()) return;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
143 if (arcname == NULL) return;
0
223b71206888 Initial import
thib
parents:
diff changeset
144 /* ¥Õ¥¡¥¤¥ë¿ô¤òÆÀ¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
145 int slen = CheckFileDeal();
223b71206888 Initial import
thib
parents:
diff changeset
146 /* ¥Õ¥¡¥¤¥ë̾¤Î¥»¥Ã¥È */
223b71206888 Initial import
thib
parents:
diff changeset
147 ListupFiles(slen);
223b71206888 Initial import
thib
parents:
diff changeset
148 if ( (!arc_atom.empty()) && arc_atom[0].filename) filenames_orig = arc_atom[0].filename;
223b71206888 Initial import
thib
parents:
diff changeset
149 sort(arc_atom.begin(), arc_atom.end());
223b71206888 Initial import
thib
parents:
diff changeset
150 }
223b71206888 Initial import
thib
parents:
diff changeset
151 ARCFILE::~ARCFILE() {
223b71206888 Initial import
thib
parents:
diff changeset
152 if (filenames_orig) delete[] filenames_orig;
223b71206888 Initial import
thib
parents:
diff changeset
153 delete[] arcname;
50
35ce1a30f3f9 * Added va_end where there is a va_start
thib
parents: 47
diff changeset
154 delete next;
0
223b71206888 Initial import
thib
parents:
diff changeset
155 }
223b71206888 Initial import
thib
parents:
diff changeset
156
223b71206888 Initial import
thib
parents:
diff changeset
157 ARCFILE::iterator ARCFILE::SearchName(const char* f, const char* ext) {
223b71206888 Initial import
thib
parents:
diff changeset
158 char buf[1024]; char buf_ext[1024];
223b71206888 Initial import
thib
parents:
diff changeset
159 iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
160 Init();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
161 if (f == NULL) return arc_atom.end();
0
223b71206888 Initial import
thib
parents:
diff changeset
162 if (arc_atom.empty()) return arc_atom.end();
223b71206888 Initial import
thib
parents:
diff changeset
163 /* ¥¨¥é¡¼¥Á¥§¥Ã¥¯ */
223b71206888 Initial import
thib
parents:
diff changeset
164 if (strlen(f)>500) return arc_atom.end();
223b71206888 Initial import
thib
parents:
diff changeset
165 if (ext && strlen(ext)>500) return arc_atom.end();
223b71206888 Initial import
thib
parents:
diff changeset
166
223b71206888 Initial import
thib
parents:
diff changeset
167 /* ¸¡º÷ */
223b71206888 Initial import
thib
parents:
diff changeset
168 strncpy(buf, f, 1000);
223b71206888 Initial import
thib
parents:
diff changeset
169 buf[1000]=0;
223b71206888 Initial import
thib
parents:
diff changeset
170 it = lower_bound(arc_atom.begin(), arc_atom.end(), (char*)buf);
223b71206888 Initial import
thib
parents:
diff changeset
171 if (it != arc_atom.end() && strcmp(it->filename_lower, buf) == 0) return it;
223b71206888 Initial import
thib
parents:
diff changeset
172 // ³ÈÄ¥»Ò¤ò¤Ä¤±¤Æ¸¡º÷
223b71206888 Initial import
thib
parents:
diff changeset
173 if (ext) {
223b71206888 Initial import
thib
parents:
diff changeset
174 strcpy(buf_ext, buf);
223b71206888 Initial import
thib
parents:
diff changeset
175 char* ext_pt = strrchr(buf_ext, '.');
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
176 if (ext_pt == NULL || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext);
0
223b71206888 Initial import
thib
parents:
diff changeset
177 *ext_pt++ = '.';
223b71206888 Initial import
thib
parents:
diff changeset
178 while(*ext=='.') ext++;
223b71206888 Initial import
thib
parents:
diff changeset
179 strcat(buf_ext, ext);
223b71206888 Initial import
thib
parents:
diff changeset
180 it = lower_bound(arc_atom.begin(), arc_atom.end(), (char*)buf_ext);
223b71206888 Initial import
thib
parents:
diff changeset
181 if (it != arc_atom.end() && strcmp(it->filename_lower, buf_ext) == 0) return it;
223b71206888 Initial import
thib
parents:
diff changeset
182 }
223b71206888 Initial import
thib
parents:
diff changeset
183
223b71206888 Initial import
thib
parents:
diff changeset
184 /* ¾®Ê¸»ú¤Ë¤·¤Æ ¸¡º÷ */
223b71206888 Initial import
thib
parents:
diff changeset
185 int i; int l = strlen(f);
223b71206888 Initial import
thib
parents:
diff changeset
186 if (l > 500) l = 500;
223b71206888 Initial import
thib
parents:
diff changeset
187 for (i=0; i<l; i++)
223b71206888 Initial import
thib
parents:
diff changeset
188 buf[i] = tolower(f[i]);
223b71206888 Initial import
thib
parents:
diff changeset
189 buf[i++] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
190 it = lower_bound(arc_atom.begin(), arc_atom.end(), (char*)buf);
223b71206888 Initial import
thib
parents:
diff changeset
191 if (it != arc_atom.end() && strcmp(it->filename_lower, buf) == 0) return it;
223b71206888 Initial import
thib
parents:
diff changeset
192
223b71206888 Initial import
thib
parents:
diff changeset
193 // ³ÈÄ¥»Ò¤ò¤Ä¤±¤Æ¸¡º÷
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
194 if (ext == NULL) return arc_atom.end();
0
223b71206888 Initial import
thib
parents:
diff changeset
195 strcpy(buf_ext, buf);
223b71206888 Initial import
thib
parents:
diff changeset
196 char* ext_pt = strrchr(buf_ext, '.');
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
197 if (ext_pt == NULL || ext_pt == buf_ext) ext_pt = buf_ext + strlen(buf_ext);
0
223b71206888 Initial import
thib
parents:
diff changeset
198 *ext_pt++ = '.';
223b71206888 Initial import
thib
parents:
diff changeset
199 /* ³ÈÄ¥»Ò¤ÎŤµ¤òÆÀ¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
200 l = strlen(ext);
223b71206888 Initial import
thib
parents:
diff changeset
201 for (i=0; i<l; i++)
223b71206888 Initial import
thib
parents:
diff changeset
202 ext_pt[i] = tolower(*ext++);
223b71206888 Initial import
thib
parents:
diff changeset
203 ext_pt[i] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
204 it = lower_bound(arc_atom.begin(), arc_atom.end(), (char*)buf_ext);
223b71206888 Initial import
thib
parents:
diff changeset
205 if (it != arc_atom.end() && strcmp(it->filename_lower, buf_ext) == 0) return it;
223b71206888 Initial import
thib
parents:
diff changeset
206 return arc_atom.end();
223b71206888 Initial import
thib
parents:
diff changeset
207 }
223b71206888 Initial import
thib
parents:
diff changeset
208
223b71206888 Initial import
thib
parents:
diff changeset
209 ARCINFO* ARCFILE::Find(const char* fname, const char* ext) {
223b71206888 Initial import
thib
parents:
diff changeset
210 Init();
223b71206888 Initial import
thib
parents:
diff changeset
211 iterator atom = SearchName(fname,ext);
223b71206888 Initial import
thib
parents:
diff changeset
212 if (atom == arc_atom.end()) {
223b71206888 Initial import
thib
parents:
diff changeset
213 if (next) return next->Find(fname, ext);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
214 else return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
215 }
223b71206888 Initial import
thib
parents:
diff changeset
216 return MakeARCINFO(*atom);
223b71206888 Initial import
thib
parents:
diff changeset
217 }
223b71206888 Initial import
thib
parents:
diff changeset
218 ARCINFO* ARCFILE::MakeARCINFO(ARCFILE_ATOM& atom) {
223b71206888 Initial import
thib
parents:
diff changeset
219 if (atom.arcsize == atom.filesize)
223b71206888 Initial import
thib
parents:
diff changeset
220 return new ARCINFO(arcname, atom);
223b71206888 Initial import
thib
parents:
diff changeset
221 else // °µ½ÌÉÕ
223b71206888 Initial import
thib
parents:
diff changeset
222 return new ARCINFO_AVG32(arcname, atom);
223b71206888 Initial import
thib
parents:
diff changeset
223 }
223b71206888 Initial import
thib
parents:
diff changeset
224 ARCINFO* NULFILE::MakeARCINFO(ARCFILE_ATOM& atom) {
223b71206888 Initial import
thib
parents:
diff changeset
225 fprintf(stderr,"NULFILE::MakeARCINFO is invalid call!\n");
223b71206888 Initial import
thib
parents:
diff changeset
226 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
227 }
223b71206888 Initial import
thib
parents:
diff changeset
228 ARCINFO* SCN2kFILE::MakeARCINFO(ARCFILE_ATOM& atom) {
223b71206888 Initial import
thib
parents:
diff changeset
229 return new ARCINFO2k(arcname, atom);
223b71206888 Initial import
thib
parents:
diff changeset
230 }
223b71206888 Initial import
thib
parents:
diff changeset
231 ARCINFO* DIRFILE::MakeARCINFO(ARCFILE_ATOM& atom) {
223b71206888 Initial import
thib
parents:
diff changeset
232 char* name = atom.filename;
223b71206888 Initial import
thib
parents:
diff changeset
233 char* new_path = new char[strlen(arcname)+strlen(name)+1];
223b71206888 Initial import
thib
parents:
diff changeset
234 strcpy(new_path,arcname); strcat(new_path, name);
223b71206888 Initial import
thib
parents:
diff changeset
235 ARCINFO* ret = new ARCINFO(new_path, atom);
223b71206888 Initial import
thib
parents:
diff changeset
236 delete[] new_path;
223b71206888 Initial import
thib
parents:
diff changeset
237 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
238 }
223b71206888 Initial import
thib
parents:
diff changeset
239
223b71206888 Initial import
thib
parents:
diff changeset
240 FILE* DIRFILE::Open(const char* fname) {
223b71206888 Initial import
thib
parents:
diff changeset
241 iterator atom = SearchName(fname);
223b71206888 Initial import
thib
parents:
diff changeset
242 if (atom == arc_atom.end()) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
243 char* name = atom->filename;
223b71206888 Initial import
thib
parents:
diff changeset
244 // make FILE*
223b71206888 Initial import
thib
parents:
diff changeset
245 char* new_path = new char[strlen(arcname)+strlen(name)+1];
223b71206888 Initial import
thib
parents:
diff changeset
246 strcpy(new_path,arcname); strcat(new_path, name);
223b71206888 Initial import
thib
parents:
diff changeset
247 FILE* ret = fopen(new_path, "rb+");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
248 fseek(ret, 0, SEEK_SET);
0
223b71206888 Initial import
thib
parents:
diff changeset
249 delete[] new_path;
223b71206888 Initial import
thib
parents:
diff changeset
250 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
251 }
223b71206888 Initial import
thib
parents:
diff changeset
252
223b71206888 Initial import
thib
parents:
diff changeset
253 char* DIRFILE::SearchFile(const char* fname) {
223b71206888 Initial import
thib
parents:
diff changeset
254 iterator atom = SearchName(fname);
223b71206888 Initial import
thib
parents:
diff changeset
255 if (atom == arc_atom.end()) return 0;
223b71206888 Initial import
thib
parents:
diff changeset
256 char* name = atom->filename;
223b71206888 Initial import
thib
parents:
diff changeset
257 char* new_path = new char[strlen(arcname)+strlen(name)+1];
223b71206888 Initial import
thib
parents:
diff changeset
258 strcpy(new_path,arcname); strcat(new_path, name);
223b71206888 Initial import
thib
parents:
diff changeset
259 struct stat sb;
223b71206888 Initial import
thib
parents:
diff changeset
260 if (stat(new_path, &sb) == 0 &&
223b71206888 Initial import
thib
parents:
diff changeset
261 ( (sb.st_mode&S_IFMT) == S_IFREG ||
223b71206888 Initial import
thib
parents:
diff changeset
262 (sb.st_mode&S_IFMT) == S_IFDIR)) {
223b71206888 Initial import
thib
parents:
diff changeset
263 return new_path;
223b71206888 Initial import
thib
parents:
diff changeset
264 }
223b71206888 Initial import
thib
parents:
diff changeset
265 delete[] new_path;
223b71206888 Initial import
thib
parents:
diff changeset
266 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
267 }
223b71206888 Initial import
thib
parents:
diff changeset
268
223b71206888 Initial import
thib
parents:
diff changeset
269 void ARCFILE::ListFiles(FILE* out) {
223b71206888 Initial import
thib
parents:
diff changeset
270 Init();
223b71206888 Initial import
thib
parents:
diff changeset
271 if (arc_atom.empty()) return;
223b71206888 Initial import
thib
parents:
diff changeset
272 // list file name...
223b71206888 Initial import
thib
parents:
diff changeset
273 fprintf(out,"%16s %10s %10s %10s\n", "Filename",
223b71206888 Initial import
thib
parents:
diff changeset
274 "pointer","arcsize", "filesize");
223b71206888 Initial import
thib
parents:
diff changeset
275 vector<ARCFILE_ATOM>::iterator it;
223b71206888 Initial import
thib
parents:
diff changeset
276 for (it=arc_atom.begin(); it!=arc_atom.end(); it++) {
223b71206888 Initial import
thib
parents:
diff changeset
277 fprintf(out,"%16s %10d %10d %10d\n",
223b71206888 Initial import
thib
parents:
diff changeset
278 it->filename,it->offset,it->arcsize,it->filesize);
223b71206888 Initial import
thib
parents:
diff changeset
279 }
223b71206888 Initial import
thib
parents:
diff changeset
280 return;
223b71206888 Initial import
thib
parents:
diff changeset
281 }
223b71206888 Initial import
thib
parents:
diff changeset
282
223b71206888 Initial import
thib
parents:
diff changeset
283 void ARCFILE::InitList(void) {
223b71206888 Initial import
thib
parents:
diff changeset
284 Init();
223b71206888 Initial import
thib
parents:
diff changeset
285 list_point = 0;
223b71206888 Initial import
thib
parents:
diff changeset
286 }
223b71206888 Initial import
thib
parents:
diff changeset
287 char* ARCFILE::ListItem(void) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
288 if (list_point < 0) return NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
289 if (list_point >= arc_atom.size()) return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
290 char* fname = arc_atom[list_point].filename;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
291 if (fname == NULL) return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
292 char* ret = new char[strlen(fname)+1];
223b71206888 Initial import
thib
parents:
diff changeset
293 strcpy(ret, fname);
223b71206888 Initial import
thib
parents:
diff changeset
294 list_point++;
223b71206888 Initial import
thib
parents:
diff changeset
295 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
296 }
223b71206888 Initial import
thib
parents:
diff changeset
297
223b71206888 Initial import
thib
parents:
diff changeset
298 int ARCFILE::CheckFileDeal(void) {
223b71206888 Initial import
thib
parents:
diff changeset
299 char buf[0x20];
223b71206888 Initial import
thib
parents:
diff changeset
300 /* ¥Ø¥Ã¥À¤Î¥Á¥§¥Ã¥¯ */
223b71206888 Initial import
thib
parents:
diff changeset
301 FILE* stream = fopen(arcname, "rb");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
302 if (stream == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
303 fprintf(stderr, "Cannot open archive file : %s\n",arcname);
223b71206888 Initial import
thib
parents:
diff changeset
304 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
305 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
306 fseek(stream, 0, SEEK_END);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
307 size_t arc_size = ftell(stream);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
308 fseek(stream, 0, SEEK_SET);
0
223b71206888 Initial import
thib
parents:
diff changeset
309 if (arc_size < 0x20) {
223b71206888 Initial import
thib
parents:
diff changeset
310 fclose(stream);
223b71206888 Initial import
thib
parents:
diff changeset
311 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
312 }
223b71206888 Initial import
thib
parents:
diff changeset
313 fread(buf, 0x20, 1, stream);
223b71206888 Initial import
thib
parents:
diff changeset
314 if (strncmp(buf, "PACL", 4) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
315 fclose(stream);
223b71206888 Initial import
thib
parents:
diff changeset
316 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
317 }
223b71206888 Initial import
thib
parents:
diff changeset
318 int len = read_little_endian_int(buf+0x10);
223b71206888 Initial import
thib
parents:
diff changeset
319 if (arc_size < size_t(0x20 + len*0x20)) {
223b71206888 Initial import
thib
parents:
diff changeset
320 fclose(stream);
223b71206888 Initial import
thib
parents:
diff changeset
321 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
322 }
223b71206888 Initial import
thib
parents:
diff changeset
323 int i; int slen = 0;
223b71206888 Initial import
thib
parents:
diff changeset
324 for (i=0; i<len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
325 fread(buf, 0x20, 1, stream);
223b71206888 Initial import
thib
parents:
diff changeset
326 slen += strlen(buf)+1;
223b71206888 Initial import
thib
parents:
diff changeset
327 }
223b71206888 Initial import
thib
parents:
diff changeset
328 fclose(stream);
223b71206888 Initial import
thib
parents:
diff changeset
329 return slen;
223b71206888 Initial import
thib
parents:
diff changeset
330 }
223b71206888 Initial import
thib
parents:
diff changeset
331 void ARCFILE::ListupFiles(int fname_len) {
223b71206888 Initial import
thib
parents:
diff changeset
332 int i; char fbuf[0x20];
223b71206888 Initial import
thib
parents:
diff changeset
333 fname_len *= 2;
223b71206888 Initial import
thib
parents:
diff changeset
334 char* buf = new char[fname_len];
223b71206888 Initial import
thib
parents:
diff changeset
335 FILE* stream = fopen(arcname, "rb");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
336 if (stream == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
337 fprintf(stderr, "Cannot open archive file : %s\n",arcname);
223b71206888 Initial import
thib
parents:
diff changeset
338 return;
223b71206888 Initial import
thib
parents:
diff changeset
339 }
223b71206888 Initial import
thib
parents:
diff changeset
340 fread(fbuf,0x20,1,stream);
223b71206888 Initial import
thib
parents:
diff changeset
341 int len = read_little_endian_int(fbuf+0x10);
223b71206888 Initial import
thib
parents:
diff changeset
342 ARCFILE_ATOM atom;
223b71206888 Initial import
thib
parents:
diff changeset
343 for (i=0; i<len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
344 fread(fbuf, 0x20, 1, stream);
223b71206888 Initial import
thib
parents:
diff changeset
345 int l = strlen(fbuf);
223b71206888 Initial import
thib
parents:
diff changeset
346 if (l*2+2 > fname_len) {
223b71206888 Initial import
thib
parents:
diff changeset
347 break;
223b71206888 Initial import
thib
parents:
diff changeset
348 }
223b71206888 Initial import
thib
parents:
diff changeset
349 atom.offset = read_little_endian_int(fbuf+0x10);
223b71206888 Initial import
thib
parents:
diff changeset
350 atom.arcsize = read_little_endian_int(fbuf+0x14);
223b71206888 Initial import
thib
parents:
diff changeset
351 atom.filesize = read_little_endian_int(fbuf+0x18);
223b71206888 Initial import
thib
parents:
diff changeset
352 int j; for (j=0; j<l; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
353 buf[j] = fbuf[j];
223b71206888 Initial import
thib
parents:
diff changeset
354 buf[j+l+1] = tolower(fbuf[j]);
223b71206888 Initial import
thib
parents:
diff changeset
355 }
223b71206888 Initial import
thib
parents:
diff changeset
356 buf[j] = buf[j+l+1] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
357 atom.filename = buf;
223b71206888 Initial import
thib
parents:
diff changeset
358 atom.filename_lower = buf+l+1;
223b71206888 Initial import
thib
parents:
diff changeset
359 arc_atom.push_back(atom);
223b71206888 Initial import
thib
parents:
diff changeset
360 buf += l*2+2; fname_len -= l*2+2;
223b71206888 Initial import
thib
parents:
diff changeset
361 }
223b71206888 Initial import
thib
parents:
diff changeset
362 fclose(stream);
223b71206888 Initial import
thib
parents:
diff changeset
363 return;
223b71206888 Initial import
thib
parents:
diff changeset
364 }
223b71206888 Initial import
thib
parents:
diff changeset
365 int DIRFILE::CheckFileDeal(void) {
223b71206888 Initial import
thib
parents:
diff changeset
366 DIR* dir; struct dirent* ent;
223b71206888 Initial import
thib
parents:
diff changeset
367 int flen = 0;
223b71206888 Initial import
thib
parents:
diff changeset
368 dir = opendir(arcname);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
369 if (dir == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
370 fprintf(stderr, "Cannot open dir file : %s\n",arcname);
223b71206888 Initial import
thib
parents:
diff changeset
371 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
372 }
223b71206888 Initial import
thib
parents:
diff changeset
373 int count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
374 while( (ent = readdir(dir)) != NULL) {
223b71206888 Initial import
thib
parents:
diff changeset
375 count++;
223b71206888 Initial import
thib
parents:
diff changeset
376 flen += strlen(ent->d_name)+1;
223b71206888 Initial import
thib
parents:
diff changeset
377 }
223b71206888 Initial import
thib
parents:
diff changeset
378 closedir(dir);
223b71206888 Initial import
thib
parents:
diff changeset
379 return flen;
223b71206888 Initial import
thib
parents:
diff changeset
380 }
223b71206888 Initial import
thib
parents:
diff changeset
381 void DIRFILE::ListupFiles(int fname_len) {
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 35
diff changeset
382 DIR* dir;
0
223b71206888 Initial import
thib
parents:
diff changeset
383 fname_len *= 2;
223b71206888 Initial import
thib
parents:
diff changeset
384 dir = opendir(arcname);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
385 if (dir == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
386 fprintf(stderr, "Cannot open dir file : %s\n",arcname);
223b71206888 Initial import
thib
parents:
diff changeset
387 return;
223b71206888 Initial import
thib
parents:
diff changeset
388 }
223b71206888 Initial import
thib
parents:
diff changeset
389 /* °ì»þŪ¤Ë arcname ¤Î¥Ç¥£¥ì¥¯¥È¥ê¤Ë°ÜÆ°¤¹¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
390 int old_dir_fd = open(".",O_RDONLY);
223b71206888 Initial import
thib
parents:
diff changeset
391 if (old_dir_fd < 0) {
223b71206888 Initial import
thib
parents:
diff changeset
392 closedir(dir);
223b71206888 Initial import
thib
parents:
diff changeset
393 return;
223b71206888 Initial import
thib
parents:
diff changeset
394 }
223b71206888 Initial import
thib
parents:
diff changeset
395 if (chdir(arcname) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
396 fprintf(stderr, "Cannot open dir file : %s\n",arcname);
223b71206888 Initial import
thib
parents:
diff changeset
397 closedir(dir);
223b71206888 Initial import
thib
parents:
diff changeset
398 close(old_dir_fd);
223b71206888 Initial import
thib
parents:
diff changeset
399 return;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
400 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
401
0
223b71206888 Initial import
thib
parents:
diff changeset
402 char* buf = new char[fname_len];
223b71206888 Initial import
thib
parents:
diff changeset
403 ARCFILE_ATOM atom;
223b71206888 Initial import
thib
parents:
diff changeset
404 struct stat sb;
223b71206888 Initial import
thib
parents:
diff changeset
405 struct dirent* ent;
223b71206888 Initial import
thib
parents:
diff changeset
406 while( (ent = readdir(dir)) != NULL) {
223b71206888 Initial import
thib
parents:
diff changeset
407 if (stat(ent->d_name, &sb) == -1) continue;
223b71206888 Initial import
thib
parents:
diff changeset
408 if ( (sb.st_mode & S_IFMT) == S_IFREG) {
223b71206888 Initial import
thib
parents:
diff changeset
409 atom.offset = 0;
223b71206888 Initial import
thib
parents:
diff changeset
410 atom.arcsize = sb.st_size;
223b71206888 Initial import
thib
parents:
diff changeset
411 atom.filesize = sb.st_size;
223b71206888 Initial import
thib
parents:
diff changeset
412 } else if ( (sb.st_mode & S_IFMT) == S_IFDIR) {
223b71206888 Initial import
thib
parents:
diff changeset
413 atom.offset = 0;
223b71206888 Initial import
thib
parents:
diff changeset
414 atom.arcsize = atom.filesize = 0;
223b71206888 Initial import
thib
parents:
diff changeset
415 } else {
223b71206888 Initial import
thib
parents:
diff changeset
416 continue;
223b71206888 Initial import
thib
parents:
diff changeset
417 }
223b71206888 Initial import
thib
parents:
diff changeset
418 int l = strlen(ent->d_name);
223b71206888 Initial import
thib
parents:
diff changeset
419 if (l*2+2 > fname_len) {
223b71206888 Initial import
thib
parents:
diff changeset
420 break;
223b71206888 Initial import
thib
parents:
diff changeset
421 }
223b71206888 Initial import
thib
parents:
diff changeset
422 int j; for (j=0; j<l+1; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
423 buf[j] = ent->d_name[j];
223b71206888 Initial import
thib
parents:
diff changeset
424 buf[j+l+1] = tolower(ent->d_name[j]);
223b71206888 Initial import
thib
parents:
diff changeset
425 }
223b71206888 Initial import
thib
parents:
diff changeset
426 atom.filename = buf; atom.filename_lower = buf+l+1;
223b71206888 Initial import
thib
parents:
diff changeset
427 arc_atom.push_back(atom);
223b71206888 Initial import
thib
parents:
diff changeset
428 buf += l*2+2; fname_len -= l*2+2;
223b71206888 Initial import
thib
parents:
diff changeset
429 }
223b71206888 Initial import
thib
parents:
diff changeset
430 /* chdir() ¤·¤¿¤Î¤ò¸µ¤ËÌá¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
431 closedir(dir);
223b71206888 Initial import
thib
parents:
diff changeset
432 fchdir(old_dir_fd); close(old_dir_fd);
223b71206888 Initial import
thib
parents:
diff changeset
433 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
434
0
223b71206888 Initial import
thib
parents:
diff changeset
435 int NULFILE::CheckFileDeal(void) {
223b71206888 Initial import
thib
parents:
diff changeset
436 return 20;
223b71206888 Initial import
thib
parents:
diff changeset
437 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
438
0
223b71206888 Initial import
thib
parents:
diff changeset
439 void NULFILE::ListupFiles(int fname_len) {
223b71206888 Initial import
thib
parents:
diff changeset
440 char* s = new char[40];
223b71206888 Initial import
thib
parents:
diff changeset
441 ARCFILE_ATOM atom;
223b71206888 Initial import
thib
parents:
diff changeset
442 atom.offset = 0; atom.arcsize = 0; atom.filesize = 0;
223b71206888 Initial import
thib
parents:
diff changeset
443 strcpy(s, "** null dummy **");
223b71206888 Initial import
thib
parents:
diff changeset
444 atom.filename = s;
223b71206888 Initial import
thib
parents:
diff changeset
445 atom.filename_lower = s;
223b71206888 Initial import
thib
parents:
diff changeset
446 arc_atom.push_back(atom);
223b71206888 Initial import
thib
parents:
diff changeset
447 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
448
0
223b71206888 Initial import
thib
parents:
diff changeset
449 int SCN2kFILE::CheckFileDeal(void) {
223b71206888 Initial import
thib
parents:
diff changeset
450 /* ¥Ø¥Ã¥À¤Î¥Á¥§¥Ã¥¯ */
223b71206888 Initial import
thib
parents:
diff changeset
451 FILE* stream = fopen(arcname, "rb");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
452 if (stream == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
453 fprintf(stderr, "Cannot open archive file : %s\n",arcname);
223b71206888 Initial import
thib
parents:
diff changeset
454 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
455 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
456 fseek(stream, 0, SEEK_END);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
457 size_t arc_size = ftell(stream);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
458 fseek(stream, 0, SEEK_SET);
0
223b71206888 Initial import
thib
parents:
diff changeset
459 if (arc_size < 10000*8) {
223b71206888 Initial import
thib
parents:
diff changeset
460 fclose(stream);
223b71206888 Initial import
thib
parents:
diff changeset
461 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
462 }
223b71206888 Initial import
thib
parents:
diff changeset
463 char* buf = new char[10000*8];
223b71206888 Initial import
thib
parents:
diff changeset
464 fread(buf, 10000, 8, stream);
223b71206888 Initial import
thib
parents:
diff changeset
465 /* size == 0 ¤Î¥Ç¡¼¥¿¤Ï¸ºß¤·¤Ê¤¤ */
223b71206888 Initial import
thib
parents:
diff changeset
466 int count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
467 int i; for (i=0; i<10000; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
468 int tmp_offset = read_little_endian_int(buf+i*8);
223b71206888 Initial import
thib
parents:
diff changeset
469 int tmp_size = read_little_endian_int(buf+i*8+4);
223b71206888 Initial import
thib
parents:
diff changeset
470 if (tmp_size <= 0 || tmp_offset < 0 || tmp_offset+tmp_size > int(arc_size) ) continue;
223b71206888 Initial import
thib
parents:
diff changeset
471 count++;
223b71206888 Initial import
thib
parents:
diff changeset
472 }
223b71206888 Initial import
thib
parents:
diff changeset
473 fclose(stream);
223b71206888 Initial import
thib
parents:
diff changeset
474 delete[] buf;
223b71206888 Initial import
thib
parents:
diff changeset
475 return count*13; /* ¥Õ¥¡¥¤¥ë̾¤Ï seenXXXX.txt ¤À¤«¤é¡¢°ì¤Ä12ʸ»ú+null */
223b71206888 Initial import
thib
parents:
diff changeset
476 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
477
0
223b71206888 Initial import
thib
parents:
diff changeset
478 void SCN2kFILE::ListupFiles(int fname_len) {
223b71206888 Initial import
thib
parents:
diff changeset
479 FILE* stream = fopen(arcname, "rb");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
480 if (stream == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
481 fprintf(stderr, "Cannot open archive file : %s\n",arcname);
223b71206888 Initial import
thib
parents:
diff changeset
482 return;
223b71206888 Initial import
thib
parents:
diff changeset
483 }
223b71206888 Initial import
thib
parents:
diff changeset
484 char* sbuf = new char[fname_len];
223b71206888 Initial import
thib
parents:
diff changeset
485 char* buf = new char[10000*8];
223b71206888 Initial import
thib
parents:
diff changeset
486 fread(buf, 10000, 8, stream);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
487 fseek(stream, 0, SEEK_END);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
488 size_t arc_size = ftell(stream);
0
223b71206888 Initial import
thib
parents:
diff changeset
489 ARCFILE_ATOM atom;
223b71206888 Initial import
thib
parents:
diff changeset
490 int i; for (i=0; i<10000; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
491 char header[0x200];
223b71206888 Initial import
thib
parents:
diff changeset
492 int tmp_offset = read_little_endian_int(buf+i*8);
223b71206888 Initial import
thib
parents:
diff changeset
493 int tmp_size = read_little_endian_int(buf+i*8+4);
223b71206888 Initial import
thib
parents:
diff changeset
494 if (tmp_size <= 0 || tmp_offset < 0 || tmp_offset+tmp_size > int(arc_size) ) continue;
223b71206888 Initial import
thib
parents:
diff changeset
495 /* header ¤òÆÀ¤Æ°µ½Ì·Á¼°¤Ê¤É¤òÄ´¤Ù¤ë */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
496 fseek(stream, tmp_offset, SEEK_SET);
0
223b71206888 Initial import
thib
parents:
diff changeset
497 fread(header, 0x200, 1, stream);
223b71206888 Initial import
thib
parents:
diff changeset
498 int header_top = read_little_endian_int(header+0);
223b71206888 Initial import
thib
parents:
diff changeset
499 int file_version = read_little_endian_int(header+4);
223b71206888 Initial import
thib
parents:
diff changeset
500
223b71206888 Initial import
thib
parents:
diff changeset
501 if (file_version == 0x1adb2) ; // Little Busters!
223b71206888 Initial import
thib
parents:
diff changeset
502 else if (file_version != 0x2712) continue; /* system version ¤¬°ã¤¦ */
223b71206888 Initial import
thib
parents:
diff changeset
503
223b71206888 Initial import
thib
parents:
diff changeset
504 if (header_top == 0x1cc) { /* ¸Å¤¤·Á¼° : avg2000 */
223b71206888 Initial import
thib
parents:
diff changeset
505 int header_size = read_little_endian_int(header+0)+read_little_endian_int(header+0x20)*4;
223b71206888 Initial import
thib
parents:
diff changeset
506 int data_size = read_little_endian_int(header+0x24);
223b71206888 Initial import
thib
parents:
diff changeset
507 atom.arcsize = data_size + header_size;
223b71206888 Initial import
thib
parents:
diff changeset
508 atom.filesize = data_size + header_size;
223b71206888 Initial import
thib
parents:
diff changeset
509 atom.private_data = header_size;
223b71206888 Initial import
thib
parents:
diff changeset
510
223b71206888 Initial import
thib
parents:
diff changeset
511 } else if (header_top == 0x1b8) { /* ½éÌ븥¾å */
223b71206888 Initial import
thib
parents:
diff changeset
512 int header_size = read_little_endian_int(header+0)+read_little_endian_int(header+0x08)*4;
223b71206888 Initial import
thib
parents:
diff changeset
513 int data_size = read_little_endian_int(header+0x0c);
223b71206888 Initial import
thib
parents:
diff changeset
514 int compdata_size = read_little_endian_int(header+0x10);
223b71206888 Initial import
thib
parents:
diff changeset
515 atom.arcsize = compdata_size + header_size;
223b71206888 Initial import
thib
parents:
diff changeset
516 atom.filesize = data_size + header_size;
223b71206888 Initial import
thib
parents:
diff changeset
517 atom.private_data = header_size;
223b71206888 Initial import
thib
parents:
diff changeset
518
223b71206888 Initial import
thib
parents:
diff changeset
519 } else if (header_top == 0x1d0) { /* ¿·¤·¤¤·Á¼°¡§ reallive */
223b71206888 Initial import
thib
parents:
diff changeset
520 int header_size = read_little_endian_int(header+0x20);
223b71206888 Initial import
thib
parents:
diff changeset
521 int data_size = read_little_endian_int(header+0x24);
223b71206888 Initial import
thib
parents:
diff changeset
522 int compdata_size = read_little_endian_int(header+0x28);
223b71206888 Initial import
thib
parents:
diff changeset
523 atom.arcsize = compdata_size + header_size;
223b71206888 Initial import
thib
parents:
diff changeset
524 atom.filesize = data_size + header_size;
223b71206888 Initial import
thib
parents:
diff changeset
525 atom.private_data = header_size;
223b71206888 Initial import
thib
parents:
diff changeset
526 } else {
223b71206888 Initial import
thib
parents:
diff changeset
527 fprintf(stderr,"invalid header top; %x : not supported\n",header_top);
223b71206888 Initial import
thib
parents:
diff changeset
528 continue; /* ¥µ¥Ý¡¼¥È¤·¤Ê¤¤·Á¼° */
223b71206888 Initial import
thib
parents:
diff changeset
529 }
223b71206888 Initial import
thib
parents:
diff changeset
530
223b71206888 Initial import
thib
parents:
diff changeset
531 atom.offset = tmp_offset;
223b71206888 Initial import
thib
parents:
diff changeset
532 atom.filename = sbuf;
223b71206888 Initial import
thib
parents:
diff changeset
533 atom.filename_lower = sbuf;
223b71206888 Initial import
thib
parents:
diff changeset
534 arc_atom.push_back(atom);
223b71206888 Initial import
thib
parents:
diff changeset
535 sprintf(sbuf, "seen%04d.txt",i); sbuf += 13;
223b71206888 Initial import
thib
parents:
diff changeset
536 }
7
fa8511a21d05 Fixes somes memory leaks
thib
parents: 0
diff changeset
537 delete[] buf;
0
223b71206888 Initial import
thib
parents:
diff changeset
538 fclose(stream);
223b71206888 Initial import
thib
parents:
diff changeset
539 }
223b71206888 Initial import
thib
parents:
diff changeset
540
223b71206888 Initial import
thib
parents:
diff changeset
541 /********************************************************
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
542 ** KeyHolder
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
543 */
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
544
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
545 KeyHolder* KeyHolder::_singleton = NULL;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
546
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
547 KeyHolder* KeyHolder::GetInstance(void)
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
548 {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
549 if (_singleton == NULL) _singleton = new KeyHolder;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
550 return _singleton;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
551 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
552
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
553 void KeyHolder::Quit(void)
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
554 {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
555 if (_singleton != NULL) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
556 delete _singleton;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
557 _singleton = NULL;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
558 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
559 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
560
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
561 void KeyHolder::SetKey(char new_key[16])
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
562 {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
563 unsigned short int i;
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
564 for (i=0; i < 16; i++)
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
565 key[i] = new_key[i];
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
566 }
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
567
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
568 void KeyHolder::SetKey2(char new_key[33])
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
569 {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
570 unsigned short int i;
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
571 char tmp[3];
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
572 tmp[2] = '\0';
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
573 for (i=0; i < 16; i++) {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
574 tmp[0] = new_key[i*2];
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
575 tmp[1] = new_key[i*2+1];
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
576 key[i] = strtoul(tmp, NULL, 16);
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
577 }
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
578 }
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
579
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
580 void KeyHolder::GuessKey(char *regname)
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
581 {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
582 char key1[16] = {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
583 0xa8, 0x28, 0xfd, 0x66,
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
584 0xa0, 0x23, 0x77, 0x69,
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
585 0xf9, 0x45, 0xf8, 0x2c,
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
586 0x7c, 0x00, 0xad, 0xf4
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
587 };
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
588
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
589 char key2[16] = {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
590 0xAF, 0x2F, 0xFB, 0x6B,
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
591 0xAF, 0x30, 0x77, 0x17,
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
592 0x87, 0x48, 0xFE, 0x2C,
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
593 0x68, 0x1A, 0xB9, 0xF0
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
594 };
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
595
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
596
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
597 if (strcmp(regname, "KEY\\CLANNAD_FV") == 0) {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
598 SetKey(key2);
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
599 }
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
600 else {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
601 SetKey(key1);
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
602 }
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
603 }
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
604
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
605 const char * KeyHolder::GetKey(void)
35
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
606 {
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
607 return key;
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
608 }
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
609
2c574c3d50a9 * Moved XOR key related things to a proper location
thib
parents: 30
diff changeset
610 /********************************************************
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
611 ** FileSearcher ¥¯¥é¥¹¤Î¼ÂÁõ
0
223b71206888 Initial import
thib
parents:
diff changeset
612 */
223b71206888 Initial import
thib
parents:
diff changeset
613
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
614 FileSearcher* FileSearcher::GetInstance(void) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
615 if (_singleton == NULL) _singleton = new FileSearcher;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
616 return _singleton;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
617 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
618
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
619 void FileSearcher::Quit(void) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
620 if (_singleton != NULL) {
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
621 delete _singleton;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
622 _singleton = NULL;
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
623 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
624 }
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
625
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
626 FileSearcher::FileSearcher(void) {
0
223b71206888 Initial import
thib
parents:
diff changeset
627 int i;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
628 root_dir = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
629 dat_dir = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
630 for (i=0; i<TYPEMAX; i++) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
631 searcher[i] = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
632 filenames[i] = default_dirnames[i];
223b71206888 Initial import
thib
parents:
diff changeset
633 is_archived[i] = default_is_archived[i];
223b71206888 Initial import
thib
parents:
diff changeset
634 }
223b71206888 Initial import
thib
parents:
diff changeset
635 }
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
636
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
637 FileSearcher::~FileSearcher(void) {
0
223b71206888 Initial import
thib
parents:
diff changeset
638 int i;
223b71206888 Initial import
thib
parents:
diff changeset
639 for (i=0; i<TYPEMAX; i++) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
640 if (filenames[i] != NULL && filenames[i] != default_dirnames[i]) delete[] filenames[i];
0
223b71206888 Initial import
thib
parents:
diff changeset
641 if (searcher[i] && searcher[i] != dat_dir && searcher[i] != root_dir) {
223b71206888 Initial import
thib
parents:
diff changeset
642 delete searcher[i];
223b71206888 Initial import
thib
parents:
diff changeset
643 }
223b71206888 Initial import
thib
parents:
diff changeset
644 }
223b71206888 Initial import
thib
parents:
diff changeset
645 if (dat_dir && dat_dir != root_dir) delete dat_dir;
223b71206888 Initial import
thib
parents:
diff changeset
646 if (root_dir) delete root_dir;
223b71206888 Initial import
thib
parents:
diff changeset
647 }
223b71206888 Initial import
thib
parents:
diff changeset
648
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
649 int FileSearcher::InitRoot(char* root) {
0
223b71206888 Initial import
thib
parents:
diff changeset
650 /* ɬÍפ˱þ¤¸¤Æ ~/ ¤òŸ³« */
223b71206888 Initial import
thib
parents:
diff changeset
651 if (root[0] == '~' && root[1] == '/') {
223b71206888 Initial import
thib
parents:
diff changeset
652 char* home = getenv("HOME");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
653 if (home != NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
654 char* new_root = new char[strlen(home)+strlen(root)];
223b71206888 Initial import
thib
parents:
diff changeset
655 strcpy(new_root, home);
223b71206888 Initial import
thib
parents:
diff changeset
656 strcat(new_root, root+1);
223b71206888 Initial import
thib
parents:
diff changeset
657 root = new_root;
223b71206888 Initial import
thib
parents:
diff changeset
658 }
223b71206888 Initial import
thib
parents:
diff changeset
659 }
223b71206888 Initial import
thib
parents:
diff changeset
660 /* ¸Å¤¤¥Ç¡¼¥¿¤ò¾Ã¤¹ */
223b71206888 Initial import
thib
parents:
diff changeset
661 int i;
223b71206888 Initial import
thib
parents:
diff changeset
662 for (i=0; i<TYPEMAX; i++) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
663 if (searcher[i] != NULL &&
0
223b71206888 Initial import
thib
parents:
diff changeset
664 searcher[i] != root_dir &&
223b71206888 Initial import
thib
parents:
diff changeset
665 searcher[i] != dat_dir) {
223b71206888 Initial import
thib
parents:
diff changeset
666 delete searcher[i];
223b71206888 Initial import
thib
parents:
diff changeset
667 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
668 searcher[i] = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
669 }
223b71206888 Initial import
thib
parents:
diff changeset
670 if (dat_dir && root_dir != dat_dir) delete dat_dir;
223b71206888 Initial import
thib
parents:
diff changeset
671 if (root_dir) delete root_dir;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
672 dat_dir = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
673
223b71206888 Initial import
thib
parents:
diff changeset
674 /* ¿·¤·¤¤¥Ç¥£¥ì¥¯¥È¥ê¤Î¤â¤È¤Ç½é´ü²½ */
223b71206888 Initial import
thib
parents:
diff changeset
675 root_dir = new DIRFILE(root);
223b71206888 Initial import
thib
parents:
diff changeset
676 root_dir->Init();
223b71206888 Initial import
thib
parents:
diff changeset
677 /* dat/ ¤ò¸¡º÷ */
223b71206888 Initial import
thib
parents:
diff changeset
678 char* dat_path = root_dir->SearchFile("dat");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
679 if (dat_path == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
680 /* ¸«¤Ä¤«¤é¤Ê¤«¤Ã¤¿¤é root ¤ò dat ¤ÎÂå¤ï¤ê¤Ë¤Ä¤«¤¦ */
223b71206888 Initial import
thib
parents:
diff changeset
681 dat_dir = root_dir;
223b71206888 Initial import
thib
parents:
diff changeset
682 } else {
223b71206888 Initial import
thib
parents:
diff changeset
683 dat_dir = new DIRFILE(dat_path);
9
b6d6c0ffb423 Fixed some memory leaks
thib
parents: 7
diff changeset
684 delete[] dat_path;
0
223b71206888 Initial import
thib
parents:
diff changeset
685 dat_dir->Init();
223b71206888 Initial import
thib
parents:
diff changeset
686 }
223b71206888 Initial import
thib
parents:
diff changeset
687 searcher[ALL] = dat_dir;
223b71206888 Initial import
thib
parents:
diff changeset
688 searcher[ROOT] = root_dir;
223b71206888 Initial import
thib
parents:
diff changeset
689 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
690 }
223b71206888 Initial import
thib
parents:
diff changeset
691
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
692 void FileSearcher::SetFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) {
0
223b71206888 Initial import
thib
parents:
diff changeset
693 int type = tp;
223b71206888 Initial import
thib
parents:
diff changeset
694 if (type < 0 || type >= TYPEMAX) return;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
695 ARCFILE* next_arc = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
696 /* ¤¹¤Ç¤Ë searcher ¤¬Â¸ºß¤¹¤ì¤Ð²òÊü */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
697 if (searcher[type] != NULL &&
0
223b71206888 Initial import
thib
parents:
diff changeset
698 searcher[type] != root_dir &&
223b71206888 Initial import
thib
parents:
diff changeset
699 searcher[type] != dat_dir) {
223b71206888 Initial import
thib
parents:
diff changeset
700 next_arc = searcher[type]->Next();
223b71206888 Initial import
thib
parents:
diff changeset
701 delete searcher[type];
223b71206888 Initial import
thib
parents:
diff changeset
702 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
703 searcher[type] = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
704 /* ŬÅö¤Ë½é´ü²½ */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
705 if (filenames[type] != NULL &&
0
223b71206888 Initial import
thib
parents:
diff changeset
706 filenames[type] != default_dirnames[type]) delete[] filenames[type];
47
5f548e5957a8 * get rid of the "deprecated conversion from string constant to ‘char*’" warnings
thib
parents: 43
diff changeset
707 filenames[type] = filename;
0
223b71206888 Initial import
thib
parents:
diff changeset
708 is_archived[type] = is_arc;
223b71206888 Initial import
thib
parents:
diff changeset
709 searcher[type] = MakeARCFILE(is_arc, filename);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
710 if (searcher[type] != NULL && next_arc)
0
223b71206888 Initial import
thib
parents:
diff changeset
711 searcher[type]->SetNext(next_arc);
223b71206888 Initial import
thib
parents:
diff changeset
712 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
713
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
714 void FileSearcher::AppendFileInformation(FILETYPE tp, ARCTYPE is_arc, char* filename) {
0
223b71206888 Initial import
thib
parents:
diff changeset
715 int type = tp;
223b71206888 Initial import
thib
parents:
diff changeset
716 if (type < 0 || type >= TYPEMAX) return;
223b71206888 Initial import
thib
parents:
diff changeset
717 /* searcher ¤¬¤Þ¤À³ä¤êÅö¤Æ¤é¤ì¤Æ¤Ê¤¤¾ì¹ç */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
718 if (searcher[type] == NULL ||
0
223b71206888 Initial import
thib
parents:
diff changeset
719 searcher[type] == root_dir ||
223b71206888 Initial import
thib
parents:
diff changeset
720 searcher[type] == dat_dir) {
223b71206888 Initial import
thib
parents:
diff changeset
721 searcher[type] = MakeARCFILE(is_archived[type], filenames[type]);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
722 if (searcher[type] == NULL) { /* ºîÀ®¤Ç¤­¤Ê¤«¤Ã¤¿¾ì¹ç */
0
223b71206888 Initial import
thib
parents:
diff changeset
723 /* ¤³¤Î·¿¾ðÊó¤ò FileInformation ¤È¤¹¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
724 SetFileInformation(tp, is_arc, filename);
223b71206888 Initial import
thib
parents:
diff changeset
725 return;
223b71206888 Initial import
thib
parents:
diff changeset
726 }
223b71206888 Initial import
thib
parents:
diff changeset
727 }
223b71206888 Initial import
thib
parents:
diff changeset
728 /* ½é´ü²½ */
223b71206888 Initial import
thib
parents:
diff changeset
729 ARCFILE* arc = MakeARCFILE(is_arc, filename);
223b71206888 Initial import
thib
parents:
diff changeset
730 /* append */
223b71206888 Initial import
thib
parents:
diff changeset
731 ARCFILE* cur;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
732 for (cur=searcher[type]; cur->Next() != NULL; cur = cur->Next()) ;
0
223b71206888 Initial import
thib
parents:
diff changeset
733 cur->SetNext(arc);
223b71206888 Initial import
thib
parents:
diff changeset
734 }
223b71206888 Initial import
thib
parents:
diff changeset
735
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
736 ARCFILE* FileSearcher::MakeARCFILE(ARCTYPE tp, const char* filename) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
737 ARCFILE* arc = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
738 char* file;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
739 if (filename == NULL) goto err;
0
223b71206888 Initial import
thib
parents:
diff changeset
740 if (tp == ATYPE_DIR) {
223b71206888 Initial import
thib
parents:
diff changeset
741 file = root_dir->SearchFile(filename);
223b71206888 Initial import
thib
parents:
diff changeset
742 } else {
223b71206888 Initial import
thib
parents:
diff changeset
743 file = dat_dir->SearchFile(filename);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
744 if (file == NULL)
0
223b71206888 Initial import
thib
parents:
diff changeset
745 file = root_dir->SearchFile(filename);
223b71206888 Initial import
thib
parents:
diff changeset
746 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
747 if (file == NULL) goto err;
0
223b71206888 Initial import
thib
parents:
diff changeset
748 switch(tp) {
223b71206888 Initial import
thib
parents:
diff changeset
749 case ATYPE_DIR: arc = new DIRFILE(file); break;
223b71206888 Initial import
thib
parents:
diff changeset
750 case ATYPE_SCN2k:
223b71206888 Initial import
thib
parents:
diff changeset
751 case ATYPE_ARC: {
223b71206888 Initial import
thib
parents:
diff changeset
752 FILE* f = fopen(file, "rb");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
753 if (f == NULL) goto err;
0
223b71206888 Initial import
thib
parents:
diff changeset
754 char header[32];
223b71206888 Initial import
thib
parents:
diff changeset
755 memset(header, 0, 32);
223b71206888 Initial import
thib
parents:
diff changeset
756 fread(header, 32, 1, f);
223b71206888 Initial import
thib
parents:
diff changeset
757 fclose(f);
223b71206888 Initial import
thib
parents:
diff changeset
758 char magic_raf[8] = {'C','A','P','F',1,0,0,0};
223b71206888 Initial import
thib
parents:
diff changeset
759 if (strncmp(header, "PACL", 4) == 0) arc = new ARCFILE(file);
223b71206888 Initial import
thib
parents:
diff changeset
760 else arc = new SCN2kFILE(file);
223b71206888 Initial import
thib
parents:
diff changeset
761 }
223b71206888 Initial import
thib
parents:
diff changeset
762 break;
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
763 default: fprintf(stderr,"FileSearcher::MAKEARCFILE : invalid archive type; type %d name %s\n",tp,filename);
0
223b71206888 Initial import
thib
parents:
diff changeset
764 delete[] file;
223b71206888 Initial import
thib
parents:
diff changeset
765 goto err;
223b71206888 Initial import
thib
parents:
diff changeset
766 }
223b71206888 Initial import
thib
parents:
diff changeset
767 delete[] file;
223b71206888 Initial import
thib
parents:
diff changeset
768 return arc;
223b71206888 Initial import
thib
parents:
diff changeset
769 err:
223b71206888 Initial import
thib
parents:
diff changeset
770 arc = new NULFILE;
223b71206888 Initial import
thib
parents:
diff changeset
771 return arc;
223b71206888 Initial import
thib
parents:
diff changeset
772 }
223b71206888 Initial import
thib
parents:
diff changeset
773
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
774 ARCINFO* FileSearcher::Find(FILETYPE type, const char* fname, const char* ext) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
775 if (searcher[type] == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
776 /* searcher ºîÀ® */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
777 if (filenames[type] == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
778 searcher[type] = dat_dir;
223b71206888 Initial import
thib
parents:
diff changeset
779 } else {
223b71206888 Initial import
thib
parents:
diff changeset
780 searcher[type] = MakeARCFILE(is_archived[type], filenames[type]);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
781 if (searcher[type] == NULL) {
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
782 fprintf(stderr,"FileSearcher::Find : invalid archive type; type %d name %s\n",type,fname);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
783 return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
784 }
223b71206888 Initial import
thib
parents:
diff changeset
785 }
223b71206888 Initial import
thib
parents:
diff changeset
786 }
223b71206888 Initial import
thib
parents:
diff changeset
787 return searcher[type]->Find(fname,ext);
223b71206888 Initial import
thib
parents:
diff changeset
788 }
223b71206888 Initial import
thib
parents:
diff changeset
789
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
790 char** FileSearcher::ListAll(FILETYPE type) {
0
223b71206888 Initial import
thib
parents:
diff changeset
791 /* ¤È¤ê¤¢¤¨¤º searcher ¤ò½é´ü²½ */
223b71206888 Initial import
thib
parents:
diff changeset
792 Find(type, "THIS FILENAME MAY NOT EXIST IN THE FILE SYSTEM !!!");
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
793 if (searcher[type] == NULL) return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
794 /* Á´¥Õ¥¡¥¤¥ë¤Î¥ê¥¹¥È¥¢¥Ã¥× */
223b71206888 Initial import
thib
parents:
diff changeset
795 int deal = 0;
223b71206888 Initial import
thib
parents:
diff changeset
796 ARCFILE* file;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
797 for (file = searcher[type]; file != NULL; file = file->Next())
0
223b71206888 Initial import
thib
parents:
diff changeset
798 deal += file->Deal();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
799 if (deal <= 0) return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
800 char** ret_list = new char*[deal+1];
223b71206888 Initial import
thib
parents:
diff changeset
801 int count = 0;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
802 for (file = searcher[type]; file != NULL; file = file->Next()) {
0
223b71206888 Initial import
thib
parents:
diff changeset
803 file->InitList();
223b71206888 Initial import
thib
parents:
diff changeset
804 char* f;
223b71206888 Initial import
thib
parents:
diff changeset
805 while( (f = file->ListItem() ) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
806 ret_list[count] = new char[strlen(f)+1];
223b71206888 Initial import
thib
parents:
diff changeset
807 strcpy(ret_list[count], f);
223b71206888 Initial import
thib
parents:
diff changeset
808 count++;
223b71206888 Initial import
thib
parents:
diff changeset
809 }
223b71206888 Initial import
thib
parents:
diff changeset
810 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
811 ret_list[count] = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
812 return ret_list;
223b71206888 Initial import
thib
parents:
diff changeset
813 }
223b71206888 Initial import
thib
parents:
diff changeset
814
223b71206888 Initial import
thib
parents:
diff changeset
815 ARCINFO::ARCINFO(const char* __arcname, ARCFILE_ATOM& atom) : info(atom) {
223b71206888 Initial import
thib
parents:
diff changeset
816 arcfile = new char[strlen(__arcname)+1];
223b71206888 Initial import
thib
parents:
diff changeset
817 strcpy(arcfile, __arcname);
223b71206888 Initial import
thib
parents:
diff changeset
818 use_mmap = false;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
819 mmapped_memory = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
820 data = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
821 fd = -1;
223b71206888 Initial import
thib
parents:
diff changeset
822 }
223b71206888 Initial import
thib
parents:
diff changeset
823
223b71206888 Initial import
thib
parents:
diff changeset
824 ARCINFO::~ARCINFO() {
223b71206888 Initial import
thib
parents:
diff changeset
825 #ifdef HAVE_MMAP
223b71206888 Initial import
thib
parents:
diff changeset
826 if (mmapped_memory) munmap(mmapped_memory, info.arcsize);
223b71206888 Initial import
thib
parents:
diff changeset
827 #endif /* HAVE_MMAP */
223b71206888 Initial import
thib
parents:
diff changeset
828 if (fd != -1) close(fd);
223b71206888 Initial import
thib
parents:
diff changeset
829 if (data != mmapped_memory) delete[] data;
223b71206888 Initial import
thib
parents:
diff changeset
830 delete[] arcfile;
223b71206888 Initial import
thib
parents:
diff changeset
831 }
223b71206888 Initial import
thib
parents:
diff changeset
832
223b71206888 Initial import
thib
parents:
diff changeset
833 int ARCINFO::Size(void) const {
223b71206888 Initial import
thib
parents:
diff changeset
834 return info.filesize;
223b71206888 Initial import
thib
parents:
diff changeset
835 }
223b71206888 Initial import
thib
parents:
diff changeset
836
223b71206888 Initial import
thib
parents:
diff changeset
837 /* ¥³¥Ô¡¼¤òÊÖ¤¹ */
223b71206888 Initial import
thib
parents:
diff changeset
838 char* ARCINFO::CopyRead(void) {
223b71206888 Initial import
thib
parents:
diff changeset
839 const char* d = Read();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
840 if (d == NULL) return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
841 int s = Size();
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
842 if (s <= 0) return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
843 char* ret = new char[s]; memcpy(ret, d, s);
223b71206888 Initial import
thib
parents:
diff changeset
844 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
845 }
223b71206888 Initial import
thib
parents:
diff changeset
846
223b71206888 Initial import
thib
parents:
diff changeset
847 const char* ARCINFO::Path(void) const {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
848 if (info.offset != 0) return NULL; /* archive file ¤Ê¤Î¤Ç¥Ñ¥¹¤òµ¢¤»¤Ê¤¤ */
0
223b71206888 Initial import
thib
parents:
diff changeset
849 char* ret = new char[strlen(arcfile)+1];
223b71206888 Initial import
thib
parents:
diff changeset
850 strcpy(ret, arcfile);
223b71206888 Initial import
thib
parents:
diff changeset
851 return ret;
223b71206888 Initial import
thib
parents:
diff changeset
852 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
853
0
223b71206888 Initial import
thib
parents:
diff changeset
854 /* ¸ß´¹À­ÀìÍÑ */
223b71206888 Initial import
thib
parents:
diff changeset
855 FILE* ARCINFO::OpenFile(int* length) const {
223b71206888 Initial import
thib
parents:
diff changeset
856 FILE* f = fopen(arcfile, "rb");
223b71206888 Initial import
thib
parents:
diff changeset
857 if (info.offset) lseek(fileno(f), info.offset, SEEK_SET);
223b71206888 Initial import
thib
parents:
diff changeset
858 if (length) *length = info.arcsize;
223b71206888 Initial import
thib
parents:
diff changeset
859 return f;
223b71206888 Initial import
thib
parents:
diff changeset
860 }
223b71206888 Initial import
thib
parents:
diff changeset
861
223b71206888 Initial import
thib
parents:
diff changeset
862 // Ÿ³«½èÍý¤Ï¤Ê¤·
223b71206888 Initial import
thib
parents:
diff changeset
863 bool ARCINFO::ExecExtract(void) {
223b71206888 Initial import
thib
parents:
diff changeset
864 return true;
223b71206888 Initial import
thib
parents:
diff changeset
865 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
866
0
223b71206888 Initial import
thib
parents:
diff changeset
867 /* Æɤ߹þ¤ß¤ò³«»Ï¤¹¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
868 const char* ARCINFO::Read(void) {
223b71206888 Initial import
thib
parents:
diff changeset
869 // ¤¹¤Ç¤Ë¥Ç¡¼¥¿¤òÆɤ߹þ¤ßºÑ¤ß¤Ê¤é²¿¤â¤·¤Ê¤¤
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
870 if (data != NULL) return data;
0
223b71206888 Initial import
thib
parents:
diff changeset
871
223b71206888 Initial import
thib
parents:
diff changeset
872 if (info.offset < 0 || info.arcsize <= 0) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
873 return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
874 }
223b71206888 Initial import
thib
parents:
diff changeset
875 /* ¥Õ¥¡¥¤¥ë¤ò³«¤¯ */
223b71206888 Initial import
thib
parents:
diff changeset
876 fd = open(arcfile, O_RDONLY);
223b71206888 Initial import
thib
parents:
diff changeset
877 if (fd < 0) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
878 return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
879 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
880 if (lseek(fd, info.offset, SEEK_SET) != info.offset) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
881 close(fd);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
882 fd = -1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
883 return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
884 }
223b71206888 Initial import
thib
parents:
diff changeset
885 /* mmap ¤ò»î¤ß¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
886 #ifdef HAVE_MMAP
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
887 mmapped_memory = (char*)mmap(NULL, info.arcsize, PROT_READ, MAP_SHARED, fd, info.offset);
0
223b71206888 Initial import
thib
parents:
diff changeset
888 if (mmapped_memory != MAP_FAILED) {
223b71206888 Initial import
thib
parents:
diff changeset
889 use_mmap = true;
223b71206888 Initial import
thib
parents:
diff changeset
890 data = (const char*)mmapped_memory;
223b71206888 Initial import
thib
parents:
diff changeset
891 } else
223b71206888 Initial import
thib
parents:
diff changeset
892 #endif /* HAVE_MMAP */
223b71206888 Initial import
thib
parents:
diff changeset
893 {
223b71206888 Initial import
thib
parents:
diff changeset
894 /* ¼ºÇÔ¡§ÉáÄ̤˥ե¡¥¤¥ë¤òÆɤ߹þ¤ß */
223b71206888 Initial import
thib
parents:
diff changeset
895 char* d = new char[info.arcsize];
223b71206888 Initial import
thib
parents:
diff changeset
896 read(fd, d, info.arcsize);
223b71206888 Initial import
thib
parents:
diff changeset
897 close(fd);
223b71206888 Initial import
thib
parents:
diff changeset
898 fd = -1;
223b71206888 Initial import
thib
parents:
diff changeset
899 use_mmap = false;
223b71206888 Initial import
thib
parents:
diff changeset
900 data = d;
223b71206888 Initial import
thib
parents:
diff changeset
901 }
223b71206888 Initial import
thib
parents:
diff changeset
902 /* Ÿ³«¤¹¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
903 if (! ExecExtract()) {
223b71206888 Initial import
thib
parents:
diff changeset
904 // ¼ºÇÔ
223b71206888 Initial import
thib
parents:
diff changeset
905 #ifdef HAVE_MMAP
223b71206888 Initial import
thib
parents:
diff changeset
906 if (use_mmap) {
223b71206888 Initial import
thib
parents:
diff changeset
907 munmap(mmapped_memory, info.arcsize);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
908 if (data == (const char*)mmapped_memory) data = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
909 }
223b71206888 Initial import
thib
parents:
diff changeset
910 #endif /* HAVE_MMAP */
223b71206888 Initial import
thib
parents:
diff changeset
911 delete[] (char*)data;
223b71206888 Initial import
thib
parents:
diff changeset
912 close(fd);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
913 fd = -1; data = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
914 return NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
915 }
223b71206888 Initial import
thib
parents:
diff changeset
916 #ifdef HAVE_MMAP
223b71206888 Initial import
thib
parents:
diff changeset
917 if (use_mmap && data != (const char*)mmapped_memory) {
223b71206888 Initial import
thib
parents:
diff changeset
918 // ¤¹¤Ç¤Ë mmap ¤ÏɬÍפʤ¤
223b71206888 Initial import
thib
parents:
diff changeset
919 munmap(mmapped_memory, info.arcsize);
223b71206888 Initial import
thib
parents:
diff changeset
920 close(fd);
223b71206888 Initial import
thib
parents:
diff changeset
921 fd = -1;
223b71206888 Initial import
thib
parents:
diff changeset
922 use_mmap = false;
223b71206888 Initial import
thib
parents:
diff changeset
923 }
223b71206888 Initial import
thib
parents:
diff changeset
924 #endif /* HAVE_MMAP */
223b71206888 Initial import
thib
parents:
diff changeset
925 return data;
223b71206888 Initial import
thib
parents:
diff changeset
926 }
223b71206888 Initial import
thib
parents:
diff changeset
927
223b71206888 Initial import
thib
parents:
diff changeset
928 /**********************************************
223b71206888 Initial import
thib
parents:
diff changeset
929 **
223b71206888 Initial import
thib
parents:
diff changeset
930 ** ²èÁüŸ³«·Ï¥¯¥é¥¹¤ÎÄêµÁ¡¢¼ÂÁõ
223b71206888 Initial import
thib
parents:
diff changeset
931 **
223b71206888 Initial import
thib
parents:
diff changeset
932 ***********************************************
223b71206888 Initial import
thib
parents:
diff changeset
933 */
223b71206888 Initial import
thib
parents:
diff changeset
934 GRPCONV::GRPCONV(void) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
935 filename = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
936 data = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
937 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
938
0
223b71206888 Initial import
thib
parents:
diff changeset
939 GRPCONV::~GRPCONV() {
223b71206888 Initial import
thib
parents:
diff changeset
940 if (filename) delete[] filename;
223b71206888 Initial import
thib
parents:
diff changeset
941 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
942
0
223b71206888 Initial import
thib
parents:
diff changeset
943 void GRPCONV::Init(const char* f, const char* d, int dlen, int w, int h, bool is_m) {
223b71206888 Initial import
thib
parents:
diff changeset
944 if (filename) delete[] filename;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
945 if (f == NULL) {
0
223b71206888 Initial import
thib
parents:
diff changeset
946 char* fn = new char[1];
223b71206888 Initial import
thib
parents:
diff changeset
947 fn[0] = 0;
223b71206888 Initial import
thib
parents:
diff changeset
948 filename = fn;
223b71206888 Initial import
thib
parents:
diff changeset
949 } else {
223b71206888 Initial import
thib
parents:
diff changeset
950 char* fn = new char[strlen(f)+1];
223b71206888 Initial import
thib
parents:
diff changeset
951 strcpy(fn,f);
223b71206888 Initial import
thib
parents:
diff changeset
952 filename = fn;
223b71206888 Initial import
thib
parents:
diff changeset
953 }
223b71206888 Initial import
thib
parents:
diff changeset
954
223b71206888 Initial import
thib
parents:
diff changeset
955 data = d;
223b71206888 Initial import
thib
parents:
diff changeset
956 datalen = dlen;
223b71206888 Initial import
thib
parents:
diff changeset
957 width = w;
223b71206888 Initial import
thib
parents:
diff changeset
958 height = h;
223b71206888 Initial import
thib
parents:
diff changeset
959 is_mask = is_m;
223b71206888 Initial import
thib
parents:
diff changeset
960 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
961
0
223b71206888 Initial import
thib
parents:
diff changeset
962 class PDTCONV : public GRPCONV {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
963 private:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
964 bool Read_PDT10(char* image);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
965 bool Read_PDT11(char* image);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
966 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
967 PDTCONV(const char* _inbuf, int inlen, const char* fname);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
968 ~PDTCONV() {}
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
969 bool Read(char* image);
0
223b71206888 Initial import
thib
parents:
diff changeset
970 };
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
971
0
223b71206888 Initial import
thib
parents:
diff changeset
972 class G00CONV : public GRPCONV {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
973 private:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
974 struct REGION {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
975 int x1, y1, x2, y2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
976 int Width() { return x2-x1+1;}
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
977 int Height() { return y2-y1+1;}
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
978 void FixVar(int& v, int& w) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
979 if (v < 0) v = 0;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
980 if (v >= w) v = w-1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
981 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
982 void Fix(int w, int h) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
983 FixVar(x1,w);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
984 FixVar(x2,w);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
985 FixVar(y1,h);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
986 FixVar(y2,h);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
987 if (x1 > x2) x2 = x1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
988 if (y1 > y2) y2 = y1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
989 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
990 };
0
223b71206888 Initial import
thib
parents:
diff changeset
991
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
992 void Copy_16bpp(char* image, int x, int y, const char* src, int bpl, int h);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
993 void Copy_32bpp(char* image, int x, int y, const char* src, int bpl, int h);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
994 bool Read_Type0(char* image);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
995 bool Read_Type1(char* image);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
996 bool Read_Type2(char* image);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
997 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
998 G00CONV(const char* _inbuf, int _inlen, const char* fname);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
999 ~G00CONV() { }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1000 bool Read(char* image);
0
223b71206888 Initial import
thib
parents:
diff changeset
1001 };
223b71206888 Initial import
thib
parents:
diff changeset
1002
223b71206888 Initial import
thib
parents:
diff changeset
1003 class BMPCONV : public GRPCONV {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1004 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1005 BMPCONV(const char* _inbuf, int _inlen, const char* fname);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1006 ~BMPCONV() {};
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1007 bool Read(char* image);
0
223b71206888 Initial import
thib
parents:
diff changeset
1008 };
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1009
0
223b71206888 Initial import
thib
parents:
diff changeset
1010 #if HAVE_LIBPNG
223b71206888 Initial import
thib
parents:
diff changeset
1011 class PNGCONV : public GRPCONV {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1012 private:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1013 const char* png_data;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1014 static void png_read(png_structp, png_bytep, png_size_t);
0
223b71206888 Initial import
thib
parents:
diff changeset
1015
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1016 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1017 PNGCONV(const char* _inbuf, int _inlen, const char* fname);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1018 ~PNGCONV() {};
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1019 bool Read(char* image);
0
223b71206888 Initial import
thib
parents:
diff changeset
1020 };
223b71206888 Initial import
thib
parents:
diff changeset
1021 #endif
223b71206888 Initial import
thib
parents:
diff changeset
1022
223b71206888 Initial import
thib
parents:
diff changeset
1023 #if HAVE_LIBJPEG
223b71206888 Initial import
thib
parents:
diff changeset
1024 class JPEGCONV : public GRPCONV {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1025 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1026 JPEGCONV(const char* _inbuf, int _inlen, const char* fname);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1027 ~JPEGCONV() {};
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1028 bool Read(char* image);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1029 void SetupSrc(struct jpeg_decompress_struct* cinfo, const char* data, int size);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1030 static void init_source(j_decompress_ptr cinfo);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1031 static boolean fill_input_buffer(j_decompress_ptr cinfo);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1032 static void skip_input_data(j_decompress_ptr cinfo, long num_bytes);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1033 static boolean resync_to_restart(j_decompress_ptr cinfo, int desired);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1034 static void term_source(j_decompress_ptr cinf);
0
223b71206888 Initial import
thib
parents:
diff changeset
1035 };
223b71206888 Initial import
thib
parents:
diff changeset
1036 #endif
223b71206888 Initial import
thib
parents:
diff changeset
1037
223b71206888 Initial import
thib
parents:
diff changeset
1038 GRPCONV* GRPCONV::AssignConverter(const char* inbuf, int inlen, const char* fname) {
223b71206888 Initial import
thib
parents:
diff changeset
1039 /* ¥Õ¥¡¥¤¥ë¤ÎÆâÍƤ˱þ¤¸¤¿¥³¥ó¥Ð¡¼¥¿¡¼¤ò³ä¤êÅö¤Æ¤ë */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1040 GRPCONV* conv = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1041 if (inlen < 10) return NULL; /* invalid file */
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 35
diff changeset
1042 if (strncmp(inbuf, "PDT10", 5) == 0 || strncmp(inbuf, "PDT11", 5) == 0) { /* PDT10 or PDT11 */
0
223b71206888 Initial import
thib
parents:
diff changeset
1043 conv = new PDTCONV(inbuf, inlen, fname);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1044 if (conv->data == NULL) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1045 delete conv;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1046 conv = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1047 }
0
223b71206888 Initial import
thib
parents:
diff changeset
1048 }
223b71206888 Initial import
thib
parents:
diff changeset
1049 #if HAVE_LIBPNG
223b71206888 Initial import
thib
parents:
diff changeset
1050 unsigned char png_magic[4] = {0x89, 'P', 'N', 'G'};
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1051 if (conv == NULL && memcmp(inbuf, png_magic,4) == 0) {
0
223b71206888 Initial import
thib
parents:
diff changeset
1052 conv = new PNGCONV(inbuf, inlen, fname);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1053 if (conv->data == NULL) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1054 delete conv;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1055 conv = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1056 }
0
223b71206888 Initial import
thib
parents:
diff changeset
1057 }
223b71206888 Initial import
thib
parents:
diff changeset
1058 #endif
223b71206888 Initial import
thib
parents:
diff changeset
1059 #if HAVE_LIBJPEG
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1060 if ( conv == NULL && *(unsigned char*)inbuf == 0xff && *(unsigned char*)(inbuf+1) == 0xd8 &&
0
223b71206888 Initial import
thib
parents:
diff changeset
1061 (strncmp(inbuf+6, "JFIF",4) == 0 || strncmp(inbuf+6,"Exif",4) == 0)) {
223b71206888 Initial import
thib
parents:
diff changeset
1062 conv = new JPEGCONV(inbuf, inlen, fname);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1063 if (conv->data == NULL) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1064 delete conv;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1065 conv = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1066 }
0
223b71206888 Initial import
thib
parents:
diff changeset
1067 }
223b71206888 Initial import
thib
parents:
diff changeset
1068 #endif
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1069 if (conv == NULL && inbuf[0]=='B' && inbuf[1]=='M' && read_little_endian_int(inbuf+10)==0x36 && read_little_endian_int(inbuf+14) == 0x28) { // Windows BMP
0
223b71206888 Initial import
thib
parents:
diff changeset
1070 conv = new BMPCONV(inbuf, inlen, fname);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1071 if (conv->data == NULL) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1072 delete conv;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1073 conv = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1074 }
0
223b71206888 Initial import
thib
parents:
diff changeset
1075 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1076 if (conv == NULL && (inbuf[0] == 0 || inbuf[0] == 1 || inbuf[0] == 2)) { /* G00 */
0
223b71206888 Initial import
thib
parents:
diff changeset
1077 conv = new G00CONV(inbuf, inlen, fname);
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1078 if (conv->data == NULL) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1079 delete conv;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1080 conv = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1081 }
0
223b71206888 Initial import
thib
parents:
diff changeset
1082 }
223b71206888 Initial import
thib
parents:
diff changeset
1083 return conv;
223b71206888 Initial import
thib
parents:
diff changeset
1084 }
223b71206888 Initial import
thib
parents:
diff changeset
1085
223b71206888 Initial import
thib
parents:
diff changeset
1086 PDTCONV::PDTCONV(const char* _inbuf, int _inlen,const char* filename) {
223b71206888 Initial import
thib
parents:
diff changeset
1087 // PDT FILE ¤Î¥Ø¥Ã¥À
223b71206888 Initial import
thib
parents:
diff changeset
1088 // +00 'PDT10' (PDT11 ¤Ï̤Âбþ)
223b71206888 Initial import
thib
parents:
diff changeset
1089 // +08 ¥Õ¥¡¥¤¥ë¥µ¥¤¥º (̵»ë)
223b71206888 Initial import
thib
parents:
diff changeset
1090 // +0C width (¤Û¤Ü¤¹¤Ù¤Æ¡¢640)
223b71206888 Initial import
thib
parents:
diff changeset
1091 // +10 height(¤Û¤Ü¤¹¤Ù¤Æ¡¢480)
223b71206888 Initial import
thib
parents:
diff changeset
1092 // +14 (mask ¤Î) x ºÂɸ (¼ÂºÝ¤Ï̵»ë¡¦¡¦¡¦Á´¥Õ¥¡¥¤¥ë¤Ç 0 )
223b71206888 Initial import
thib
parents:
diff changeset
1093 // +1c (mask ¤Î) yºÂɸ (¼ÂºÝ¤Ï̵»ë ¡¦¡¦¡¦Á´¥Õ¥¡¥¤¥ë¤Ç 0 )
223b71206888 Initial import
thib
parents:
diff changeset
1094 // +20 mask ¤¬Â¸ºß¤¹¤ì¤Ð¡¢mask ¤Ø¤Î¥Ý¥¤¥ó¥¿
223b71206888 Initial import
thib
parents:
diff changeset
1095
223b71206888 Initial import
thib
parents:
diff changeset
1096 /* ¥Ø¥Ã¥À¥Á¥§¥Ã¥¯ */
223b71206888 Initial import
thib
parents:
diff changeset
1097 if (_inlen < 0x20) {
223b71206888 Initial import
thib
parents:
diff changeset
1098 fprintf(stderr, "Invalid PDT file %s : size is too small\n",filename);
223b71206888 Initial import
thib
parents:
diff changeset
1099 return;
223b71206888 Initial import
thib
parents:
diff changeset
1100 }
223b71206888 Initial import
thib
parents:
diff changeset
1101 if (strncmp(_inbuf, "PDT10", 5) != 0 && strncmp(_inbuf, "PDT11", 5) != 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1102 fprintf(stderr, "Invalid PDT file %s : not 'PDT10 / PDT11' file.\n", filename);
223b71206888 Initial import
thib
parents:
diff changeset
1103 return;
223b71206888 Initial import
thib
parents:
diff changeset
1104 }
223b71206888 Initial import
thib
parents:
diff changeset
1105 if (size_t(_inlen) != size_t(read_little_endian_int(_inbuf+0x08))) {
223b71206888 Initial import
thib
parents:
diff changeset
1106 fprintf(stderr, "Invalid archive file %s : invalid header.(size)\n",
223b71206888 Initial import
thib
parents:
diff changeset
1107 filename);
223b71206888 Initial import
thib
parents:
diff changeset
1108 return;
223b71206888 Initial import
thib
parents:
diff changeset
1109 }
223b71206888 Initial import
thib
parents:
diff changeset
1110
223b71206888 Initial import
thib
parents:
diff changeset
1111 int w = read_little_endian_int(_inbuf+0x0c);
223b71206888 Initial import
thib
parents:
diff changeset
1112 int h = read_little_endian_int(_inbuf+0x10);
223b71206888 Initial import
thib
parents:
diff changeset
1113 int mask_pt = read_little_endian_int(_inbuf + 0x1c);
223b71206888 Initial import
thib
parents:
diff changeset
1114 Init(filename, _inbuf, _inlen, w, h, mask_pt ? true : false);
223b71206888 Initial import
thib
parents:
diff changeset
1115 }
223b71206888 Initial import
thib
parents:
diff changeset
1116
223b71206888 Initial import
thib
parents:
diff changeset
1117
223b71206888 Initial import
thib
parents:
diff changeset
1118 G00CONV::G00CONV(const char* _inbuf, int _inlen, const char* filename) {
223b71206888 Initial import
thib
parents:
diff changeset
1119 // G00 FILE ¤Î¥Ø¥Ã¥À
223b71206888 Initial import
thib
parents:
diff changeset
1120 // +00 type (1, 2)
223b71206888 Initial import
thib
parents:
diff changeset
1121 // +01: width(word)
223b71206888 Initial import
thib
parents:
diff changeset
1122 // +03: height(word)
223b71206888 Initial import
thib
parents:
diff changeset
1123 // type 1: (color table ÉÕ¤­ LZ °µ½Ì ; PDT11 ¤ËÂбþ)
223b71206888 Initial import
thib
parents:
diff changeset
1124 // +05: °µ½Ì¥µ¥¤¥º(dword) ; +5 ¤¹¤ë¤È¥Ç¡¼¥¿Á´ÂΤΥµ¥¤¥º
223b71206888 Initial import
thib
parents:
diff changeset
1125 // +09: Ÿ³«¸å¥µ¥¤¥º(dword)
223b71206888 Initial import
thib
parents:
diff changeset
1126 // type 2: (¥Þ¥¹¥¯²Ä¡¢²èÁü¤ò¶ë·ÁÎΰè¤Ëʬ³ä¤·¤Æ¤½¤ì¤¾¤ì°µ½Ì)
223b71206888 Initial import
thib
parents:
diff changeset
1127 // +05: index size
223b71206888 Initial import
thib
parents:
diff changeset
1128 // +09: index table(each size is 0x18)
223b71206888 Initial import
thib
parents:
diff changeset
1129 // +00
223b71206888 Initial import
thib
parents:
diff changeset
1130 //
223b71206888 Initial import
thib
parents:
diff changeset
1131 // +09+0x18*size+00: data size
223b71206888 Initial import
thib
parents:
diff changeset
1132 // +09+0x18*size+04: out size
223b71206888 Initial import
thib
parents:
diff changeset
1133 // +09+0x18*size+08: (data top)
223b71206888 Initial import
thib
parents:
diff changeset
1134 //
223b71206888 Initial import
thib
parents:
diff changeset
1135
223b71206888 Initial import
thib
parents:
diff changeset
1136 /* ¥Ç¡¼¥¿¤«¤é¾ðÊóÆɤ߹þ¤ß */
223b71206888 Initial import
thib
parents:
diff changeset
1137 int type = *_inbuf;
223b71206888 Initial import
thib
parents:
diff changeset
1138
223b71206888 Initial import
thib
parents:
diff changeset
1139 int w = read_little_endian_short(_inbuf+1);
223b71206888 Initial import
thib
parents:
diff changeset
1140 int h = read_little_endian_short(_inbuf+3);
223b71206888 Initial import
thib
parents:
diff changeset
1141 if (w < 0 || h < 0) return;
223b71206888 Initial import
thib
parents:
diff changeset
1142
223b71206888 Initial import
thib
parents:
diff changeset
1143 if (type == 0 || type == 1) { // color table ÉÕ¤­°µ½Ì
223b71206888 Initial import
thib
parents:
diff changeset
1144 if (_inlen < 13) {
223b71206888 Initial import
thib
parents:
diff changeset
1145 fprintf(stderr, "Invalid G00 file %s : size is too small\n",filename);
223b71206888 Initial import
thib
parents:
diff changeset
1146 return;
223b71206888 Initial import
thib
parents:
diff changeset
1147 }
223b71206888 Initial import
thib
parents:
diff changeset
1148 int data_sz = read_little_endian_int(_inbuf+5);
223b71206888 Initial import
thib
parents:
diff changeset
1149
223b71206888 Initial import
thib
parents:
diff changeset
1150 if (_inlen != data_sz+5) {
223b71206888 Initial import
thib
parents:
diff changeset
1151 fprintf(stderr, "Invalid archive file %s : invalid header.(size)\n",
223b71206888 Initial import
thib
parents:
diff changeset
1152 filename);
223b71206888 Initial import
thib
parents:
diff changeset
1153 return;
223b71206888 Initial import
thib
parents:
diff changeset
1154 }
223b71206888 Initial import
thib
parents:
diff changeset
1155 Init(filename, _inbuf, _inlen, w, h, false);
223b71206888 Initial import
thib
parents:
diff changeset
1156 } else if (type == 2) { // color table ¤Ê¤·¡¢¥Þ¥¹¥¯ÉÕ¤­²Ä¤Î°µ½Ì
223b71206888 Initial import
thib
parents:
diff changeset
1157
223b71206888 Initial import
thib
parents:
diff changeset
1158 int head_size = read_little_endian_short(_inbuf+5);
223b71206888 Initial import
thib
parents:
diff changeset
1159 if (head_size < 0 || head_size*24 > _inlen) return;
223b71206888 Initial import
thib
parents:
diff changeset
1160
223b71206888 Initial import
thib
parents:
diff changeset
1161 const char* data_top = _inbuf + 9 + head_size*24;
223b71206888 Initial import
thib
parents:
diff changeset
1162 int data_sz = read_little_endian_int(data_top);
223b71206888 Initial import
thib
parents:
diff changeset
1163 if (_inbuf + _inlen != data_top + data_sz) {
223b71206888 Initial import
thib
parents:
diff changeset
1164 fprintf(stderr, "Invalid archive file %s : invalid header.(size)\n",
223b71206888 Initial import
thib
parents:
diff changeset
1165 filename);
223b71206888 Initial import
thib
parents:
diff changeset
1166 return;
223b71206888 Initial import
thib
parents:
diff changeset
1167 }
223b71206888 Initial import
thib
parents:
diff changeset
1168 Init(filename, _inbuf, _inlen, w, h, true);
223b71206888 Initial import
thib
parents:
diff changeset
1169 }
223b71206888 Initial import
thib
parents:
diff changeset
1170 return;
223b71206888 Initial import
thib
parents:
diff changeset
1171 }
223b71206888 Initial import
thib
parents:
diff changeset
1172
223b71206888 Initial import
thib
parents:
diff changeset
1173 bool G00CONV::Read(char* image) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1174 if (data == NULL) return false;
0
223b71206888 Initial import
thib
parents:
diff changeset
1175 /* header ¼±ÊÌ */
223b71206888 Initial import
thib
parents:
diff changeset
1176 int type = *data;
223b71206888 Initial import
thib
parents:
diff changeset
1177 if (type == 0) return Read_Type0(image);
223b71206888 Initial import
thib
parents:
diff changeset
1178 else if (type == 1) return Read_Type1(image);
223b71206888 Initial import
thib
parents:
diff changeset
1179 else if (type == 2) return Read_Type2(image);
223b71206888 Initial import
thib
parents:
diff changeset
1180 }
223b71206888 Initial import
thib
parents:
diff changeset
1181
223b71206888 Initial import
thib
parents:
diff changeset
1182 /* °ìÈÌŪ¤Ê LZ °µ½Ì¤ÎŸ³«¥ë¡¼¥Á¥ó */
223b71206888 Initial import
thib
parents:
diff changeset
1183 /* datasize ¤Ï¥Ç¡¼¥¿¤ÎÂ礭¤µ¡¢char / short / int ¤òÁÛÄê */
223b71206888 Initial import
thib
parents:
diff changeset
1184 /* datatype ¤Ï Copy1Pixel (1¥Ç¡¼¥¿¤Î¥³¥Ô¡¼)µÚ¤Ó ExtractData(LZ °µ½Ì¤Î¾ðÊó¤òÆÀ¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1185 ** ¤È¤¤¤¦¥á¥½¥Ã¥É¤ò¼ÂÁõ¤·¤¿¥¯¥é¥¹ */
223b71206888 Initial import
thib
parents:
diff changeset
1186 static int bitrev_table[256] = {
223b71206888 Initial import
thib
parents:
diff changeset
1187 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0, 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
223b71206888 Initial import
thib
parents:
diff changeset
1188 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8, 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
223b71206888 Initial import
thib
parents:
diff changeset
1189 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4, 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
223b71206888 Initial import
thib
parents:
diff changeset
1190 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec, 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
223b71206888 Initial import
thib
parents:
diff changeset
1191 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2, 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
223b71206888 Initial import
thib
parents:
diff changeset
1192 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea, 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
223b71206888 Initial import
thib
parents:
diff changeset
1193 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6, 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
223b71206888 Initial import
thib
parents:
diff changeset
1194 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee, 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
223b71206888 Initial import
thib
parents:
diff changeset
1195 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1, 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
223b71206888 Initial import
thib
parents:
diff changeset
1196 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9, 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
223b71206888 Initial import
thib
parents:
diff changeset
1197 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5, 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
223b71206888 Initial import
thib
parents:
diff changeset
1198 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed, 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
223b71206888 Initial import
thib
parents:
diff changeset
1199 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3, 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
223b71206888 Initial import
thib
parents:
diff changeset
1200 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb, 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
223b71206888 Initial import
thib
parents:
diff changeset
1201 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7, 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
223b71206888 Initial import
thib
parents:
diff changeset
1202 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef, 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff};
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1203
0
223b71206888 Initial import
thib
parents:
diff changeset
1204 template<class DataType, class DataSize> inline int lzExtract(DataType& datatype,const char*& src, char*& dest, const char* srcend, char* destend) {
223b71206888 Initial import
thib
parents:
diff changeset
1205 int count = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1206 const char* lsrcend = srcend; char* ldestend = destend;
223b71206888 Initial import
thib
parents:
diff changeset
1207 const char* lsrc = src; char* ldest = dest;
223b71206888 Initial import
thib
parents:
diff changeset
1208
223b71206888 Initial import
thib
parents:
diff changeset
1209 if (lsrc+50 < lsrcend && ldest+1024 < ldestend) {
223b71206888 Initial import
thib
parents:
diff changeset
1210 /* ¤Þ¤º¡¢ÈÏ°Ï¥Á¥§¥Ã¥¯¤ò´Ë¤¯¤·¤Æ¹â®¤Ê¥ë¡¼¥Á¥ó¤ò»È¤¦ */
223b71206888 Initial import
thib
parents:
diff changeset
1211 lsrcend -= 50;
223b71206888 Initial import
thib
parents:
diff changeset
1212 ldestend += 1024;
223b71206888 Initial import
thib
parents:
diff changeset
1213 while (ldest < ldestend && lsrc < lsrcend) {
223b71206888 Initial import
thib
parents:
diff changeset
1214 count += 8;
223b71206888 Initial import
thib
parents:
diff changeset
1215 int flag = int(*(unsigned char*)lsrc++);
223b71206888 Initial import
thib
parents:
diff changeset
1216 if (datatype.IsRev()) flag = bitrev_table[flag];
223b71206888 Initial import
thib
parents:
diff changeset
1217 int i; for (i=0; i<8; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1218 if (flag & 0x80) {
223b71206888 Initial import
thib
parents:
diff changeset
1219 datatype.Copy1Pixel(lsrc, ldest);
223b71206888 Initial import
thib
parents:
diff changeset
1220 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1221 int data, size;
223b71206888 Initial import
thib
parents:
diff changeset
1222 datatype.ExtractData(lsrc, data, size);
223b71206888 Initial import
thib
parents:
diff changeset
1223 DataSize* p_dest = ((DataSize*)ldest) - data;
223b71206888 Initial import
thib
parents:
diff changeset
1224 int k; for (k=0; k<size; k++) {
223b71206888 Initial import
thib
parents:
diff changeset
1225 p_dest[data] = *p_dest;
223b71206888 Initial import
thib
parents:
diff changeset
1226 p_dest++;
223b71206888 Initial import
thib
parents:
diff changeset
1227 }
223b71206888 Initial import
thib
parents:
diff changeset
1228 ldest += size*sizeof(DataSize);
223b71206888 Initial import
thib
parents:
diff changeset
1229 }
223b71206888 Initial import
thib
parents:
diff changeset
1230 flag <<= 1;
223b71206888 Initial import
thib
parents:
diff changeset
1231 }
223b71206888 Initial import
thib
parents:
diff changeset
1232 }
223b71206888 Initial import
thib
parents:
diff changeset
1233 lsrcend += 50;
223b71206888 Initial import
thib
parents:
diff changeset
1234 ldestend += 1024;
223b71206888 Initial import
thib
parents:
diff changeset
1235 }
223b71206888 Initial import
thib
parents:
diff changeset
1236 /* »Ä¤ê¤òÊÑ´¹ */
223b71206888 Initial import
thib
parents:
diff changeset
1237 while (ldest < ldestend && lsrc < lsrcend) {
223b71206888 Initial import
thib
parents:
diff changeset
1238 count += 8;
223b71206888 Initial import
thib
parents:
diff changeset
1239 int flag = int(*(unsigned char*)lsrc++);
223b71206888 Initial import
thib
parents:
diff changeset
1240 if (datatype.IsRev()) flag = bitrev_table[flag];
223b71206888 Initial import
thib
parents:
diff changeset
1241 int i; for (i=0; i<8 && ldest < ldestend && lsrc < lsrcend; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1242 if (flag & 0x80) {
223b71206888 Initial import
thib
parents:
diff changeset
1243 datatype.Copy1Pixel(lsrc, ldest);
223b71206888 Initial import
thib
parents:
diff changeset
1244 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1245 int data, size;
223b71206888 Initial import
thib
parents:
diff changeset
1246 datatype.ExtractData(lsrc, data, size);
223b71206888 Initial import
thib
parents:
diff changeset
1247 DataSize* p_dest = ((DataSize*)ldest) - data;
223b71206888 Initial import
thib
parents:
diff changeset
1248 int k; for (k=0; k<size; k++) {
223b71206888 Initial import
thib
parents:
diff changeset
1249 p_dest[data] = *p_dest;
223b71206888 Initial import
thib
parents:
diff changeset
1250 p_dest++;
223b71206888 Initial import
thib
parents:
diff changeset
1251 }
223b71206888 Initial import
thib
parents:
diff changeset
1252 ldest += size*sizeof(DataSize);
223b71206888 Initial import
thib
parents:
diff changeset
1253 }
223b71206888 Initial import
thib
parents:
diff changeset
1254 flag <<= 1;
223b71206888 Initial import
thib
parents:
diff changeset
1255 }
223b71206888 Initial import
thib
parents:
diff changeset
1256 }
223b71206888 Initial import
thib
parents:
diff changeset
1257 dest=ldest; src=lsrc;
223b71206888 Initial import
thib
parents:
diff changeset
1258 return 0;
223b71206888 Initial import
thib
parents:
diff changeset
1259 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1260
0
223b71206888 Initial import
thib
parents:
diff changeset
1261 /* °ú¿ô¤ò¸º¤é¤¹¤¿¤á¤Îwrapper */
223b71206888 Initial import
thib
parents:
diff changeset
1262 template<class DataType, class DataSize> inline int lzExtract(DataType datatype, DataSize datasize ,const char*& src, char*& dest, const char* srcend, char* destend) {
223b71206888 Initial import
thib
parents:
diff changeset
1263 return lzExtract<DataType, DataSize>(datatype,src,dest,srcend,destend);
223b71206888 Initial import
thib
parents:
diff changeset
1264 }
223b71206888 Initial import
thib
parents:
diff changeset
1265
223b71206888 Initial import
thib
parents:
diff changeset
1266 /* ÉáÄ̤ΠPDT */
223b71206888 Initial import
thib
parents:
diff changeset
1267 class Extract_DataType {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1268 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1269 static void ExtractData(const char*& lsrc, int& data, int& size) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1270 data = read_little_endian_short(lsrc) & 0xffff;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1271 size = (data & 0x0f) + 1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1272 data = (data>>4)+1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1273 lsrc += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1274 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1275 static void Copy1Pixel(const char*& lsrc, char*& ldest) {
0
223b71206888 Initial import
thib
parents:
diff changeset
1276 #ifdef WORDS_BIGENDIAN
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1277 ldest[3] = lsrc[0];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1278 ldest[2] = lsrc[1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1279 ldest[1] = lsrc[2];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1280 ldest[0] = 0;
0
223b71206888 Initial import
thib
parents:
diff changeset
1281 #else
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1282 *(int*)ldest = read_little_endian_int(lsrc); ldest[3]=0;
0
223b71206888 Initial import
thib
parents:
diff changeset
1283 #endif
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1284 lsrc += 3; ldest += 4;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1285 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1286 static int IsRev(void) { return 0; }
0
223b71206888 Initial import
thib
parents:
diff changeset
1287 };
223b71206888 Initial import
thib
parents:
diff changeset
1288
223b71206888 Initial import
thib
parents:
diff changeset
1289 /* PDT11 ¤ÎÂè°ìÃʳ¬ÊÑ´¹ */
223b71206888 Initial import
thib
parents:
diff changeset
1290 class Extract_DataType_PDT11 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1291 private:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1292 int* index_table;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1293 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1294 Extract_DataType_PDT11(int* it) { index_table = it; }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1295 void ExtractData(const char*& lsrc, int& data, int& size) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1296 data = int(*(const unsigned char*)lsrc);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1297 size = (data>>4) + 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1298 data = index_table[data&0x0f];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1299 lsrc++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1300 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1301 static void Copy1Pixel(const char*& lsrc, char*& ldest) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1302 *ldest = *lsrc;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1303 ldest++; lsrc++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1304 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1305 static int IsRev(void) { return 0; }
0
223b71206888 Initial import
thib
parents:
diff changeset
1306 };
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1307
0
223b71206888 Initial import
thib
parents:
diff changeset
1308 /* ¥Þ¥¹¥¯ÍÑ */
223b71206888 Initial import
thib
parents:
diff changeset
1309 class Extract_DataType_Mask {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1310 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1311 void ExtractData(const char*& lsrc, int& data, int& size) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1312 int d = read_little_endian_short(lsrc) & 0xffff;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1313 size = (d & 0xff) + 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1314 data = (d>>8)+1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1315 lsrc += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1316 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1317 static void Copy1Pixel(const char*& lsrc, char*& ldest) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1318 *ldest = *lsrc;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1319 ldest++; lsrc++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1320 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1321 static int IsRev(void) { return 0; }
0
223b71206888 Initial import
thib
parents:
diff changeset
1322 };
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1323
0
223b71206888 Initial import
thib
parents:
diff changeset
1324 /* ½ñ¸ËÍÑ */
223b71206888 Initial import
thib
parents:
diff changeset
1325 class Extract_DataType_ARC {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1326 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1327 void ExtractData(const char*& lsrc, int& data, int& size) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1328 data = read_little_endian_short(lsrc) & 0xffff;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1329 size = (data&0x0f) + 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1330 data = (data>>4) + 1;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1331 lsrc+= 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1332 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1333 static void Copy1Pixel(const char*& lsrc, char*& ldest) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1334 *ldest = *lsrc;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1335 ldest++; lsrc++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1336 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1337 static int IsRev(void) { return 0; }
0
223b71206888 Initial import
thib
parents:
diff changeset
1338 };
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1339
0
223b71206888 Initial import
thib
parents:
diff changeset
1340 /* avg2000 ¤Î¥·¥Ê¥ê¥ªÍÑ */
223b71206888 Initial import
thib
parents:
diff changeset
1341 class Extract_DataType_SCN2k {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1342 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1343 void ExtractData(const char*& lsrc, int& data, int& size) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1344 data = read_little_endian_short(lsrc) & 0xffff;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1345 size = (data&0x0f) + 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1346 data = (data>>4);
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1347 lsrc+= 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1348 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1349 static void Copy1Pixel(const char*& lsrc, char*& ldest) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1350 *ldest = *lsrc;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1351 ldest++; lsrc++;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1352 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1353 static int IsRev(void) { return 1; }
0
223b71206888 Initial import
thib
parents:
diff changeset
1354 };
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1355
0
223b71206888 Initial import
thib
parents:
diff changeset
1356 /* ReadLive ¤Î type0 */
223b71206888 Initial import
thib
parents:
diff changeset
1357 class Extract_DataType_G00Type0 {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1358 public:
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1359 static void ExtractData(const char*& lsrc, int& data, int& size) {
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1360 data = read_little_endian_short(lsrc) & 0xffff;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1361 size = ((data & 0x0f)+ 1) * 3;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1362 data = (data>>4) * 3;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1363 lsrc += 2;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1364 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1365 static void Copy1Pixel(const char*& lsrc, char*& ldest) {
0
223b71206888 Initial import
thib
parents:
diff changeset
1366 #ifdef WORDS_BIGENDIAN
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1367 ldest[0] = lsrc[0];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1368 ldest[1] = lsrc[1];
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1369 ldest[2] = lsrc[2];
0
223b71206888 Initial import
thib
parents:
diff changeset
1370 #else /* LITTLE ENDIAN / intel architecture */
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1371 *(int*)ldest = *(int*)lsrc;
0
223b71206888 Initial import
thib
parents:
diff changeset
1372 #endif
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1373 lsrc += 3; ldest += 3;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1374 }
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1375 static int IsRev(void) { return 1; }
0
223b71206888 Initial import
thib
parents:
diff changeset
1376 };
223b71206888 Initial import
thib
parents:
diff changeset
1377
223b71206888 Initial import
thib
parents:
diff changeset
1378
223b71206888 Initial import
thib
parents:
diff changeset
1379 bool PDTCONV::Read(char* image) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1380 if (data == NULL) return false;
0
223b71206888 Initial import
thib
parents:
diff changeset
1381
223b71206888 Initial import
thib
parents:
diff changeset
1382 if (strncmp(data, "PDT10", 5) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1383 if (! Read_PDT10(image)) return false;
223b71206888 Initial import
thib
parents:
diff changeset
1384 } else if (strncmp(data, "PDT11", 5) == 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1385 if (! Read_PDT11(image)) return false;
223b71206888 Initial import
thib
parents:
diff changeset
1386 }
223b71206888 Initial import
thib
parents:
diff changeset
1387 if (! is_mask) return true;
223b71206888 Initial import
thib
parents:
diff changeset
1388 // ¥Þ¥¹¥¯Æɤ߹þ¤ß
223b71206888 Initial import
thib
parents:
diff changeset
1389 int mask_pt = read_little_endian_int(data + 0x1c);
223b71206888 Initial import
thib
parents:
diff changeset
1390 char* buf = new char[width*height+1024];
223b71206888 Initial import
thib
parents:
diff changeset
1391 const char* src = data + mask_pt;
223b71206888 Initial import
thib
parents:
diff changeset
1392 const char* srcend = data + datalen;
223b71206888 Initial import
thib
parents:
diff changeset
1393 char* dest = buf;
223b71206888 Initial import
thib
parents:
diff changeset
1394 char* destend = buf + width*height;
223b71206888 Initial import
thib
parents:
diff changeset
1395 while(lzExtract(Extract_DataType_Mask(), char(), src, dest, srcend, destend)) ;
223b71206888 Initial import
thib
parents:
diff changeset
1396 int i; int len = width*height;
223b71206888 Initial import
thib
parents:
diff changeset
1397 src = buf; dest = image;
223b71206888 Initial import
thib
parents:
diff changeset
1398 for (i=0; i<len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1399 *(int*)dest |= int(*(unsigned char*)src) << 24;
223b71206888 Initial import
thib
parents:
diff changeset
1400 src++;
223b71206888 Initial import
thib
parents:
diff changeset
1401 dest += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1402 }
223b71206888 Initial import
thib
parents:
diff changeset
1403 delete[] buf;
223b71206888 Initial import
thib
parents:
diff changeset
1404 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1405 }
223b71206888 Initial import
thib
parents:
diff changeset
1406
223b71206888 Initial import
thib
parents:
diff changeset
1407
223b71206888 Initial import
thib
parents:
diff changeset
1408 bool PDTCONV::Read_PDT10(char* image) {
223b71206888 Initial import
thib
parents:
diff changeset
1409 int mask_pt = read_little_endian_int(data + 0x1c);
223b71206888 Initial import
thib
parents:
diff changeset
1410
223b71206888 Initial import
thib
parents:
diff changeset
1411 const char* src = data + 0x20;
223b71206888 Initial import
thib
parents:
diff changeset
1412 const char* srcend;
223b71206888 Initial import
thib
parents:
diff changeset
1413 if (mask_pt == 0) srcend = data + datalen;
223b71206888 Initial import
thib
parents:
diff changeset
1414 else srcend = data + mask_pt;
223b71206888 Initial import
thib
parents:
diff changeset
1415
223b71206888 Initial import
thib
parents:
diff changeset
1416 char* dest = image;
223b71206888 Initial import
thib
parents:
diff changeset
1417 char* destend;
223b71206888 Initial import
thib
parents:
diff changeset
1418
223b71206888 Initial import
thib
parents:
diff changeset
1419 destend = image + width*height*4;
223b71206888 Initial import
thib
parents:
diff changeset
1420 while(lzExtract(Extract_DataType(), int(), src, dest, srcend, destend)) ;
223b71206888 Initial import
thib
parents:
diff changeset
1421 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1422 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1423
0
223b71206888 Initial import
thib
parents:
diff changeset
1424 bool PDTCONV::Read_PDT11(char* image) {
223b71206888 Initial import
thib
parents:
diff changeset
1425 int index_table[16];
223b71206888 Initial import
thib
parents:
diff changeset
1426 int color_table[256];
223b71206888 Initial import
thib
parents:
diff changeset
1427 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1428 for (i=0; i<16; i++)
223b71206888 Initial import
thib
parents:
diff changeset
1429 index_table[i] = read_little_endian_int(data + 0x420 + i*4);
223b71206888 Initial import
thib
parents:
diff changeset
1430
223b71206888 Initial import
thib
parents:
diff changeset
1431 int mask_pt = read_little_endian_int(data + 0x1c);
223b71206888 Initial import
thib
parents:
diff changeset
1432
223b71206888 Initial import
thib
parents:
diff changeset
1433 const char* src = data + 0x460;
223b71206888 Initial import
thib
parents:
diff changeset
1434 const char* srcend;
223b71206888 Initial import
thib
parents:
diff changeset
1435 if (mask_pt == 0) srcend = data + datalen;
223b71206888 Initial import
thib
parents:
diff changeset
1436 else srcend = data + mask_pt;
223b71206888 Initial import
thib
parents:
diff changeset
1437
223b71206888 Initial import
thib
parents:
diff changeset
1438 char* dest = image;
223b71206888 Initial import
thib
parents:
diff changeset
1439 char* destend = image + width*height;
223b71206888 Initial import
thib
parents:
diff changeset
1440
223b71206888 Initial import
thib
parents:
diff changeset
1441 while(lzExtract(Extract_DataType_PDT11(index_table), char(), src, dest, srcend, destend)) ;
223b71206888 Initial import
thib
parents:
diff changeset
1442
223b71206888 Initial import
thib
parents:
diff changeset
1443 const char* cur = data + 0x20;
223b71206888 Initial import
thib
parents:
diff changeset
1444 for (i=0; i<256; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1445 color_table[i] = read_little_endian_int(cur);
223b71206888 Initial import
thib
parents:
diff changeset
1446 cur += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1447 }
223b71206888 Initial import
thib
parents:
diff changeset
1448 src = image + width*height;
223b71206888 Initial import
thib
parents:
diff changeset
1449 int* desti = (int*)(image + width*height*4);
223b71206888 Initial import
thib
parents:
diff changeset
1450 while(desti != (int*)image)
223b71206888 Initial import
thib
parents:
diff changeset
1451 *--desti = color_table[*(unsigned char*)--src];
223b71206888 Initial import
thib
parents:
diff changeset
1452 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1453 }
223b71206888 Initial import
thib
parents:
diff changeset
1454
223b71206888 Initial import
thib
parents:
diff changeset
1455 /* dest ¤Ï dest_end ¤è¤ê¤â 256 byte °Ê¾åÀè¤Þ¤Ç
223b71206888 Initial import
thib
parents:
diff changeset
1456 ** ½ñ¤­¹þ¤ß²Äǽ¤Ç¤¢¤ë¤³¤È¡£
223b71206888 Initial import
thib
parents:
diff changeset
1457 */
223b71206888 Initial import
thib
parents:
diff changeset
1458 void ARCINFO::Extract(char*& dest_start, char*& src_start, char* dest_end, char* src_end) {
223b71206888 Initial import
thib
parents:
diff changeset
1459 const char* src = src_start;
223b71206888 Initial import
thib
parents:
diff changeset
1460 while (lzExtract(Extract_DataType_ARC(), char(), src, dest_start, src_end, dest_end)) ;
223b71206888 Initial import
thib
parents:
diff changeset
1461 src_start = (char*)src;
223b71206888 Initial import
thib
parents:
diff changeset
1462 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1463
0
223b71206888 Initial import
thib
parents:
diff changeset
1464 void ARCINFO::Extract2k(char*& dest_start, char*& src_start, char* dest_end, char* src_end) {
223b71206888 Initial import
thib
parents:
diff changeset
1465 const char* src = src_start;
223b71206888 Initial import
thib
parents:
diff changeset
1466 while (lzExtract(Extract_DataType_SCN2k(), char(), src, dest_start, src_end, dest_end)) ;
223b71206888 Initial import
thib
parents:
diff changeset
1467 src_start = (char*)src;
223b71206888 Initial import
thib
parents:
diff changeset
1468 }
223b71206888 Initial import
thib
parents:
diff changeset
1469
223b71206888 Initial import
thib
parents:
diff changeset
1470 bool ARCINFO_AVG32::ExecExtract(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1471 // ¥Ø¥Ã¥À¤Î¥Á¥§¥Ã¥¯
223b71206888 Initial import
thib
parents:
diff changeset
1472 if (strncmp(data, "PACK", 4) != 0) return false;
223b71206888 Initial import
thib
parents:
diff changeset
1473 if (read_little_endian_int(data+8) != info.filesize) return false;
223b71206888 Initial import
thib
parents:
diff changeset
1474 if (read_little_endian_int(data+12) != info.arcsize) return false;
223b71206888 Initial import
thib
parents:
diff changeset
1475
223b71206888 Initial import
thib
parents:
diff changeset
1476 // ¥Õ¥¡¥¤¥ë¤òŸ³«¤¹¤ë
223b71206888 Initial import
thib
parents:
diff changeset
1477 char* ret_data = new char[info.filesize+1024];
223b71206888 Initial import
thib
parents:
diff changeset
1478
223b71206888 Initial import
thib
parents:
diff changeset
1479 const char* s = data + 0x10;
223b71206888 Initial import
thib
parents:
diff changeset
1480 const char* send = data + info.arcsize;
223b71206888 Initial import
thib
parents:
diff changeset
1481 char* d = ret_data;
223b71206888 Initial import
thib
parents:
diff changeset
1482 char* dend = ret_data + info.filesize;
223b71206888 Initial import
thib
parents:
diff changeset
1483 while(lzExtract(Extract_DataType_ARC(), char(), s, d, send, dend)) ;
223b71206888 Initial import
thib
parents:
diff changeset
1484 if (! use_mmap) delete[] data;
223b71206888 Initial import
thib
parents:
diff changeset
1485 data = ret_data;
223b71206888 Initial import
thib
parents:
diff changeset
1486 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1487 }
223b71206888 Initial import
thib
parents:
diff changeset
1488
223b71206888 Initial import
thib
parents:
diff changeset
1489 char ARCINFO2k::decode_seed[256] ={
223b71206888 Initial import
thib
parents:
diff changeset
1490 0x8b ,0xe5 ,0x5d ,0xc3 ,0xa1 ,0xe0 ,0x30 ,0x44 ,0x00 ,0x85 ,0xc0 ,0x74 ,0x09 ,0x5f ,0x5e ,0x33
223b71206888 Initial import
thib
parents:
diff changeset
1491 ,0xc0 ,0x5b ,0x8b ,0xe5 ,0x5d ,0xc3 ,0x8b ,0x45 ,0x0c ,0x85 ,0xc0 ,0x75 ,0x14 ,0x8b ,0x55 ,0xec
223b71206888 Initial import
thib
parents:
diff changeset
1492 ,0x83 ,0xc2 ,0x20 ,0x52 ,0x6a ,0x00 ,0xe8 ,0xf5 ,0x28 ,0x01 ,0x00 ,0x83 ,0xc4 ,0x08 ,0x89 ,0x45
223b71206888 Initial import
thib
parents:
diff changeset
1493 ,0x0c ,0x8b ,0x45 ,0xe4 ,0x6a ,0x00 ,0x6a ,0x00 ,0x50 ,0x53 ,0xff ,0x15 ,0x34 ,0xb1 ,0x43 ,0x00
223b71206888 Initial import
thib
parents:
diff changeset
1494 ,0x8b ,0x45 ,0x10 ,0x85 ,0xc0 ,0x74 ,0x05 ,0x8b ,0x4d ,0xec ,0x89 ,0x08 ,0x8a ,0x45 ,0xf0 ,0x84
223b71206888 Initial import
thib
parents:
diff changeset
1495 ,0xc0 ,0x75 ,0x78 ,0xa1 ,0xe0 ,0x30 ,0x44 ,0x00 ,0x8b ,0x7d ,0xe8 ,0x8b ,0x75 ,0x0c ,0x85 ,0xc0
223b71206888 Initial import
thib
parents:
diff changeset
1496 ,0x75 ,0x44 ,0x8b ,0x1d ,0xd0 ,0xb0 ,0x43 ,0x00 ,0x85 ,0xff ,0x76 ,0x37 ,0x81 ,0xff ,0x00 ,0x00
223b71206888 Initial import
thib
parents:
diff changeset
1497 ,0x04 ,0x00 ,0x6a ,0x00 ,0x76 ,0x43 ,0x8b ,0x45 ,0xf8 ,0x8d ,0x55 ,0xfc ,0x52 ,0x68 ,0x00 ,0x00
223b71206888 Initial import
thib
parents:
diff changeset
1498 ,0x04 ,0x00 ,0x56 ,0x50 ,0xff ,0x15 ,0x2c ,0xb1 ,0x43 ,0x00 ,0x6a ,0x05 ,0xff ,0xd3 ,0xa1 ,0xe0
223b71206888 Initial import
thib
parents:
diff changeset
1499 ,0x30 ,0x44 ,0x00 ,0x81 ,0xef ,0x00 ,0x00 ,0x04 ,0x00 ,0x81 ,0xc6 ,0x00 ,0x00 ,0x04 ,0x00 ,0x85
223b71206888 Initial import
thib
parents:
diff changeset
1500 ,0xc0 ,0x74 ,0xc5 ,0x8b ,0x5d ,0xf8 ,0x53 ,0xe8 ,0xf4 ,0xfb ,0xff ,0xff ,0x8b ,0x45 ,0x0c ,0x83
223b71206888 Initial import
thib
parents:
diff changeset
1501 ,0xc4 ,0x04 ,0x5f ,0x5e ,0x5b ,0x8b ,0xe5 ,0x5d ,0xc3 ,0x8b ,0x55 ,0xf8 ,0x8d ,0x4d ,0xfc ,0x51
223b71206888 Initial import
thib
parents:
diff changeset
1502 ,0x57 ,0x56 ,0x52 ,0xff ,0x15 ,0x2c ,0xb1 ,0x43 ,0x00 ,0xeb ,0xd8 ,0x8b ,0x45 ,0xe8 ,0x83 ,0xc0
223b71206888 Initial import
thib
parents:
diff changeset
1503 ,0x20 ,0x50 ,0x6a ,0x00 ,0xe8 ,0x47 ,0x28 ,0x01 ,0x00 ,0x8b ,0x7d ,0xe8 ,0x89 ,0x45 ,0xf4 ,0x8b
223b71206888 Initial import
thib
parents:
diff changeset
1504 ,0xf0 ,0xa1 ,0xe0 ,0x30 ,0x44 ,0x00 ,0x83 ,0xc4 ,0x08 ,0x85 ,0xc0 ,0x75 ,0x56 ,0x8b ,0x1d ,0xd0
223b71206888 Initial import
thib
parents:
diff changeset
1505 ,0xb0 ,0x43 ,0x00 ,0x85 ,0xff ,0x76 ,0x49 ,0x81 ,0xff ,0x00 ,0x00 ,0x04 ,0x00 ,0x6a ,0x00 ,0x76};
30
3fe3e5f184b5 * Added CLANNAD Full Voice's key
thib
parents: 27
diff changeset
1506
0
223b71206888 Initial import
thib
parents:
diff changeset
1507
223b71206888 Initial import
thib
parents:
diff changeset
1508 bool ARCINFO2k::ExecExtract(void) {
223b71206888 Initial import
thib
parents:
diff changeset
1509 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1510 char* ret_data = new char[info.filesize + 1024];
223b71206888 Initial import
thib
parents:
diff changeset
1511 char* decoded_data = new char[info.arcsize + 1024];
223b71206888 Initial import
thib
parents:
diff changeset
1512
223b71206888 Initial import
thib
parents:
diff changeset
1513 /* header ¤Î¥³¥Ô¡¼ */
223b71206888 Initial import
thib
parents:
diff changeset
1514 memcpy(ret_data, data, info.private_data);
223b71206888 Initial import
thib
parents:
diff changeset
1515
223b71206888 Initial import
thib
parents:
diff changeset
1516 /* ¤Þ¤º¡¢xor ¤Î°Å¹æ²½¤ò²ò¤¯ */
223b71206888 Initial import
thib
parents:
diff changeset
1517 const char* s; const char* send;
223b71206888 Initial import
thib
parents:
diff changeset
1518 char* d; char* dend;
223b71206888 Initial import
thib
parents:
diff changeset
1519
223b71206888 Initial import
thib
parents:
diff changeset
1520 s = data + info.private_data;
223b71206888 Initial import
thib
parents:
diff changeset
1521 send = data + info.arcsize;
223b71206888 Initial import
thib
parents:
diff changeset
1522 d = decoded_data + info.private_data;
223b71206888 Initial import
thib
parents:
diff changeset
1523 dend = decoded_data + info.arcsize;
223b71206888 Initial import
thib
parents:
diff changeset
1524 i = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1525 while(s != send)
223b71206888 Initial import
thib
parents:
diff changeset
1526 *d++ = *s++ ^ decode_seed[(i++)&0xff];
223b71206888 Initial import
thib
parents:
diff changeset
1527
223b71206888 Initial import
thib
parents:
diff changeset
1528 if (info.filesize == info.arcsize) {
223b71206888 Initial import
thib
parents:
diff changeset
1529 memcpy(ret_data+info.private_data, decoded_data + info.private_data + 8, info.arcsize - info.private_data - 8);
223b71206888 Initial import
thib
parents:
diff changeset
1530 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1531 /* °µ½Ì¤µ¤ì¤Æ¤¤¤ë¤Ê¤é¡¢¤½¤ì¤òŸ³« */
223b71206888 Initial import
thib
parents:
diff changeset
1532 s = (const char*)(decoded_data + info.private_data + 8);
223b71206888 Initial import
thib
parents:
diff changeset
1533 send = (const char*)(decoded_data + info.arcsize);
223b71206888 Initial import
thib
parents:
diff changeset
1534 d = ret_data + info.private_data;
223b71206888 Initial import
thib
parents:
diff changeset
1535 dend = ret_data + info.filesize;
223b71206888 Initial import
thib
parents:
diff changeset
1536 while(lzExtract(Extract_DataType_SCN2k(), char(), s, d, send, dend)) ;
223b71206888 Initial import
thib
parents:
diff changeset
1537 }
223b71206888 Initial import
thib
parents:
diff changeset
1538 if (read_little_endian_int(data+4) == 0x1adb2) { // Little Busters!
53
ddbcbd000206 * MuSys, AyuSysConfig, FileSearcher (former FILESEARCHER) and KeyHolder (former KEYHOLDER) are now singletons
thib
parents: 52
diff changeset
1539 const char *decode_key = KeyHolder::GetInstance()->GetKey();
0
223b71206888 Initial import
thib
parents:
diff changeset
1540 int header_size = info.private_data;
223b71206888 Initial import
thib
parents:
diff changeset
1541 for (i=0x100; i<=0x200 && header_size+i < info.filesize; i++) {
30
3fe3e5f184b5 * Added CLANNAD Full Voice's key
thib
parents: 27
diff changeset
1542 ret_data[header_size+i] ^= decode_key[i&0x0f];
0
223b71206888 Initial import
thib
parents:
diff changeset
1543 }
223b71206888 Initial import
thib
parents:
diff changeset
1544 }
223b71206888 Initial import
thib
parents:
diff changeset
1545 delete[] decoded_data;
223b71206888 Initial import
thib
parents:
diff changeset
1546 if (! use_mmap) delete[] data;
223b71206888 Initial import
thib
parents:
diff changeset
1547 data = ret_data;
223b71206888 Initial import
thib
parents:
diff changeset
1548 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1549 }
223b71206888 Initial import
thib
parents:
diff changeset
1550
223b71206888 Initial import
thib
parents:
diff changeset
1551 bool G00CONV::Read_Type0(char* image) {
223b71206888 Initial import
thib
parents:
diff changeset
1552 int uncompress_size = read_little_endian_int(data+9);
223b71206888 Initial import
thib
parents:
diff changeset
1553 char* uncompress_data = new char[uncompress_size+1024];
223b71206888 Initial import
thib
parents:
diff changeset
1554
223b71206888 Initial import
thib
parents:
diff changeset
1555 // ¤Þ¤ºÅ¸³«
223b71206888 Initial import
thib
parents:
diff changeset
1556 const char* src = data + 13;
223b71206888 Initial import
thib
parents:
diff changeset
1557 const char* srcend = data + datalen;
223b71206888 Initial import
thib
parents:
diff changeset
1558 char* dest = uncompress_data;
223b71206888 Initial import
thib
parents:
diff changeset
1559 char* dstend = uncompress_data + uncompress_size;
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 35
diff changeset
1560 while(lzExtract(Extract_DataType_G00Type0(), char(), src, dest, srcend, dstend)){};
0
223b71206888 Initial import
thib
parents:
diff changeset
1561 // image ¤Ë¥³¥Ô¡¼
223b71206888 Initial import
thib
parents:
diff changeset
1562 CopyRGB(image, uncompress_data);
223b71206888 Initial import
thib
parents:
diff changeset
1563 delete[] uncompress_data;
223b71206888 Initial import
thib
parents:
diff changeset
1564 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1565 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1566
0
223b71206888 Initial import
thib
parents:
diff changeset
1567 bool G00CONV::Read_Type1(char* image) {
223b71206888 Initial import
thib
parents:
diff changeset
1568 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1569 int uncompress_size = read_little_endian_int(data+9) + 1;
223b71206888 Initial import
thib
parents:
diff changeset
1570 char* uncompress_data = new char[uncompress_size + 1024];
223b71206888 Initial import
thib
parents:
diff changeset
1571
223b71206888 Initial import
thib
parents:
diff changeset
1572 // ¤Þ¤º¡¢Å¸³«
223b71206888 Initial import
thib
parents:
diff changeset
1573 const char* src = data + 13;
223b71206888 Initial import
thib
parents:
diff changeset
1574 const char* srcend = data + datalen;
223b71206888 Initial import
thib
parents:
diff changeset
1575 char* dest = uncompress_data;
223b71206888 Initial import
thib
parents:
diff changeset
1576 char* destend = uncompress_data + uncompress_size;
223b71206888 Initial import
thib
parents:
diff changeset
1577
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 35
diff changeset
1578 while(lzExtract(Extract_DataType_SCN2k(), char(), src, dest, srcend, destend)){};
0
223b71206888 Initial import
thib
parents:
diff changeset
1579
223b71206888 Initial import
thib
parents:
diff changeset
1580 int colortable[256];
223b71206888 Initial import
thib
parents:
diff changeset
1581 memset(colortable, 0, sizeof(int)*256);
223b71206888 Initial import
thib
parents:
diff changeset
1582 int colortable_len = read_little_endian_short(uncompress_data);
223b71206888 Initial import
thib
parents:
diff changeset
1583 if (colortable_len > 256) colortable_len = 256;
223b71206888 Initial import
thib
parents:
diff changeset
1584 if (colortable_len < 0) colortable_len = 0;
223b71206888 Initial import
thib
parents:
diff changeset
1585 for (i=0; i<colortable_len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1586 colortable[i] = read_little_endian_int(uncompress_data+2+i*4);
223b71206888 Initial import
thib
parents:
diff changeset
1587 }
223b71206888 Initial import
thib
parents:
diff changeset
1588 src = uncompress_data + 2 + read_little_endian_short(uncompress_data)*4;
223b71206888 Initial import
thib
parents:
diff changeset
1589 srcend = uncompress_data + uncompress_size;
223b71206888 Initial import
thib
parents:
diff changeset
1590 dest = image; destend = image + width*height*4;
223b71206888 Initial import
thib
parents:
diff changeset
1591 while(dest < destend && src < srcend) {
223b71206888 Initial import
thib
parents:
diff changeset
1592 *(int*)dest = colortable[*(unsigned char*)src];
223b71206888 Initial import
thib
parents:
diff changeset
1593 dest += 4; src ++;
223b71206888 Initial import
thib
parents:
diff changeset
1594 }
223b71206888 Initial import
thib
parents:
diff changeset
1595 delete[] uncompress_data;
223b71206888 Initial import
thib
parents:
diff changeset
1596 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1597 }
223b71206888 Initial import
thib
parents:
diff changeset
1598
223b71206888 Initial import
thib
parents:
diff changeset
1599 bool G00CONV::Read_Type2(char* image) {
223b71206888 Initial import
thib
parents:
diff changeset
1600 memset(image, 0, width*height*4);
223b71206888 Initial import
thib
parents:
diff changeset
1601 /* ʬ³äÎΰè¤òÆÀ¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
1602 int region_deal = read_little_endian_int(data+5);
223b71206888 Initial import
thib
parents:
diff changeset
1603 REGION* region_table = new REGION[region_deal];
223b71206888 Initial import
thib
parents:
diff changeset
1604
223b71206888 Initial import
thib
parents:
diff changeset
1605 const char* head = data + 9;
223b71206888 Initial import
thib
parents:
diff changeset
1606 int i; for (i=0; i<region_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1607 region_table[i].x1 = read_little_endian_int(head+0);
223b71206888 Initial import
thib
parents:
diff changeset
1608 region_table[i].y1 = read_little_endian_int(head+4);
223b71206888 Initial import
thib
parents:
diff changeset
1609 region_table[i].x2 = read_little_endian_int(head+8);
223b71206888 Initial import
thib
parents:
diff changeset
1610 region_table[i].y2 = read_little_endian_int(head+12);
223b71206888 Initial import
thib
parents:
diff changeset
1611 region_table[i].Fix(width, height);
223b71206888 Initial import
thib
parents:
diff changeset
1612 head += 24;
223b71206888 Initial import
thib
parents:
diff changeset
1613 }
223b71206888 Initial import
thib
parents:
diff changeset
1614
223b71206888 Initial import
thib
parents:
diff changeset
1615 // Ÿ³«
223b71206888 Initial import
thib
parents:
diff changeset
1616 int uncompress_size = read_little_endian_int(head+4);
223b71206888 Initial import
thib
parents:
diff changeset
1617 char* uncompress_data = new char[uncompress_size + 1024];
223b71206888 Initial import
thib
parents:
diff changeset
1618
223b71206888 Initial import
thib
parents:
diff changeset
1619 const char* src = head + 8;
223b71206888 Initial import
thib
parents:
diff changeset
1620 const char* srcend = data + datalen;
223b71206888 Initial import
thib
parents:
diff changeset
1621 char* dest = uncompress_data;
223b71206888 Initial import
thib
parents:
diff changeset
1622 char* destend = uncompress_data + uncompress_size;
43
01aa5ddf7dc8 A lot of very minor improvements (deleted some unused variables, and other things like that...)
thib
parents: 35
diff changeset
1623 while(lzExtract(Extract_DataType_SCN2k(), char(), src, dest, srcend, destend)){};
0
223b71206888 Initial import
thib
parents:
diff changeset
1624
223b71206888 Initial import
thib
parents:
diff changeset
1625 /* region_deal2 == region_deal ¤Î¤Ï¤º¡Ä¡Ä*/
223b71206888 Initial import
thib
parents:
diff changeset
1626 int region_deal2 = read_little_endian_int(uncompress_data);
223b71206888 Initial import
thib
parents:
diff changeset
1627 if (region_deal > region_deal2) region_deal = region_deal2;
223b71206888 Initial import
thib
parents:
diff changeset
1628
223b71206888 Initial import
thib
parents:
diff changeset
1629 for (i=0; i < region_deal; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1630 int offset = read_little_endian_int(uncompress_data + i*8 + 4);
223b71206888 Initial import
thib
parents:
diff changeset
1631 int length = read_little_endian_int(uncompress_data + i*8 + 8);
223b71206888 Initial import
thib
parents:
diff changeset
1632 src = (const char*)(uncompress_data + offset + 0x74);
223b71206888 Initial import
thib
parents:
diff changeset
1633 srcend = (const char*)(uncompress_data + offset + length);
223b71206888 Initial import
thib
parents:
diff changeset
1634 while(src < srcend) {
223b71206888 Initial import
thib
parents:
diff changeset
1635 int x, y, w, h;
223b71206888 Initial import
thib
parents:
diff changeset
1636 /* ¥³¥Ô¡¼¤¹¤ëÎΰè¤òÆÀ¤ë */
223b71206888 Initial import
thib
parents:
diff changeset
1637 x = read_little_endian_short(src);
223b71206888 Initial import
thib
parents:
diff changeset
1638 y = read_little_endian_short(src+2);
223b71206888 Initial import
thib
parents:
diff changeset
1639 w = read_little_endian_short(src+6);
223b71206888 Initial import
thib
parents:
diff changeset
1640 h = read_little_endian_short(src+8);
223b71206888 Initial import
thib
parents:
diff changeset
1641 src += 0x5c;
223b71206888 Initial import
thib
parents:
diff changeset
1642
223b71206888 Initial import
thib
parents:
diff changeset
1643 x += region_table[i].x1;
223b71206888 Initial import
thib
parents:
diff changeset
1644 y += region_table[i].y1;
223b71206888 Initial import
thib
parents:
diff changeset
1645
223b71206888 Initial import
thib
parents:
diff changeset
1646 Copy_32bpp(image, x, y, src, w*4, h);
223b71206888 Initial import
thib
parents:
diff changeset
1647
223b71206888 Initial import
thib
parents:
diff changeset
1648 src += w*h*4;
223b71206888 Initial import
thib
parents:
diff changeset
1649 }
223b71206888 Initial import
thib
parents:
diff changeset
1650 }
223b71206888 Initial import
thib
parents:
diff changeset
1651 delete[] uncompress_data;
7
fa8511a21d05 Fixes somes memory leaks
thib
parents: 0
diff changeset
1652 delete[] region_table;
0
223b71206888 Initial import
thib
parents:
diff changeset
1653 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1654 }
223b71206888 Initial import
thib
parents:
diff changeset
1655
223b71206888 Initial import
thib
parents:
diff changeset
1656 void G00CONV::Copy_32bpp(char* image, int x, int y, const char* src, int bpl, int h) {
223b71206888 Initial import
thib
parents:
diff changeset
1657 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1658 int* dest = (int*)(image + x*4 + y*4*width);
223b71206888 Initial import
thib
parents:
diff changeset
1659 int w = bpl / 4;
223b71206888 Initial import
thib
parents:
diff changeset
1660 for (i=0; i<h; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1661 const char* s = src;
223b71206888 Initial import
thib
parents:
diff changeset
1662 int* d = dest;
223b71206888 Initial import
thib
parents:
diff changeset
1663 int j; for (j=0; j<w; j++) {
223b71206888 Initial import
thib
parents:
diff changeset
1664 *d++ = read_little_endian_int(s);
223b71206888 Initial import
thib
parents:
diff changeset
1665 s += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1666 }
223b71206888 Initial import
thib
parents:
diff changeset
1667 src += bpl; dest += width;
223b71206888 Initial import
thib
parents:
diff changeset
1668 }
223b71206888 Initial import
thib
parents:
diff changeset
1669 }
223b71206888 Initial import
thib
parents:
diff changeset
1670
223b71206888 Initial import
thib
parents:
diff changeset
1671 void GRPCONV::CopyRGBA_rev(char* image, const char* buf) {
223b71206888 Initial import
thib
parents:
diff changeset
1672 int mask = is_mask ? 0 : 0xff000000;
223b71206888 Initial import
thib
parents:
diff changeset
1673 /* ¿§ÊÑ´¹¤ò¹Ô¤¦ */
223b71206888 Initial import
thib
parents:
diff changeset
1674 int len = width * height;
223b71206888 Initial import
thib
parents:
diff changeset
1675 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1676 unsigned char* s = (unsigned char*)buf;
223b71206888 Initial import
thib
parents:
diff changeset
1677 int* d = (int*)image;
223b71206888 Initial import
thib
parents:
diff changeset
1678 for(i=0; i<len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1679 *d = (int(s[2])) | (int(s[1])<<8) | (int(s[0])<<16) | (int(s[3])<<24) | mask;
223b71206888 Initial import
thib
parents:
diff changeset
1680 d++; s += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1681 }
223b71206888 Initial import
thib
parents:
diff changeset
1682 }
223b71206888 Initial import
thib
parents:
diff changeset
1683
223b71206888 Initial import
thib
parents:
diff changeset
1684 void GRPCONV::CopyRGBA(char* image, const char* buf) {
223b71206888 Initial import
thib
parents:
diff changeset
1685 if (!is_mask) {
223b71206888 Initial import
thib
parents:
diff changeset
1686 CopyRGB(image, buf);
223b71206888 Initial import
thib
parents:
diff changeset
1687 return;
223b71206888 Initial import
thib
parents:
diff changeset
1688 }
223b71206888 Initial import
thib
parents:
diff changeset
1689 /* ¿§ÊÑ´¹¤ò¹Ô¤¦ */
223b71206888 Initial import
thib
parents:
diff changeset
1690 int len = width * height;
223b71206888 Initial import
thib
parents:
diff changeset
1691 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1692 int* outbuf = (int*)image;
223b71206888 Initial import
thib
parents:
diff changeset
1693 for(i=0; i<len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1694 *outbuf++ = read_little_endian_int(buf);
223b71206888 Initial import
thib
parents:
diff changeset
1695 buf += 4;
223b71206888 Initial import
thib
parents:
diff changeset
1696 }
223b71206888 Initial import
thib
parents:
diff changeset
1697 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1698
0
223b71206888 Initial import
thib
parents:
diff changeset
1699 void GRPCONV::CopyRGB(char* image, const char* buf) {
223b71206888 Initial import
thib
parents:
diff changeset
1700 /* ¿§ÊÑ´¹¤ò¹Ô¤¦ */
223b71206888 Initial import
thib
parents:
diff changeset
1701 int len = width * height;
223b71206888 Initial import
thib
parents:
diff changeset
1702 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1703 unsigned char* s = (unsigned char*)buf;
223b71206888 Initial import
thib
parents:
diff changeset
1704 int* d = (int*)image;
223b71206888 Initial import
thib
parents:
diff changeset
1705 for(i=0; i<len; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1706 *d = (int(s[0])) | (int(s[1])<<8) | (int(s[2])<<16) | 0xff000000;
223b71206888 Initial import
thib
parents:
diff changeset
1707 d++; s+=3;
223b71206888 Initial import
thib
parents:
diff changeset
1708 }
223b71206888 Initial import
thib
parents:
diff changeset
1709 }
223b71206888 Initial import
thib
parents:
diff changeset
1710
223b71206888 Initial import
thib
parents:
diff changeset
1711 #if HAVE_LIBPNG
223b71206888 Initial import
thib
parents:
diff changeset
1712 PNGCONV::PNGCONV(const char* _inbuf, int _inlen, const char* _filename) {
223b71206888 Initial import
thib
parents:
diff changeset
1713 int w,h,type;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1714 png_structp png_ptr = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1715 png_infop info_ptr = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1716 png_infop end_info = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1717
223b71206888 Initial import
thib
parents:
diff changeset
1718 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1719 if (!png_ptr) return;
223b71206888 Initial import
thib
parents:
diff changeset
1720
223b71206888 Initial import
thib
parents:
diff changeset
1721 info_ptr = png_create_info_struct(png_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1722 if (!info_ptr) goto err;
223b71206888 Initial import
thib
parents:
diff changeset
1723
223b71206888 Initial import
thib
parents:
diff changeset
1724 end_info = png_create_info_struct(png_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1725 if (!end_info) goto err;
223b71206888 Initial import
thib
parents:
diff changeset
1726
223b71206888 Initial import
thib
parents:
diff changeset
1727 if (setjmp(png_jmpbuf(png_ptr))) {
223b71206888 Initial import
thib
parents:
diff changeset
1728 /* error occured !! */
223b71206888 Initial import
thib
parents:
diff changeset
1729 goto err;
223b71206888 Initial import
thib
parents:
diff changeset
1730 }
223b71206888 Initial import
thib
parents:
diff changeset
1731
223b71206888 Initial import
thib
parents:
diff changeset
1732 /* initialize I/O */
223b71206888 Initial import
thib
parents:
diff changeset
1733 png_data = _inbuf;
223b71206888 Initial import
thib
parents:
diff changeset
1734 png_set_read_fn(png_ptr, (png_voidp)this, &png_read);
223b71206888 Initial import
thib
parents:
diff changeset
1735
223b71206888 Initial import
thib
parents:
diff changeset
1736 png_read_info(png_ptr, info_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1737
223b71206888 Initial import
thib
parents:
diff changeset
1738 w = png_get_image_width(png_ptr, info_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1739 h = png_get_image_height(png_ptr, info_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1740 type = png_get_color_type(png_ptr, info_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1741
223b71206888 Initial import
thib
parents:
diff changeset
1742 if (type == PNG_COLOR_TYPE_GRAY || type == PNG_COLOR_TYPE_GRAY_ALPHA) goto err; // not supported
223b71206888 Initial import
thib
parents:
diff changeset
1743
223b71206888 Initial import
thib
parents:
diff changeset
1744 Init(filename, _inbuf, _inlen, w, h, type == PNG_COLOR_TYPE_RGB_ALPHA ? true : false);
223b71206888 Initial import
thib
parents:
diff changeset
1745
223b71206888 Initial import
thib
parents:
diff changeset
1746 err:
223b71206888 Initial import
thib
parents:
diff changeset
1747 if (png_ptr) {
223b71206888 Initial import
thib
parents:
diff changeset
1748 if (end_info)
223b71206888 Initial import
thib
parents:
diff changeset
1749 png_destroy_read_struct(&png_ptr, &info_ptr,&end_info);
223b71206888 Initial import
thib
parents:
diff changeset
1750 else if (info_ptr)
223b71206888 Initial import
thib
parents:
diff changeset
1751 png_destroy_read_struct(&png_ptr, &info_ptr,(png_infopp)0);
223b71206888 Initial import
thib
parents:
diff changeset
1752 else
223b71206888 Initial import
thib
parents:
diff changeset
1753 png_destroy_read_struct(&png_ptr, (png_infopp) 0,(png_infopp)0);
223b71206888 Initial import
thib
parents:
diff changeset
1754 }
223b71206888 Initial import
thib
parents:
diff changeset
1755 }
223b71206888 Initial import
thib
parents:
diff changeset
1756
223b71206888 Initial import
thib
parents:
diff changeset
1757 bool PNGCONV::Read(char* image) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1758 if (data == NULL) return false;
0
223b71206888 Initial import
thib
parents:
diff changeset
1759 bool retcode = false;
223b71206888 Initial import
thib
parents:
diff changeset
1760 int bpp = is_mask ? 4 : 3;
223b71206888 Initial import
thib
parents:
diff changeset
1761 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1762 char* buf;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1763 png_bytepp row_pointers = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1764
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1765 png_structp png_ptr = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1766 png_infop info_ptr = NULL;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1767 png_infop end_info = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1768
223b71206888 Initial import
thib
parents:
diff changeset
1769 png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
223b71206888 Initial import
thib
parents:
diff changeset
1770 if (!png_ptr) goto err;
223b71206888 Initial import
thib
parents:
diff changeset
1771 info_ptr = png_create_info_struct(png_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1772 if (!info_ptr) goto err;
223b71206888 Initial import
thib
parents:
diff changeset
1773 end_info = png_create_info_struct(png_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1774 if (!end_info) goto err;
223b71206888 Initial import
thib
parents:
diff changeset
1775
223b71206888 Initial import
thib
parents:
diff changeset
1776 if (setjmp(png_jmpbuf(png_ptr))) {
223b71206888 Initial import
thib
parents:
diff changeset
1777 /* error occured !! */
223b71206888 Initial import
thib
parents:
diff changeset
1778 goto err;
223b71206888 Initial import
thib
parents:
diff changeset
1779 }
223b71206888 Initial import
thib
parents:
diff changeset
1780
223b71206888 Initial import
thib
parents:
diff changeset
1781 buf= new char[width*height*4];
223b71206888 Initial import
thib
parents:
diff changeset
1782 /* initialize I/O */
223b71206888 Initial import
thib
parents:
diff changeset
1783 png_data = data;
223b71206888 Initial import
thib
parents:
diff changeset
1784 png_set_read_fn(png_ptr, (png_voidp)this, &png_read);
223b71206888 Initial import
thib
parents:
diff changeset
1785
223b71206888 Initial import
thib
parents:
diff changeset
1786 row_pointers = (png_bytepp)png_malloc(png_ptr, height*sizeof(png_bytep));
223b71206888 Initial import
thib
parents:
diff changeset
1787 for (i=0; i<height; i++) row_pointers[i] = (png_bytep)(buf + width*bpp*i);
223b71206888 Initial import
thib
parents:
diff changeset
1788 png_set_rows(png_ptr, info_ptr, row_pointers);
223b71206888 Initial import
thib
parents:
diff changeset
1789
223b71206888 Initial import
thib
parents:
diff changeset
1790 png_read_png(png_ptr, info_ptr,
223b71206888 Initial import
thib
parents:
diff changeset
1791 PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_EXPAND | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_BGR,0);
223b71206888 Initial import
thib
parents:
diff changeset
1792
223b71206888 Initial import
thib
parents:
diff changeset
1793 if (buf != image) {
223b71206888 Initial import
thib
parents:
diff changeset
1794 CopyRGBA(image, buf);
223b71206888 Initial import
thib
parents:
diff changeset
1795 delete[] buf;
223b71206888 Initial import
thib
parents:
diff changeset
1796 }
223b71206888 Initial import
thib
parents:
diff changeset
1797 png_free(png_ptr, (png_voidp)row_pointers);
223b71206888 Initial import
thib
parents:
diff changeset
1798
223b71206888 Initial import
thib
parents:
diff changeset
1799 retcode = true;
223b71206888 Initial import
thib
parents:
diff changeset
1800 err:
223b71206888 Initial import
thib
parents:
diff changeset
1801 if (png_ptr) {
223b71206888 Initial import
thib
parents:
diff changeset
1802 if (end_info)
223b71206888 Initial import
thib
parents:
diff changeset
1803 png_destroy_read_struct(&png_ptr, &info_ptr,&end_info);
223b71206888 Initial import
thib
parents:
diff changeset
1804 else if (info_ptr)
223b71206888 Initial import
thib
parents:
diff changeset
1805 png_destroy_read_struct(&png_ptr, &info_ptr,(png_infopp)0);
223b71206888 Initial import
thib
parents:
diff changeset
1806 else
223b71206888 Initial import
thib
parents:
diff changeset
1807 png_destroy_read_struct(&png_ptr, (png_infopp) 0,(png_infopp)0);
223b71206888 Initial import
thib
parents:
diff changeset
1808 }
223b71206888 Initial import
thib
parents:
diff changeset
1809 return retcode;
223b71206888 Initial import
thib
parents:
diff changeset
1810 }
223b71206888 Initial import
thib
parents:
diff changeset
1811
223b71206888 Initial import
thib
parents:
diff changeset
1812 void PNGCONV::png_read(png_structp png_ptr, png_bytep d, png_size_t sz) {
223b71206888 Initial import
thib
parents:
diff changeset
1813 PNGCONV* orig = (PNGCONV*)png_get_io_ptr(png_ptr);
223b71206888 Initial import
thib
parents:
diff changeset
1814 memcpy(d, orig->png_data, sz);
223b71206888 Initial import
thib
parents:
diff changeset
1815 orig->png_data += sz;
223b71206888 Initial import
thib
parents:
diff changeset
1816 }
223b71206888 Initial import
thib
parents:
diff changeset
1817 #endif /* HAVE_LIBPNG */
223b71206888 Initial import
thib
parents:
diff changeset
1818
223b71206888 Initial import
thib
parents:
diff changeset
1819 #if HAVE_LIBJPEG
223b71206888 Initial import
thib
parents:
diff changeset
1820 JPEGCONV::JPEGCONV(const char* _inbuf, int _inlen, const char* _filename) {
223b71206888 Initial import
thib
parents:
diff changeset
1821 struct jpeg_decompress_struct cinfo;
223b71206888 Initial import
thib
parents:
diff changeset
1822 struct jpeg_error_mgr jerr;
223b71206888 Initial import
thib
parents:
diff changeset
1823 cinfo.err = jpeg_std_error(&jerr);
223b71206888 Initial import
thib
parents:
diff changeset
1824 jpeg_create_decompress(&cinfo);
223b71206888 Initial import
thib
parents:
diff changeset
1825 cinfo.src = new jpeg_source_mgr;
223b71206888 Initial import
thib
parents:
diff changeset
1826 SetupSrc(&cinfo, _inbuf, _inlen);
223b71206888 Initial import
thib
parents:
diff changeset
1827
223b71206888 Initial import
thib
parents:
diff changeset
1828 if (jpeg_read_header(&cinfo, TRUE) == JPEG_HEADER_OK) {
223b71206888 Initial import
thib
parents:
diff changeset
1829 Init(filename, _inbuf, _inlen, cinfo.image_width, cinfo.image_height, false);
223b71206888 Initial import
thib
parents:
diff changeset
1830 }
223b71206888 Initial import
thib
parents:
diff changeset
1831 delete cinfo.src;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1832 cinfo.src = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1833 jpeg_destroy_decompress(&cinfo);
223b71206888 Initial import
thib
parents:
diff changeset
1834 }
223b71206888 Initial import
thib
parents:
diff changeset
1835
223b71206888 Initial import
thib
parents:
diff changeset
1836 bool JPEGCONV::Read(char* image) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1837 if (data == NULL) return false;
0
223b71206888 Initial import
thib
parents:
diff changeset
1838 bool retcode = false;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1839 JSAMPARRAY rows, rows_orig;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1840 int i;
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1841 char* buf = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1842
223b71206888 Initial import
thib
parents:
diff changeset
1843 struct jpeg_decompress_struct cinfo;
223b71206888 Initial import
thib
parents:
diff changeset
1844 struct jpeg_error_mgr jerr;
223b71206888 Initial import
thib
parents:
diff changeset
1845 cinfo.err = jpeg_std_error(&jerr);
223b71206888 Initial import
thib
parents:
diff changeset
1846 jpeg_create_decompress(&cinfo);
223b71206888 Initial import
thib
parents:
diff changeset
1847 cinfo.src = new jpeg_source_mgr;
223b71206888 Initial import
thib
parents:
diff changeset
1848 SetupSrc(&cinfo, data, datalen);
223b71206888 Initial import
thib
parents:
diff changeset
1849
223b71206888 Initial import
thib
parents:
diff changeset
1850 if (jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK) goto err;
223b71206888 Initial import
thib
parents:
diff changeset
1851
223b71206888 Initial import
thib
parents:
diff changeset
1852 cinfo.out_color_space = JCS_RGB;
223b71206888 Initial import
thib
parents:
diff changeset
1853
223b71206888 Initial import
thib
parents:
diff changeset
1854 jpeg_start_decompress(&cinfo);
223b71206888 Initial import
thib
parents:
diff changeset
1855
223b71206888 Initial import
thib
parents:
diff changeset
1856 rows = new JSAMPROW[height];
223b71206888 Initial import
thib
parents:
diff changeset
1857 rows_orig = rows;
223b71206888 Initial import
thib
parents:
diff changeset
1858 buf = new char[width*height*3];
223b71206888 Initial import
thib
parents:
diff changeset
1859 for (i=0; i<height; i++) rows[i] = (JSAMPROW)(buf+width*3*i);
223b71206888 Initial import
thib
parents:
diff changeset
1860
223b71206888 Initial import
thib
parents:
diff changeset
1861 for (i=0; i<height; ) {
223b71206888 Initial import
thib
parents:
diff changeset
1862 int cnt = jpeg_read_scanlines(&cinfo, rows, height-i);
223b71206888 Initial import
thib
parents:
diff changeset
1863 rows += cnt;
223b71206888 Initial import
thib
parents:
diff changeset
1864 i += cnt;
223b71206888 Initial import
thib
parents:
diff changeset
1865 }
223b71206888 Initial import
thib
parents:
diff changeset
1866 delete[] rows_orig;
223b71206888 Initial import
thib
parents:
diff changeset
1867 CopyRGBA_rev(image, buf);
223b71206888 Initial import
thib
parents:
diff changeset
1868 delete[] buf;
223b71206888 Initial import
thib
parents:
diff changeset
1869
223b71206888 Initial import
thib
parents:
diff changeset
1870 jpeg_finish_decompress(&cinfo);
223b71206888 Initial import
thib
parents:
diff changeset
1871 retcode = true;
223b71206888 Initial import
thib
parents:
diff changeset
1872 err:
223b71206888 Initial import
thib
parents:
diff changeset
1873 delete cinfo.src;
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1874 cinfo.src = NULL;
0
223b71206888 Initial import
thib
parents:
diff changeset
1875 jpeg_destroy_decompress(&cinfo);
223b71206888 Initial import
thib
parents:
diff changeset
1876 return retcode;
223b71206888 Initial import
thib
parents:
diff changeset
1877 }
223b71206888 Initial import
thib
parents:
diff changeset
1878
223b71206888 Initial import
thib
parents:
diff changeset
1879 void JPEGCONV::init_source(j_decompress_ptr cinfo) {
223b71206888 Initial import
thib
parents:
diff changeset
1880 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1881
0
223b71206888 Initial import
thib
parents:
diff changeset
1882 boolean JPEGCONV::fill_input_buffer(j_decompress_ptr cinfo) {
223b71206888 Initial import
thib
parents:
diff changeset
1883 static char dummy[1024];
223b71206888 Initial import
thib
parents:
diff changeset
1884 memset(dummy, 0, 1024);
223b71206888 Initial import
thib
parents:
diff changeset
1885 cinfo->src->next_input_byte = (const JOCTET*)dummy;
223b71206888 Initial import
thib
parents:
diff changeset
1886 cinfo->src->bytes_in_buffer = 1024;
223b71206888 Initial import
thib
parents:
diff changeset
1887 fprintf(stderr,"JPEGCONV::fill_input_buffer: warning corrupted jpeg stream\n");
223b71206888 Initial import
thib
parents:
diff changeset
1888 return TRUE;
223b71206888 Initial import
thib
parents:
diff changeset
1889 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1890
0
223b71206888 Initial import
thib
parents:
diff changeset
1891 void JPEGCONV::skip_input_data(j_decompress_ptr cinfo, long num_bytes) {
223b71206888 Initial import
thib
parents:
diff changeset
1892 if (cinfo->src->bytes_in_buffer > num_bytes) {
223b71206888 Initial import
thib
parents:
diff changeset
1893 cinfo->src->next_input_byte += num_bytes;
223b71206888 Initial import
thib
parents:
diff changeset
1894 cinfo->src->bytes_in_buffer -= num_bytes;
223b71206888 Initial import
thib
parents:
diff changeset
1895 }
223b71206888 Initial import
thib
parents:
diff changeset
1896 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1897
0
223b71206888 Initial import
thib
parents:
diff changeset
1898 boolean JPEGCONV::resync_to_restart(j_decompress_ptr cinfo, int desired) {
223b71206888 Initial import
thib
parents:
diff changeset
1899 return jpeg_resync_to_restart(cinfo, desired);
223b71206888 Initial import
thib
parents:
diff changeset
1900 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1901
0
223b71206888 Initial import
thib
parents:
diff changeset
1902 void JPEGCONV::term_source(j_decompress_ptr cinf) {
223b71206888 Initial import
thib
parents:
diff changeset
1903 }
223b71206888 Initial import
thib
parents:
diff changeset
1904
223b71206888 Initial import
thib
parents:
diff changeset
1905 void JPEGCONV::SetupSrc(struct jpeg_decompress_struct* cinfo, const char* data, int size) {
223b71206888 Initial import
thib
parents:
diff changeset
1906 cinfo->src->next_input_byte = (const JOCTET*) data;
223b71206888 Initial import
thib
parents:
diff changeset
1907 cinfo->src->bytes_in_buffer = size;
223b71206888 Initial import
thib
parents:
diff changeset
1908 cinfo->src->init_source = init_source;
223b71206888 Initial import
thib
parents:
diff changeset
1909 cinfo->src->fill_input_buffer = fill_input_buffer;
223b71206888 Initial import
thib
parents:
diff changeset
1910 cinfo->src->skip_input_data = skip_input_data;
223b71206888 Initial import
thib
parents:
diff changeset
1911 cinfo->src->resync_to_restart = resync_to_restart;
223b71206888 Initial import
thib
parents:
diff changeset
1912 cinfo->src->term_source = term_source;
223b71206888 Initial import
thib
parents:
diff changeset
1913 }
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1914
0
223b71206888 Initial import
thib
parents:
diff changeset
1915 #endif /* HAVE_LIBJPEG */
223b71206888 Initial import
thib
parents:
diff changeset
1916 BMPCONV::BMPCONV(const char* _inbuf, int _inlen, const char* _filename) {
223b71206888 Initial import
thib
parents:
diff changeset
1917 /* ¥Ç¡¼¥¿¤«¤é¾ðÊóÆɤ߹þ¤ß */
223b71206888 Initial import
thib
parents:
diff changeset
1918 int w = read_little_endian_int(_inbuf + 0x12);
223b71206888 Initial import
thib
parents:
diff changeset
1919 int h = read_little_endian_int(_inbuf + 0x16);
223b71206888 Initial import
thib
parents:
diff changeset
1920 if (h < 0) h = -h;
223b71206888 Initial import
thib
parents:
diff changeset
1921 int bpp = read_little_endian_short(_inbuf + 0x1c);
223b71206888 Initial import
thib
parents:
diff changeset
1922 int comp = read_little_endian_int(_inbuf + 0x1e);
223b71206888 Initial import
thib
parents:
diff changeset
1923 Init(filename, _inbuf, _inlen, w, h, bpp==32 ? true : false);
223b71206888 Initial import
thib
parents:
diff changeset
1924 }
223b71206888 Initial import
thib
parents:
diff changeset
1925
223b71206888 Initial import
thib
parents:
diff changeset
1926 bool BMPCONV::Read(char* image) {
52
15a18fbe6f21 * Known bugs added to the README
thib
parents: 50
diff changeset
1927 if (data == NULL) return false;
0
223b71206888 Initial import
thib
parents:
diff changeset
1928
223b71206888 Initial import
thib
parents:
diff changeset
1929 /* ¥Þ¥¹¥¯¤Î¥Á¥§¥Ã¥¯ */
223b71206888 Initial import
thib
parents:
diff changeset
1930 int bpp = read_little_endian_short(data+0x1c);
223b71206888 Initial import
thib
parents:
diff changeset
1931 int h = read_little_endian_int(data + 0x16);
223b71206888 Initial import
thib
parents:
diff changeset
1932 int dsz = read_little_endian_int(data + 0x22);
223b71206888 Initial import
thib
parents:
diff changeset
1933 bpp /= 8;
223b71206888 Initial import
thib
parents:
diff changeset
1934
223b71206888 Initial import
thib
parents:
diff changeset
1935 int bpl = dsz / height;
223b71206888 Initial import
thib
parents:
diff changeset
1936 if (bpl == 0) bpl = bpp*width;
223b71206888 Initial import
thib
parents:
diff changeset
1937 bpl = bpp * width;
223b71206888 Initial import
thib
parents:
diff changeset
1938 bpl = (bpl+3) & (~3);
223b71206888 Initial import
thib
parents:
diff changeset
1939
223b71206888 Initial import
thib
parents:
diff changeset
1940
223b71206888 Initial import
thib
parents:
diff changeset
1941 int i;
223b71206888 Initial import
thib
parents:
diff changeset
1942 char* buf = new char[width*height*bpp+1024];
223b71206888 Initial import
thib
parents:
diff changeset
1943 const char* src = data + 0x36;
223b71206888 Initial import
thib
parents:
diff changeset
1944 char* dest = buf;
223b71206888 Initial import
thib
parents:
diff changeset
1945 if (h < 0) {
223b71206888 Initial import
thib
parents:
diff changeset
1946 for (i=0; i<height; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1947 memcpy(dest+i*width*bpp, src+i*bpl, width*bpp);
223b71206888 Initial import
thib
parents:
diff changeset
1948 }
223b71206888 Initial import
thib
parents:
diff changeset
1949 } else {
223b71206888 Initial import
thib
parents:
diff changeset
1950 for (i=0; i<height; i++) {
223b71206888 Initial import
thib
parents:
diff changeset
1951 memcpy(dest+i*width*bpp, src+(height-i-1)*bpl, width*bpp);
223b71206888 Initial import
thib
parents:
diff changeset
1952 }
223b71206888 Initial import
thib
parents:
diff changeset
1953 }
223b71206888 Initial import
thib
parents:
diff changeset
1954 if (bpp == 3) CopyRGB(image, buf);
223b71206888 Initial import
thib
parents:
diff changeset
1955 else /* bpp == 4 */ CopyRGBA(image, buf);
223b71206888 Initial import
thib
parents:
diff changeset
1956 delete[] buf;
223b71206888 Initial import
thib
parents:
diff changeset
1957 return true;
223b71206888 Initial import
thib
parents:
diff changeset
1958 }
223b71206888 Initial import
thib
parents:
diff changeset
1959