Changeset 540 for abuse/trunk/src/imlib/specs.cpp
- Timestamp:
- Apr 24, 2011, 10:33:34 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
abuse/trunk/src/imlib/specs.cpp
r539 r540 25 25 #include "image.h" 26 26 #include "palette.h" 27 #include "pcxread.h"28 27 #include "specs.h" 29 28 #include "dprint.h" … … 963 962 } 964 963 965 void spec_directory::extract(char const *name)966 {967 jFILE fp(name, "rb");968 if (fp.open_failure())969 {970 fprintf(stderr, "Spec: ERROR - could not open %s\n", name);971 return;972 }973 974 spec_directory dir(&fp);975 if (dir.total <= 0)976 {977 fprintf(stderr, "Spec: ERROR - no signature or no data in %s\n", name);978 return;979 }980 981 char const *out = "SPEC.DIR";982 mkdir(out, S_IRUSR | S_IWUSR | S_IXUSR);983 if (chdir(out))984 {985 fprintf(stderr, "Spec: ERROR - could not create or cd to %s\n", out);986 return;987 }988 989 palette *pal = NULL;990 991 for (int i = 0; i < dir.total; i++)992 {993 spec_entry *se = dir.entries[i];994 995 FILE *fp2 = fopen(se->name, "wb");996 if (!fp2)997 {998 fprintf(stderr, "Spec: ERROR - could not write to %s\n", se->name);999 continue;1000 }1001 1002 fp.seek(se->offset, SEEK_SET);1003 uint8_t buf[1024];1004 size_t todo = se->size;1005 while (todo > 0)1006 {1007 fp.read(buf, Min(todo, 1024));1008 fwrite(buf, Min(todo, 1024), 1, fp2);1009 todo -= Min(todo, 1024);1010 }1011 fclose(fp2);1012 1013 fprintf(stderr, "Spec: %s (type %i): %i bytes\n",1014 se->name, se->type, (int)se->size);1015 1016 /* If it's a palette, keep it */1017 if (!pal && se->type == SPEC_PALETTE)1018 pal = new palette(se, &fp);1019 }1020 1021 /* If we have a palette, output all images */1022 for (int i = 0; pal && i < dir.total; i++)1023 {1024 char buf[1024];1025 spec_entry *se = dir.entries[i];1026 1027 switch (se->type)1028 {1029 case SPEC_IMAGE:1030 case SPEC_FORETILE:1031 case SPEC_BACKTILE:1032 case SPEC_CHARACTER:1033 case SPEC_CHARACTER2:1034 sprintf(buf, "%s-export.pcx", se->name);1035 image *im = new image(&fp, se);1036 write_PCX(im, pal, buf);1037 delete im;1038 fprintf(stderr, "Spec: %s is an image\n", buf);1039 break;1040 }1041 }1042 1043 /* Clean up */1044 delete pal;1045 }1046 1047 964 void note_open_fd(int fd, char const *str) 1048 965 {
Note: See TracChangeset
for help on using the changeset viewer.