@@ 44,6 44,12 @@ struct GlyphInfo{
};
+struct RawImage{
+ char chan[12], minx[12], miny[12], maxx[12], maxy[12];
+ uchar data[];
+};
+
+
uint fwidth, nglyphs, glyphlen, glyphedge, baseline;
uchar setconv, donaive, doholes;
@@ 52,6 58,7 @@ struct MapFile *mapfiles, *lastmf;
uchar wasmferr, wasreaderr;
struct GlyphInfo *glyphs;
+struct RawImage *glyphbuf;
void
@@ 371,6 378,28 @@ loadwidths(Biobuf *b, char *file)
}
}
+void
+allocrawimage(void)
+{
+ char buf[13];
+ uint imglen;
+
+ /* cols * rows */
+ imglen = glyphedge * nglyphs*fwidth;
+ glyphbuf = malloc(sizeof(struct RawImage) + imglen);
+
+ memcpy(glyphbuf->chan, " k1 ", 12);
+ memcpy(glyphbuf->minx, " 0 ", 12);
+ memcpy(glyphbuf->miny, " 0 ", 12);
+
+ snprint(buf, 12, "%11d ", nglyphs*fwidth*8);
+ memcpy(glyphbuf->maxx, buf, 11);
+ snprint(buf, 12, "%11d ", glyphedge);
+ memcpy(glyphbuf->maxy, buf, 11);
+
+ memset(glyphbuf->data, 0, imglen);
+}
+
uchar
testscanline(uchar *bitmap, int rowlen)
{
@@ 402,6 431,19 @@ parseglyph(uchar *bitmap, struct GlyphInfo *ginfo, uint *botfreqs)
ginfo->top = top; ginfo->bottom = bot;
}
void
+storeglyph(uint i, uchar *bitmap)
+{
+ uint y, x;
+ ulong dstidx, srcidx;
+ for(x = 0; x < fwidth; x++){
+ for(y = 0; y < glyphedge; y++){
+ dstidx = (i*fwidth)+x+(y*fwidth*nglyphs);
+ srcidx = y+(x*glyphedge);
+ glyphbuf->data[dstidx] = bitmap[srcidx];
+ }
+ }
+}
+void
readglyphs(Biobuf *b, uint *botfreqs)
{
uint i;
@@ 417,6 459,7 @@ readglyphs(Biobuf *b, uint *botfreqs)
if(n != glyphlen)
sysfatal("unexpected eof");
parseglyph(bitmap, glyphs+i, botfreqs);
+ storeglyph(i, bitmap);
}
free(bitmap);
@@ 449,7 492,9 @@ loadufx(char *infile)
glyphs = malloc(nglyphs * sizeof(struct GlyphInfo));
b = Bopen(infile, OREAD);
-
+
+ allocrawimage();
+
loadwidths(b, infile);
loadglyphs(b);
@@ 519,4 564,8 @@ main(int argc, char **argv)
sysfatal("-b: baseline must be in range 1-width*8");
loadufx(infile);
+
+ int fd = create(outdir, OWRITE, 0644);
+ write(fd, glyphbuf, sizeof(struct RawImage) + (glyphedge*nglyphs*fwidth));
+ close(fd);
}