10 int read_aaf(FILE * in, struct aaf * _aaf)
18 elements = fread(_aaf, sizeof(struct aaf), 1, in);
20 perror("Unable to correctly read input file");
24 if (strncmp("AAFF", _aaf->signature, 4) != 0) {
25 fprintf(stderr, "Invalid sigature of input file\n");
29 _aaf->max_h = be16toh(_aaf->max_h);
30 _aaf->gap_h = be16toh(_aaf->gap_h);
31 _aaf->space_width = be16toh(_aaf->space_width);
32 _aaf->gap_v = be16toh(_aaf->gap_v);
34 for (i = 0; i < AAF_GLYPH_MAX; i++) {
35 _aaf->glyphs[i].w = be16toh(_aaf->glyphs[i].w);
36 _aaf->glyphs[i].h = be16toh(_aaf->glyphs[i].h);
37 _aaf->glyphs[i].off = be32toh(_aaf->glyphs[i].off);
43 void free_aaf_glyph_data(struct aaf_glyph_data ** data)
49 for (i = 0; i < AAF_GLYPH_MAX; i++) {
51 free(data[i]->pixels);
61 struct aaf_glyph_data ** read_aaf_glyph_data(FILE * in, struct aaf * _aaf)
63 struct aaf_glyph_data ** data = NULL;
72 data = malloc(sizeof(struct aaf_glyph_data*) * AAF_GLYPH_MAX);
74 for (i = 0; i < AAF_GLYPH_MAX; i++) {
75 const struct aaf_glyph * glyph = &(_aaf->glyphs[i]);
79 if ((glyph->w * glyph->h) == 0) {
83 data[i] = malloc(sizeof(struct aaf_glyph_data));
84 if (data[i] == NULL) {
85 perror("Unable to allocate memory for glyph data");
86 free_aaf_glyph_data(data);
87 fseek(in, offset, SEEK_SET);
91 data[i]->pixels = malloc(sizeof(uint8_t) * glyph->w * glyph->h);
92 if (data[i]->pixels == NULL) {
93 perror("Unable to allocate memory for glyph pixel data");
94 free_aaf_glyph_data(data);
95 fseek(in, offset, SEEK_SET);
99 fseek(in, sizeof(struct aaf) + glyph->off, SEEK_SET);
100 fread(data[i]->pixels, sizeof(uint8_t), glyph->w * glyph->h, in);
103 fseek(in, offset, SEEK_SET);
108 int write_aaf_glyph_as_pgm(FILE * out, const struct aaf_glyph * glyph, const struct aaf_glyph_data * data)
115 assert(glyph != NULL);
116 assert(data != NULL);
118 error = fprintf(out, "%s\n%d %d\n%d\n",
126 perror("Unable to write PGM header");
130 for (h = 0; h < glyph->h; h++) {
131 for (w = 0; w < glyph->w; w++) {
132 error = fprintf(out, "%d",
133 data->pixels[h * glyph->w + w]
137 perror("Unabe to write PGM image data");
141 if (w + 1 < glyph->w) {