Skip to content

Commit

Permalink
Removed image file naming due to many missunderstandings.
Browse files Browse the repository at this point in the history
  • Loading branch information
jklmnn committed Nov 10, 2014
1 parent 94c3517 commit 1b31cad
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ Currently supported are gif and bmp.

Usage:

Run 'make' to compile and then run 'imagejs option jsfile.js imagefile'.
Run 'make' to compile and then run 'imagejs option jsfile.js'
The outcoming image file will be named like the input file + the image ending..
Options are currently bmp and gif.

Example:

`$ ./imagejs gif code.js`
will return a file named code.js.gif

Background:
-----------

Expand Down
12 changes: 12 additions & 0 deletions bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ char *bmp_js(char *content, int size){
}
return buffer;
}

char *bmp_filename(char *fn, int size){
char _bmp_ending[BMP_ENDING] = {0x2e, 0x62, 0x6d, 0x70, 0x00};
char *newfile = (char*)malloc(size + BMP_ENDING);
for(int i = 0; i < size; i++){
newfile[i] = fn[i];
}
for(int i = 0; i < BMP_ENDING; i++){
newfile[size + i] = _bmp_ending[i];
}
return newfile;
}
2 changes: 2 additions & 0 deletions bmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ License: GNU GENERAL PUBLIC LICENSE Version 3
#include <stdlib.h>

#define BMP_JS_HEADER 139
#define BMP_ENDING 5

char *bmp_js(char*, int);
char *bmp_filename(char*, int);

#endif
12 changes: 12 additions & 0 deletions gif.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,15 @@ char* gif_js(char *content, int size){
}
return buffer;
}

char *gif_filename(char *fn, int size){
char _gif_ending[GIF_ENDING] = {0x2e, 0x67, 0x69, 0x66, 0x00};
char *newfile = (char*)malloc(size + GIF_ENDING);
for(int i = 0; i < size; i++){
newfile[i] = fn[i];
}
for(int i = 0; i < GIF_ENDING; i++){
newfile[size + i] = _gif_ending[i];
}
return newfile;
}
2 changes: 2 additions & 0 deletions gif.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ License: GNU GENERAL PUBLIC LICENSE Version 3
#include <stdlib.h>

#define GIF_JS_HEADER 18
#define GIF_ENDING 5

char *gif_js(char*, int);
char *gif_filename(char*, int);

#endif
13 changes: 10 additions & 3 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ License: GNU GENERAL PUBLIC LICENSE Version 3
#include "gif.h"
#include "bmp.h"

int getlen(char* str){
int i;
for(i = 0; str[i] != 0; i++);
return i;
}

int main(int argc, char *argv[]){
if(argc < 4){
if(argc < 3){
printf("ImageJs Version 0.1\n");
printf("Usage: %s [option] [javascript file] [gif file]\n", argv[0]);
printf("Usage: %s [option] [javascript file]\n", argv[0]);
printf("Options: gif, bmp\n");
return 1;
}
Expand All @@ -25,7 +31,6 @@ int main(int argc, char *argv[]){
int filesize;
char *buf;
in = fopen(argv[2], "rb");
out = fopen(argv[3], "wb");
fseek(in, 0, SEEK_END);
filesize = ftell(in);
rewind(in);
Expand All @@ -35,12 +40,14 @@ int main(int argc, char *argv[]){
char *outbuf;
if(strcmp(argv[1], "bmp") == 0){
outbuf = bmp_js(buf, filesize);
out = fopen(bmp_filename(argv[2], getlen(argv[2])), "wb");
for(int i = 0; i < filesize + BMP_JS_HEADER; i++){
fprintf(out, "%c", outbuf[i]);
}
}
if(strcmp(argv[1], "gif") == 0){
outbuf = gif_js(buf, filesize);
out = fopen(gif_filename(argv[2], getlen(argv[2])), "wb");
for(int i = 0; i < filesize + GIF_JS_HEADER; i++){
fprintf(out, "%c", outbuf[i]);
}
Expand Down

0 comments on commit 1b31cad

Please sign in to comment.