diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:43:59 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-11-17 19:43:59 (GMT) |
| commit | e3594aba9e05c6865d396418c028049cda92c2f3 (patch) | |
| tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 /font | |
| parent | fb43f7d23e99765ae093fc45608901cb5907d1d8 (diff) | |
| download | powder-e3594aba9e05c6865d396418c028049cda92c2f3.zip powder-e3594aba9e05c6865d396418c028049cda92c2f3.tar.gz | |
Remove old code
Diffstat (limited to 'font')
| -rw-r--r-- | font/Makefile | 20 | ||||
| -rw-r--r-- | font/editor.c | 288 | ||||
| -rw-r--r-- | font/font.bin | bin | 31028 -> 0 bytes | |||
| -rw-r--r-- | font/packer.c | 111 | ||||
| -rw-r--r-- | font/unpacker.c | 113 |
5 files changed, 0 insertions, 532 deletions
diff --git a/font/Makefile b/font/Makefile deleted file mode 100644 index 608827d..0000000 --- a/font/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -editor: editor.c - gcc -oeditor -DSCALE=2 -DFONTEDITOR editor.c -lSDL -lm -O3 -ffast-math -march=k8 -Wall -std=c99 - -editor.exe: editor.c - gcc -oeditor.exe -DSCALE=2 -DFONTEDITOR editor.c -lmingw32 -lm -lSDLmain -lSDL -O3 -ffast-math -march=k8 -Wall -std=c99 -mwindows - -packer: packer.c - gcc -opacker -DFONTEDITOR packer.c -lm -O3 -ffast-math -march=k8 -Wall -std=c99 - -packer.exe: packer.c - gcc -opacker.exe -DFONTEDITOR packer.c -lm -O3 -ffast-math -march=k8 -Wall -std=c99 - -unpacker: unpacker.c - gcc -ounpacker -DFONTEDITOR unpacker.c -lm -O3 -ffast-math -march=k8 -Wall -std=c99 - -unpacker.exe: unpacker.c - gcc -ounpacker.exe -DFONTEDITOR unpacker.c -lm -O3 -ffast-math -march=k8 -Wall -std=c99 - -clean: - rm -f editor packer unpacker editor.exe packer.exe unpacker.exe diff --git a/font/editor.c b/font/editor.c deleted file mode 100644 index 7714782..0000000 --- a/font/editor.c +++ /dev/null @@ -1,288 +0,0 @@ -#ifdef FONTEDITOR - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> -#include <SDL/SDL.h> - -#define CELLW 12 -#define CELLH 10 - -#define XRES 800 -#define YRES 600 - -char xsize=CELLW, ysize=CELLH; -char base=7, top=2; -char font[256][CELLH][CELLW]; -char width[256]; - -void blendpixel(unsigned *vid, int x, int y, int r, int g, int b, int a) -{ - int t; - if(x<0 || y<0 || x>=XRES || y>=YRES) - return; - if(a!=255) { - t = vid[y*XRES+x]; - r = (a*r + (255-a)*((t>>16)&255)) >> 8; - g = (a*g + (255-a)*((t>>8)&255)) >> 8; - b = (a*b + (255-a)*(t&255)) >> 8; - } - vid[y*XRES+x] = (r<<16)|(g<<8)|b; -} - -int drawchar(unsigned *vid, int x, int y, int c, int r, int g, int b) -{ - int i, j; - for(j=0; j<CELLH; j++) - for(i=0; i<width[c]; i++) - blendpixel(vid, x+i, y+j, r, g, b, (font[c][j][i]*255)/3); - return x + width[c]; -} - -int drawtext(unsigned *vid, int x, int y, char *s, int r, int g, int b) -{ - for(;*s;s++) - x = drawchar(vid, x, y, *s, r, g, b); - return x; -} - -void drawline(unsigned *vid, int x1, int y1, int x2, int y2, int r, int g, int b, int a) -{ - int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; - float e, de; - if(cp) { - y = x1; - x1 = y1; - y1 = y; - y = x2; - x2 = y2; - y2 = y; - } - if(x1 > x2) { - y = x1; - x1 = x2; - x2 = y; - y = y1; - y1 = y2; - y2 = y; - } - dx = x2 - x1; - dy = abs(y2 - y1); - e = 0.0f; - de = dy/(float)dx; - y = y1; - sy = (y1<y2) ? 1 : -1; - for(x=x1; x<=x2; x++) { - if(cp) - blendpixel(vid, y, x, r, g, b, a); - else - blendpixel(vid, x, y, r, g, b, a); - e += de; - if(e >= 0.5f) { - y += sy; - e -= 1.0f; - } - } -} - -void drawcell(unsigned *vid, int i, int j, int c, int m) -{ - int x,y,x0=i*32+64,y0=j*32+64; - for(y=1;y<32;y++) - for(x=1;x<32;x++) - blendpixel(vid, x0+x, y0+y, 127*m, 127*m, 127*m, c); - for(x=0;x<32;x+=2) { - if(!j) - blendpixel(vid, x0+x, y0, 64*m, 64*m, 64*m, 255); - if(!i) - blendpixel(vid, x0, y0+x, 64*m, 64*m, 64*m, 255); - blendpixel(vid, x0+x, y0+32, 64*m, 64*m, 64*m, 255); - blendpixel(vid, x0+32, y0+x, 64*m, 64*m, 64*m, 255); - } -} - -/*********************************************************** - * SDL OUTPUT * - ***********************************************************/ - -SDL_Surface *sdl_scrn; -int sdl_key; -void sdl_open(void) -{ - if(SDL_Init(SDL_INIT_VIDEO)<0) { - fprintf(stderr, "Initializing SDL: %s\n", SDL_GetError()); - exit(1); - } - atexit(SDL_Quit); - sdl_scrn=SDL_SetVideoMode(XRES*SCALE,YRES*SCALE + 40*SCALE,32,SDL_SWSURFACE); - if(!sdl_scrn) { - fprintf(stderr, "Creating window: %s\n", SDL_GetError()); - exit(1); - } -} - -void sdl_blit(int x, int y, int w, int h, unsigned int *src, int pitch) -{ - unsigned *dst,i,j,k; - if(SDL_MUSTLOCK(sdl_scrn)) - if(SDL_LockSurface(sdl_scrn)<0) - return; - dst=(unsigned *)sdl_scrn->pixels+y*sdl_scrn->pitch/4+x; - for(j=0;j<h;j++) { - for(k=0;k<SCALE;k++) { - for(i=0;i<w*SCALE;i++) - dst[i]=src[i/SCALE]; - dst+=sdl_scrn->pitch/4; - } - src+=pitch/4; - } - if(SDL_MUSTLOCK(sdl_scrn)) - SDL_UnlockSurface(sdl_scrn); - SDL_UpdateRect(sdl_scrn,0,0,0,0); -} - -int frame_idx=0; -void dump_frame(unsigned int *src, int w, int h, int pitch) -{ - char frame_name[32]; - unsigned j,i,c; - FILE *f; - sprintf(frame_name,"frame%04d.ppm",frame_idx); - f=fopen(frame_name,"w"); - fprintf(f,"P6\n%d %d\n255\n",w,h); - for(j=0;j<h;j++) { - for(i=0;i<w;i++) { - c=((src[i]&0xFF0000)>>16)|(src[i]&0x00FF00)|((src[i]&0x0000FF)<<16); - fwrite(&c,3,1,f); - } - src+=pitch/4; - } - fclose(f); - frame_idx++; -} - -int sdl_poll(void) -{ - SDL_Event event; - sdl_key=0; - while(SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_KEYDOWN: - sdl_key=event.key.keysym.sym; - break; - case SDL_QUIT: - return 1; - } - } - return 0; -} - -/*********************************************************** - * MAIN PROGRAM * - ***********************************************************/ - -char *tag = "(c) 2008 Stanislaw Skowronek"; - -int main(int argc, char *argv[]) -{ - unsigned *vid_buf = calloc(XRES*YRES, sizeof(unsigned)); - int x, y, b = 0, lb, c = 0xA0, i, j, dc = 0; - int mode = 0; - FILE *f; - - f = fopen("font.bin", "r"); - if(f) { - fread(&xsize, 1, 1, f); - fread(&ysize, 1, 1, f); - fread(&base, 1, 1, f); - fread(&top, 1, 1, f); - fread(width, 1, 256, f); - fread(font, CELLW*CELLH, 256, f); - fclose(f); - } - - sdl_open(); - while(!sdl_poll()) { - if(sdl_key=='q' || sdl_key==SDLK_ESCAPE) - break; - if(sdl_key==' ' || sdl_key=='=') { - c++; - printf("Current: %02X '%c'\n", c, c); - } - if(sdl_key=='\b' || sdl_key=='-') { - c--; - printf("Current: %02X '%c'\n", c, c); - } - - lb = b; - b = SDL_GetMouseState(&x, &y); - if(b) { - x /= SCALE; - y /= SCALE; - } - - i = x/32-2; - j = y/32-2; - if(!lb && b && (i<0 || i>=CELLW)) { - if(abs(j-base) < abs(j-top)) - mode = 2; // BASE - else - mode = 3; // TOP - } else if(!lb && b && (j<0 || j>=CELLH)) - mode = 4; // LEFT - else if(!lb && b) { - mode = 1; // DRAW - if(b==1) - dc = (font[c][j][i]+3)%4; - else - dc = (font[c][j][i]+1)%4; - } - - if(b) - switch(mode) { - case 1: - if(i>=0 && j>=0 && i<CELLW && j<CELLH) - font[c][j][i] = dc; - break; - case 2: - base = j; - break; - case 3: - top = j; - break; - case 4: - width[c] = i; - break; - } - - memset(vid_buf, 0, XRES*YRES*4); - for(j=0; j<CELLH; j++) - for(i=0; i<CELLW; i++) - drawcell(vid_buf, i, j, (font[c][j][i]*255)/3, i>=width[c]?1:2); - drawline(vid_buf, 32, 64+base*32, 128+32*CELLW, 64+base*32, 128, 255, 128, 255); - drawline(vid_buf, 32, 64+top*32, 128+32*CELLW, 64+top*32, 128, 128, 255, 255); - drawline(vid_buf, 64+width[c]*32, 32, 64+width[c]*32, 128+32*CELLH, 255, 128, 128, 255); - - drawtext(vid_buf, 64, 192+32*CELLH, "A quick brown fox jumps over the lazy dog.", 255, 255, 255); - drawtext(vid_buf, 64, 192+33*CELLH, "A QUICK BROWN FOX JUMPS OVER THE LAZY DOG.", 255, 255, 255); - drawtext(vid_buf, 64, 192+34*CELLH, "0123456789 ~`!@#$%^&*()-=_+[]{}\\|;:'\",./<>?", 255, 255, 255); - - drawchar(vid_buf, 32, 192+32*CELLH, c, 255, 255, 255); - - sdl_blit(0, 0, XRES, YRES, vid_buf, XRES*4); - } - - f = fopen("font.bin", "w"); - fwrite(&xsize, 1, 1, f); - fwrite(&ysize, 1, 1, f); - fwrite(&base, 1, 1, f); - fwrite(&top, 1, 1, f); - fwrite(width, 1, 256, f); - fwrite(font, CELLW*CELLH, 256, f); - fclose(f); - - return 0; -} - -#endif diff --git a/font/font.bin b/font/font.bin Binary files differdeleted file mode 100644 index ea3687d..0000000 --- a/font/font.bin +++ /dev/null diff --git a/font/packer.c b/font/packer.c deleted file mode 100644 index 4ecf8a7..0000000 --- a/font/packer.c +++ /dev/null @@ -1,111 +0,0 @@ -#ifdef FONTEDITOR - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> - -#define CELLW 12 -#define CELLH 10 - -char xsize=CELLW, ysize=CELLH; -char base=7, top=2; -char font[256][CELLH][CELLW]; -char width[256]; - -int bits_n = 0, bits_a = 0; -int flush_bits(void) -{ - if(bits_n) { - bits_a >>= 8-bits_n; - printf("0x%02X, ", bits_a); - bits_a = 0; - bits_n = 0; - return 1; - } - return 0; -} -int stock_bits(int b, int nb) -{ - bits_a >>= nb; - bits_a |= b << (8-nb); - bits_n += nb; - if(bits_n >= 8) { - printf("0x%02X, ", bits_a); - bits_a = 0; - bits_n = 0; - return 1; - } - return 0; -} - -int save_char(int c) -{ - int nb = 1; - int x, y; - - if(!width[c]) - return 0; - - printf(" 0x%02X, ", width[c]); - - for(y=0; y<CELLH; y++) - for(x=0; x<width[c]; x++) - nb += stock_bits(font[c][y][x]&3, 2); - nb += flush_bits(); - - printf("\n"); - - return nb; -} - -char *tag = "(c) 2008 Stanislaw Skowronek"; - -int main(int argc, char *argv[]) -{ - FILE *f; - int c, p[256], n = 0; - - memset(p, 0, 256*4); - - f = fopen("font.bin", "r"); - fread(&xsize, 1, 1, f); - fread(&ysize, 1, 1, f); - fread(&base, 1, 1, f); - fread(&top, 1, 1, f); - fread(width, 1, 256, f); - fread(font, CELLW*CELLH, 256, f); - fclose(f); - - printf("#ifndef FONT_H_CHECK\n"); - printf("#define FONT_H_CHECK\n"); - - printf("#define FONT_H %d\n", ysize); - - printf("#ifdef INCLUDE_FONTDATA\n"); - - printf("char font_data[] = {\n"); - for(c=0; c<256; c++) { - p[c] = n; - n += save_char(c); - } - printf("};\n"); - - printf("short font_ptrs[] = {\n"); - for(c=0; c<256; c++) { - if(!(c%8)) - printf(" "); - printf("0x%04X,", p[c]); - if((c%8)==7) - printf("\n"); - else - printf(" "); - } - printf("};\n"); - - printf("#endif\n#endif\n"); - - return 0; -} - -#endif diff --git a/font/unpacker.c b/font/unpacker.c deleted file mode 100644 index d2df723..0000000 --- a/font/unpacker.c +++ /dev/null @@ -1,113 +0,0 @@ -#ifdef FONTEDITOR - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <math.h> - -#define INCLUDE_FONTDATA - -#include "font.h" - -#define CELLW 12 -#define CELLH 10 - -char xsize=CELLW, ysize=CELLH; -char base=7, top=2; -char font[256][CELLH][CELLW]; -char width[256]; - -int bits_n = 0, bits_a = 0; -int flush_bits(void) -{ - if(bits_n) { - bits_a >>= 8-bits_n; - printf("0x%02X, ", bits_a); - bits_a = 0; - bits_n = 0; - return 1; - } - return 0; -} -int stock_bits(int b, int nb) -{ - bits_a >>= nb; - bits_a |= b << (8-nb); - bits_n += nb; - if(bits_n >= 8) { - printf("0x%02X, ", bits_a); - bits_a = 0; - bits_n = 0; - return 1; - } - return 0; -} - -int save_char(int c) -{ - int nb = 1; - int x, y; - - if(!width[c]) - return 0; - - printf(" 0x%02X, ", width[c]); - - for(y=0; y<CELLH; y++) - for(x=0; x<width[c]; x++) - nb += stock_bits(font[c][y][x]&3, 2); - nb += flush_bits(); - - printf("\n"); - - return nb; -} - -void load_char(int c) -{ - unsigned char *start = font_data + font_ptrs[c]; - int x, y, w, b; - - w = *(start ++); - - if(!w) - return; - - b = 0; - for(y=0; y<CELLH; y++) - for(x=0; x<w; x++) { - font[c][y][x] = ((*start) >> b) & 3; - b += 2; - if(b >= 8) { - start ++; - b = 0; - } - } - - width[c] = w; -printf("%02x: %d\n", c, w); -} - -char *tag = "(c) 2011 Stanislaw Skowronek"; - -int main(int argc, char *argv[]) -{ - FILE *f; - int i; - - for(i=0; i<sizeof(font_ptrs)/sizeof(short); i++) - load_char(i); - - f = fopen("font.bin", "w"); - fwrite(&xsize, 1, 1, f); - fwrite(&ysize, 1, 1, f); - fwrite(&base, 1, 1, f); - fwrite(&top, 1, 1, f); - fwrite(width, 1, 256, f); - fwrite(font, CELLW*CELLH, 256, f); - fclose(f); - - return 0; -} - -#endif |
