From b95c01bbeb8af95d534aa3ef74f45bdee20ec419 Mon Sep 17 00:00:00 2001 From: neauoire Date: Mon, 30 Nov 2020 11:40:31 -0800 Subject: [PATCH] Removed bmp stuff until I figure it out --- README.md | 11 +--- nasu-export2.chr | Bin 0 -> 8192 bytes nasu.c | 129 +++++++++++++++-------------------------------- 3 files changed, 43 insertions(+), 97 deletions(-) create mode 100644 nasu-export2.chr diff --git a/README.md b/README.md index 5e4d962..73c5259 100644 --- a/README.md +++ b/README.md @@ -18,12 +18,6 @@ To resume working on a tileset: ./nasu example.chr ``` -Import a bmp: - -``` -./nasu example.bmp -``` - ## Controls ### Generics @@ -38,12 +32,11 @@ Import a bmp: ### General -- `1-7` Patterns -- `ASDF` Colors0-3 +- `1-4` Colors0-3 +- `ASDFG` Modes0-4 - `H` Toggle Guides - `Z` Decr. Brush Size - `X` Incr. Brush Size -- `C` Cleanup Brush - `N` Clear ### Paint diff --git a/nasu-export2.chr b/nasu-export2.chr new file mode 100644 index 0000000000000000000000000000000000000000..52a5be5c381fcce4a04e4ca419aaab29ff551d38 GIT binary patch literal 8192 zcmeHM4``KD6#q8e+~%LXGHB$~mt>RBIa16d=*7UA|C+}BnbzBMlBMf4C#G&X!=Vtw zD0CBxKBP!3zJ5=0hiIeAlu8fSwa6Sh^@=)nVj zASiJHz#%1`?`WreJ>^NO^8l#iLa(DVW4ko-CsSO1;(H5QVG54!!yh`IH?$R6J< zo&$^@%c@GN%CoZ_|fvT#?#bq-~SC*9*=I1UcT^cH1=pA~a z|38XA#=L&TUDrcn1M2>JsjEcH1r$|mS@EMH4-WX8C!NS`$bAh)X@Gy@c^H8nU83e)I0G4pNm}|D92Nt zvqS3r@Z+)`*r(ig4t`_4^n-HZ)4ms=j{!kuEcgNA=))igaq1`JKu2V*M>I~Pq>uneU zKS;i{zTSVCFK?WA9^|ZQkbMgVyn2(DNuBr_r4ET_&yhTb1_|{Kap#@&&|AN6=-r4w zUqm3-)>;33ffw#$yuR@1dcfd59y$)%sSElO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00001 diff --git a/nasu.c b/nasu.c index 1bdfce1..8420331 100644 --- a/nasu.c +++ b/nasu.c @@ -55,22 +55,6 @@ distance(int ax, int ay, int bx, int by) return (bx - ax) * (bx - ax) + (by - ay) * (by - ay); } -int -spos(char *s, char *ss) -{ - int a = 0, b = 0; - while(s[a] != '\0') { - if(s[a] == ss[b]) { - if(ss[b + 1] == '\0') - return a - b; - b++; - } else - b = 0; - a++; - } - return -1; -} - unsigned char chex(char c) { @@ -90,14 +74,6 @@ shex(char *s, int len) return n; } -int -getclr(int r, int g, int b) -{ - return r && g && b && r == g && g == b ? 1 : r > g && r > b ? 2 - : g > r && g > b ? 3 - : 0; -} - /* chr */ void @@ -117,25 +93,27 @@ rowchr(int x, int y) int getchr(int x, int y) { - int ch1, ch2; - int r = rowchr(x, y); - int px = x % 8; + int ch1, ch2, r = rowchr(x, y); if(r < 0 || r > SZ - 8) return 0; - ch1 = (chrbuf[r] >> (7 - px)) & 1; - ch2 = (chrbuf[r + 8] >> (7 - px)) & 1; - return ch1 && !ch2 ? 1 : !ch1 && ch2 ? 2 - : ch1 && ch2 ? 3 - : 0; + ch1 = (chrbuf[r] >> (7 - x % 8)) & 1; + ch2 = (chrbuf[r + 8] >> (7 - x % 8)) & 1; + if(ch1 && !ch2) + return 1; + if(!ch1 && ch2) + return 2; + if(ch1 && ch2) + return 3; + return 0; } void putchr(int x, int y, int color) { int r = rowchr(x, y), px = x % 8; - if(x < 0 || x > HOR * 8) + if(x < 0 || x >= HOR * 8) return; - if(y < 0 || y > VER * 8) + if(y < 0 || y >= VER * 8) return; if(!color) { chrbuf[r] &= ~(1UL << (7 - px)); @@ -180,12 +158,6 @@ patt(int x, int y, int mode, int size) return ((x + y) % 2) == 0 && ((y - x) % 2) == 0; if(mode == 3) return 1; - if(mode == 4) - return y % size == 0; - if(mode == 5) - return x % size == 0; - if(mode == 6) - return (x + y) % size == 0 || (x - y) % size == 0; return 0; } @@ -195,9 +167,11 @@ fill(int x, int y, int mode, int size, int color) int ox, oy; for(ox = x - (size / 2); ox < x + size; ++ox) for(oy = y - (size / 2); oy < y + size; ++oy) - if(mode == 7 && jagg(ox, oy)) + if(distance(x, y, ox, oy) < size) + continue; + else if(mode == 4 && jagg(ox, oy)) putchr(ox, oy, 0); - else if(patt(ox, oy, mode, size) && distance(x, y, ox, oy) < size) + else if(patt(ox, oy, mode, size)) putchr(ox, oy, color); } @@ -228,10 +202,10 @@ line(int ax, int ay, int bx, int by, int color) void clear(Uint32 *dst) { - int i, j; - for(i = 0; i < HEIGHT; i++) - for(j = 0; j < WIDTH; j++) - dst[i * WIDTH + j] = theme[0]; + int v, h; + for(v = 0; v < HEIGHT; v++) + for(h = 0; h < WIDTH; h++) + dst[v * WIDTH + h] = theme[0]; } void @@ -279,7 +253,7 @@ drawui(Uint32 *dst) drawicon(dst, 5 * 8, bottom, icon3, theme[brush.mode == 1 ? 2 : 3]); drawicon(dst, 6 * 8, bottom, icon4, theme[brush.mode == 2 ? 2 : 3]); drawicon(dst, 7 * 8, bottom, icon5, theme[brush.mode == 3 ? 2 : 3]); - drawicon(dst, 8 * 8, bottom, icon6, theme[brush.mode == 7 ? 2 : 3]); + drawicon(dst, 8 * 8, bottom, icon6, theme[brush.mode == 4 ? 2 : 3]); } void @@ -371,7 +345,11 @@ void renderbmp(void) { SDL_Surface *surface = SDL_GetWindowSurface(gWindow); - SDL_RenderReadPixels(gRenderer, NULL, SDL_PIXELFORMAT_ARGB8888, surface->pixels, surface->pitch); + SDL_RenderReadPixels(gRenderer, + NULL, + SDL_PIXELFORMAT_ARGB8888, + surface->pixels, + surface->pitch); if(SDL_SaveBMP(surface, "nasu-render.bmp")) printf("SDL_SaveBMP failed: %s\n", SDL_GetError()); else @@ -380,34 +358,15 @@ renderbmp(void) } void -loadchr(char *path) +loadchr(FILE *f) { - FILE *f = fopen(path, "rb"); - if(f == NULL) + if(!f) error("Load", "Invalid input file"); if(!fread(chrbuf, sizeof(chrbuf), 1, f)) error("Load", "Invalid input size"); fclose(f); } -void -loadbmp(char *path) -{ - FILE *f = fopen(path, "rb"); - int i, width = HOR * 8, height = VER * 8, size = 3 * width * height; - unsigned char header[54]; - unsigned char data[4096 * 256]; - if(!fread(header, sizeof(unsigned char), 54, f)) - error("Load", "Invalid bmp header"); - if(!fread(data, sizeof(unsigned char), size, f)) - error("Load", "Invalid bmp body"); - for(i = 0; i < size; i += 3) { - int x = (i / 3) % width, y = height - (i / 3) / width - 1; - putchr(x, y, getclr(data[i + 2], data[i + 1], data[i])); - } - fclose(f); -} - void loadtheme(FILE *f) { @@ -439,7 +398,7 @@ selectoption(int option) case 5: setmode(&brush, 1); break; case 6: setmode(&brush, 2); break; case 7: setmode(&brush, 3); break; - case 8: setmode(&brush, 7); break; + case 8: setmode(&brush, 4); break; } } @@ -514,23 +473,20 @@ dokey(SDL_Event *event, Brush *b) case SDLK_PLUS: modzoom(1); break; case SDLK_UNDERSCORE: case SDLK_MINUS: modzoom(-1); break; - case SDLK_1: setmode(b, 0); break; - case SDLK_2: setmode(b, 1); break; - case SDLK_3: setmode(b, 2); break; - case SDLK_4: setmode(b, 3); break; - case SDLK_5: setmode(b, 4); break; - case SDLK_6: setmode(b, 5); break; - case SDLK_7: setmode(b, 6); break; + case SDLK_1: setcolor(b, 1); break; + case SDLK_2: setcolor(b, 2); break; + case SDLK_3: setcolor(b, 3); break; + case SDLK_4: setcolor(b, 0); break; case SDLK_e: exportchr(b); break; case SDLK_r: renderbmp(); break; - case SDLK_a: setcolor(b, 0); break; - case SDLK_s: setcolor(b, 1); break; - case SDLK_d: setcolor(b, 2); break; - case SDLK_f: setcolor(b, 3); break; + case SDLK_a: setmode(b, 0); break; + case SDLK_s: setmode(b, 1); break; + case SDLK_d: setmode(b, 2); break; + case SDLK_f: setmode(b, 3); break; + case SDLK_g: setmode(b, 4); break; case SDLK_h: toggleguide(); break; case SDLK_z: modsize(b, -1); break; case SDLK_x: modsize(b, 1); break; - case SDLK_c: setmode(b, 7); break; case SDLK_n: destroy(); break; } } @@ -580,13 +536,10 @@ main(int argc, char **argv) return error("Init", "Failure"); loadtheme(fopen("theme.svg", "r")); + newchr(); - if(argc > 1 && spos(argv[1], ".bmp") > -1) - loadbmp(argv[1]); - else if(argc > 1 && spos(argv[1], ".chr") > -1) - loadchr(argv[1]); - else - newchr(); + if(argc > 1) + loadchr(fopen(argv[1], "r")); redraw(pixels);