projects
/
swan-dev
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
e91d694
)
tools: bmp2tiles write to seperate output folder
author
Robin Krens
<robin@robinkrens.nl>
Wed, 15 Jun 2022 14:54:40 +0000
(16:54 +0200)
committer
Robin Krens
<robin@robinkrens.nl>
Wed, 15 Jun 2022 14:56:54 +0000
(16:56 +0200)
tools/bmp2tiles/bmp2tiles.c
patch
|
blob
|
history
diff --git
a/tools/bmp2tiles/bmp2tiles.c
b/tools/bmp2tiles/bmp2tiles.c
index
7da5a38
..
61ce69c
100644
(file)
--- a/
tools/bmp2tiles/bmp2tiles.c
+++ b/
tools/bmp2tiles/bmp2tiles.c
@@
-14,6
+14,10
@@
#include <unistd.h>
#include <assert.h>
#include <getopt.h>
#include <unistd.h>
#include <assert.h>
#include <getopt.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/sysmacros.h>
#include <SDL2/SDL_image.h>
#define TILE_SZ 32
#include <SDL2/SDL_image.h>
#define TILE_SZ 32
@@
-103,7
+107,7
@@
FILE * openstream(const char * name, const char * prefix,
unsigned buf_len = 256;
char buf[buf_len];
unsigned buf_len = 256;
char buf[buf_len];
- snprintf(buf, buf_len, "%s
%d.%s"
, name, tile_nr, prefix);
+ snprintf(buf, buf_len, "%s
/%s%d.%s", prefix
, name, tile_nr, prefix);
//printf("%s\n", buf);
if (!append) {
//printf("%s\n", buf);
if (!append) {
@@
-115,6
+119,20
@@
FILE * openstream(const char * name, const char * prefix,
return stream;
}
return stream;
}
+int create_dir(const char *name)
+{
+ struct stat statbuf;
+
+ if (stat(name, &statbuf) == -1)
+ return mkdir(name, 0755);
+
+ if ((statbuf.st_mode & S_IFMT) != S_IFDIR)
+ return -1;
+
+ return 0;
+}
+
+
int main(int argc, char *argv[])
{
SDL_Surface * rawbmp;
int main(int argc, char *argv[])
{
SDL_Surface * rawbmp;
@@
-178,6
+196,15
@@
int main(int argc, char *argv[])
sprintf(outfile, "out");
}
sprintf(outfile, "out");
}
+ /* check for existing gfx/ and pal/ directories */
+ ret = create_dir("gfx/");
+ ret += create_dir("pal/");
+
+ if (ret) {
+ fprintf(stderr, "error: can not create output location\n");
+ goto cleanup;
+ }
+
fprintf(stdout, "generating %d tile(s) \
in %d gfx file(s) \
with %d pal file(s)\n",
fprintf(stdout, "generating %d tile(s) \
in %d gfx file(s) \
with %d pal file(s)\n",
@@
-185,7
+212,6
@@
int main(int argc, char *argv[])
seperate_gfx ? gfx->row_tiles * gfx->col_tiles : 1,
seperate_pal ? gfx->row_tiles * gfx->col_tiles : 1);
seperate_gfx ? gfx->row_tiles * gfx->col_tiles : 1,
seperate_pal ? gfx->row_tiles * gfx->col_tiles : 1);
-
for (int i = 0, cnt = 0; i < gfx->row_tiles; ++i) {
for (int j = 0; j < gfx->col_tiles; ++j, ++cnt) {
for (int i = 0, cnt = 0; i < gfx->row_tiles; ++i) {
for (int j = 0; j < gfx->col_tiles; ++j, ++cnt) {