Skip to content

Commit 1faf262

Browse files
committed
Removed bitmap creating.
Created version 0.7.1
1 parent 53c3ad6 commit 1faf262

File tree

5 files changed

+12
-73
lines changed

5 files changed

+12
-73
lines changed

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@
99
0.7.0:
1010
Added injecting to webp files.
1111
Fixed crash on not existing gif file.
12+
0.7.1:
13+
Fix in Makefile for compatibility.
14+
Minor refactoring.

bmp.c

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -22,54 +22,22 @@ char *bmp_js_l(char *content, int size){
2222
unsigned int height = 1;
2323
const char _bmp_header1[18] = {0x42, 0x4d, 0x2f, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00};
2424
char sizew[4], sizeh[4];
25-
const char _bmp_header2[BMP_JS_HEADER_V - 32] = {0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x2f, 0x3d, 0x30, 0x3b, 0x0a};
25+
const char _bmp_header2[BMP_JS_HEADER_L - 32] = {0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x2f, 0x3d, 0x30, 0x3b, 0x0a};
2626
const char _bmp_footer[6] = {0x2f, 0x2f, 0x00, 0x00, 0x00, 0x00};
27-
char *buffer = (char*)malloc(BMP_JS_HEADER_V + size);
27+
char *buffer = (char*)malloc(BMP_JS_HEADER_L + size);
2828
for(int i = 0; i < 4; i++){
2929
sizew[i] = (width >> i*8) &0xff;
3030
sizeh[i] = (height >> i*8) &0xff;
3131
}
3232
memcpy(buffer, _bmp_header1, 18);
3333
memcpy(&buffer[18], sizew, 4);
3434
memcpy(&buffer[22], sizeh, 4);
35-
memcpy(&buffer[26], _bmp_header2, BMP_JS_HEADER_V - 26);
36-
memcpy(&buffer[BMP_JS_HEADER_V-6], content, size);
37-
memcpy(&buffer[BMP_JS_HEADER_V-6+size], _bmp_footer, 6);
35+
memcpy(&buffer[26], _bmp_header2, BMP_JS_HEADER_L - 26);
36+
memcpy(&buffer[BMP_JS_HEADER_L-6], content, size);
37+
memcpy(&buffer[BMP_JS_HEADER_L-6+size], _bmp_footer, 6);
3838
return buffer;
3939
}
4040

