indie-raster 0.0.6 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/indie-raster.gemspec +1 -1
- data/make.sh +2 -0
- data/src-c/canvas.c +28 -0
- data/src-c/canvas.h +2 -0
- data/src-c/commands.c +10 -0
- data/src-c/commands.h +1 -0
- data/src-ruby/indie-raster.rb +8 -2
- data/test/expected.pbm +0 -0
- data/test/expected.ppm +4 -0
- data/test/test.rb +35 -0
- data/test/zebra.pbm +0 -0
- metadata +6 -2
data/.gitignore
CHANGED
data/indie-raster.gemspec
CHANGED
data/make.sh
CHANGED
data/src-c/canvas.c
CHANGED
@@ -60,6 +60,11 @@ void Canvas_writeP4(Canvas *c, FILE *f) {
|
|
60
60
|
}
|
61
61
|
|
62
62
|
|
63
|
+
void Canvas_writeP6(Canvas *c, FILE *f) {
|
64
|
+
Canvas_writeSubrectP6(c, f, 0, 0, c->w, c->h);
|
65
|
+
}
|
66
|
+
|
67
|
+
|
63
68
|
void Canvas_writeSubrectP4(Canvas *c, FILE *f, long x, long y, long w, long h) {
|
64
69
|
if (c->bpp == 1) {
|
65
70
|
fprintf(f, "P4\n%ld %ld\n", w, h);
|
@@ -71,6 +76,29 @@ void Canvas_writeSubrectP4(Canvas *c, FILE *f, long x, long y, long w, long h) {
|
|
71
76
|
}
|
72
77
|
|
73
78
|
|
79
|
+
void Canvas_writeSubrectP6(Canvas *c, FILE *f, long x0, long y0, long w, long h) {
|
80
|
+
long pos, x, y;
|
81
|
+
if (c->bpp == 1) {
|
82
|
+
fprintf(f, "P6\n%ld %ld\n255\n", w, h);
|
83
|
+
for (y = y0; y < (h + y0); y++) {
|
84
|
+
if (y < c->h) {
|
85
|
+
for (x = x0; x < (w + x0); x++) {
|
86
|
+
if (y < c->h) {
|
87
|
+
pos = (y * (c->w)) + x;
|
88
|
+
fputc(c->pixels[pos], f);
|
89
|
+
fputc(c->pixels[pos], f);
|
90
|
+
fputc(c->pixels[pos], f);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
}
|
96
|
+
else {
|
97
|
+
// HANDLE
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
|
74
102
|
void Canvas_drawOnto(Canvas *src, Canvas *dest, long x0, long y0) {
|
75
103
|
|
76
104
|
long n;
|
data/src-c/canvas.h
CHANGED
@@ -23,7 +23,9 @@ Canvas* Canvas_readImage(FILE *f);
|
|
23
23
|
|
24
24
|
void Canvas_free(Canvas **c);
|
25
25
|
void Canvas_writeP4(Canvas *c, FILE *f);
|
26
|
+
void Canvas_writeP6(Canvas *c, FILE *f);
|
26
27
|
void Canvas_writeSubrectP4(Canvas *c, FILE *f, long x, long y, long w, long h);
|
28
|
+
void Canvas_writeSubrectP6(Canvas *c, FILE *f, long x, long y, long w, long h);
|
27
29
|
void Canvas_drawOnto(Canvas *src, Canvas *dest, long x0, long y0);
|
28
30
|
|
29
31
|
#endif
|
data/src-c/commands.c
CHANGED
@@ -28,6 +28,10 @@ void run_commands(Session *s, FILE *f, FILE *outfile) {
|
|
28
28
|
long srcId = atol(strtok(NULL, " \t\n"));
|
29
29
|
exportP4(s, srcId, outfile);
|
30
30
|
}
|
31
|
+
else if (strcmp(tok, "exportP6") == 0) {
|
32
|
+
long srcId = atol(strtok(NULL, " \t\n"));
|
33
|
+
exportP6(s, srcId, outfile);
|
34
|
+
}
|
31
35
|
else if (strcmp(tok, "loadImage") == 0) {
|
32
36
|
long destId = atol(strtok(NULL, " \t\n"));
|
33
37
|
long size = atol(strtok(NULL, " \t\n"));
|
@@ -79,6 +83,12 @@ void exportP4(Session *s, long srcId, FILE *outfile) {
|
|
79
83
|
}
|
80
84
|
|
81
85
|
|
86
|
+
void exportP6(Session *s, long srcId, FILE *outfile) {
|
87
|
+
Canvas *c = Session_getCanvas(s, srcId);
|
88
|
+
Canvas_writeP6(c, outfile);
|
89
|
+
}
|
90
|
+
|
91
|
+
|
82
92
|
void loadImage(Session *s, long destId, long size, FILE *f) {
|
83
93
|
Canvas *c = Canvas_readImage(f);
|
84
94
|
Session_setCanvas(s, destId, c);
|
data/src-c/commands.h
CHANGED
@@ -17,6 +17,7 @@
|
|
17
17
|
void run_commands(Session *s, FILE *f, FILE *outfile);
|
18
18
|
void createBlank(Session *s, long destId, long w, long h);
|
19
19
|
void exportP4(Session *s, long srcId, FILE *outfile);
|
20
|
+
void exportP6(Session *s, long srcId, FILE *outfile);
|
20
21
|
void loadImage(Session *s, long destId, long size, FILE *f);
|
21
22
|
void loadFont(Session *s, long destId, long size, FILE *f);
|
22
23
|
void drawText(Session *s, long destId, long x, long y, long fontId, long numChars, FILE *f);
|
data/src-ruby/indie-raster.rb
CHANGED
@@ -81,10 +81,16 @@ class IndieRasterSession
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def exportP4(opt = {})
|
84
|
+
export 'exportP4', opt
|
85
|
+
end
|
86
|
+
|
87
|
+
def exportP6(opt = {})
|
88
|
+
export 'exportP6', opt
|
89
|
+
end
|
84
90
|
|
85
|
-
|
91
|
+
def export(command, opt)
|
86
92
|
|
87
|
-
input = @c.join
|
93
|
+
input = @c.join('') + "#{command} #{opt[:id] or 1}\n"
|
88
94
|
|
89
95
|
tmppath = opt[:commands_temp_path]
|
90
96
|
if tmppath
|
data/test/expected.pbm
ADDED
Binary file
|