41-
char *bmp_js_m(char *content, int size){
42-
const char _bmp_header1[18] = {0x42, 0x4d, 0x2f, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7a, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00};
43-
char sizew[4], sizeh[4];
44-
unsigned int *wh = getsize(size);
45-
int width = wh[0];
46-
int height = wh[1];
47-
const char _bmp_header2[96] = {0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42, 0x47, 0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
48-
char *buffer = (char*)malloc(BMP_JS_HEADER_M + width * 3 *height + height * 9);
49-
for(int i = 0; i < 4; i++){
50-
sizew[i] = (width >> i*8) &0xff;
51-
sizeh[i] = (height >> i*8) &0xff;
52-
}
53-
memcpy(buffer, _bmp_header1, 18);
54-
memcpy(&buffer[18], sizew, 4);
55-
memcpy(&buffer[22], sizeh, 4);
56-
memcpy(&buffer[26], _bmp_header2, 96);
57-
char *chnk = chunk(content, size);
58-
memcpy(&buffer[122], createline(chnk, (width - 3) * 3), width * 3);
59-
for(int i = 1; i < height; i++){
60-
memcpy(&buffer[122 + (width * 3)*i], createline(&chnk[i*((width - 3) * 3)], (width - 3) * 3), width * 3);
61-
}
62-
return buffer;
63-
}
64-
65-
char *chunk(char *content, int size){
66-
char _chunkhead[6] = {0x2a, 0x2f, 0x3d, 0x30, 0x3b, 0x0a};
67-
char *chunks = (char*)malloc(size + 6);
68-
memcpy(chunks, _chunkhead, 6);
69-
memcpy(&chunks[6], content, size);
70-
return chunks;
71-
}
72-
7341
char *bmp_js_i(char *content, int csize, char *image, int isize){
7442
const char _bmp_header[7] = {0x42, 0x4d, 0x3d, 0x30, 0x3b, 0x2f, 0x2a};
7543
const char _bmp_header_end[BMP_JS_HEADER_I] = {0x2a, 0x2f, 0x3b};
@@ -88,19 +56,3 @@ char *bmp_filename(char *fn, int size){
8856
memcpy(&newfile[size], _bmp_ending, BMP_ENDING);
8957
return newfile;
9058
}
91-
92-
unsigned int *getsize(int size){
93-
int *wh = (int*)malloc(sizeof(int) * 2);
94-
wh[0] = (int)sqrt((double)size) + 2;
95-
wh[1] = (size / wh[0] + 2)/2 + 1;
96-
printf("%d, %dx%d\n", size, wh[0], wh[1]);
97-
return wh;
98-
}
99-
100-
char *createline(char *line, int len){
101-
char _line_end[9] = {0x2f, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2a, 0x2f};
102-
char *newline = (char*)malloc(len + 9);
103-
memcpy(newline, line, len);
104-
memcpy(&newline[len], _line_end, 9);
105-
return newline;
106-
}

bmp.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,15 @@ License: GNU GENERAL PUBLIC LICENSE Version 3
1212

1313
#include <stdlib.h>
1414
#include <string.h>
15-
#include <math.h>
16-
#include <stdio.h>
1715

1816
#define BMP_JS_HEADER 139
19-
#define BMP_JS_HEADER_V 134
20-
#define BMP_JS_HEADER_M 96
17+
#define BMP_JS_HEADER_L 134
2118
#define BMP_JS_HEADER_I 3
2219
#define BMP_ENDING 5
2320

2421
char *bmp_js(char*, int);
2522
char *bmp_js_l(char*, int);
26-
char *bmp_js_m(char*, int);
2723
char *bmp_js_i(char*, int, char*, int);
2824
char *bmp_filename(char*, int);
29-
unsigned int *getsize(int);
30-
char *createline(char*, int);
31-
char *chunk(char*, int);
3225

3326
#endif

main.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,7 @@ int main(int argc, char *argv[]){
9797
if(strcmp(argv[3], "-l") == 0){
9898
outbuf = bmp_js_l(buf, filesize);
9999
out = fopen(bmp_filename(argv[2], getlen(argv[2])), "wb");
100-
for(int i = 0; i < filesize + BMP_JS_HEADER_V; i++){
101-
fprintf(out, "%c", outbuf[i]);
102-
}
103-
}else if(strcmp(argv[3], "-m") == 0){
104-
outbuf = bmp_js_m(buf, filesize);
105-
out = fopen(bmp_filename(argv[2], getlen(argv[2])), "wb");
106-
int *mapsize = getsize(filesize);
107-
printf("%dx%d", mapsize[0], mapsize[1]);
108-
int outsize = mapsize[0] * 3 * mapsize[1] + BMP_JS_HEADER_M;
109-
for(int i = 0; i < outsize; i++){
100+
for(int i = 0; i < filesize + BMP_JS_HEADER_L; i++){
110101
fprintf(out, "%c", outbuf[i]);
111102
}
112103
}else{

meta.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ License: GNU GENERAL PUBLIC LICENSE Version 3
88

99

1010
#define VERSION_MAJ 0
11-
#define VERSION_MIN 8
12-
#define VERSION_FIX 0
11+
#define VERSION_MIN 7
12+
#define VERSION_FIX 1
1313
#define AUTHOR "jklmnn"
1414
#define HOMEPAGE "http://jklmnn.de/imagejs"
1515
#define LICENSE "GPLv3"

0 commit comments

Comments
 (0)