annotate TOOLS/subfont-c/subfont.c @ 17100:29760118597b

fix mplayer.c:509: warning: implicit declaration of function 'free_osd_list'
author rathann
date Mon, 05 Dec 2005 01:34:13 +0000
parents c304e5836276
children 3e4ed47265d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1 /*
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
2 * Renders antialiased fonts for mplayer using freetype library.
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
3 * Should work with TrueType, Type1 and any other font supported by libfreetype.
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
4 * Can generate font.desc for any encoding.
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
5 *
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
6 *
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
7 * Artur Zaprzala <zybi@fanthom.irc.pl>
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
8 *
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
9 */
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
10
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
11 #include <stdio.h>
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
12 #include <stdlib.h>
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
13 #include <iconv.h>
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
14 #include <math.h>
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
15 #include <string.h>
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
16 #include <libgen.h>
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
17
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
18
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
19 #ifndef OLD_FREETYPE2
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
20 #include <ft2build.h>
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
21 #include FT_FREETYPE_H
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
22 #include FT_GLYPH_H
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
23 #else /* freetype 2.0.1 */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
24 #include <freetype/freetype.h>
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
25 #include <freetype/ftglyph.h>
1677
1bf2c3dbc36e Resolved endianess issues.
zybi
parents: 1675
diff changeset
26 #endif
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
27
1677
1bf2c3dbc36e Resolved endianess issues.
zybi
parents: 1675
diff changeset
28
17014
c304e5836276 Unify include path handling by adding $(MPROOT) to CFLAGS.
diego
parents: 13186
diff changeset
29 #include "bswap.h"
c304e5836276 Unify include path handling by adding $(MPROOT) to CFLAGS.
diego
parents: 13186
diff changeset
30 #include "osdep/timer.h"
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
31
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
32 #ifndef DEBUG
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
33 #define DEBUG 0
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
34 #endif
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
35
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
36
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
37 //// default values
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
38 char *encoding = "iso-8859-1"; /* target encoding */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
39 char *charmap = "ucs-4"; /* font charmap encoding, I hope ucs-4 is always big endian */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
40 /* gcc 2.1.3 doesn't support ucs-4le, but supports ucs-4 (==ucs-4be) */
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
41 float ppem = 22; /* font size in pixels */
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
42
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
43 double radius = 2; /* blur radius */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
44 double thickness = 1.5; /* outline thickness */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
45
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
46 char* font_desc = "font.desc";
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
47 //char* font_desc = "/dev/stdout";
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
48
4935
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
49 char *outdir = ".";
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
50
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
51 //// constants
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
52 int const colors = 256;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
53 int const maxcolor = 255;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
54 unsigned const base = 256;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
55 unsigned const first_char = 33;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
56 #define max_charset_size 60000
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
57 //int const max_charset_size = 256;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
58 unsigned charset_size = 0;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
59
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
60 ////
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
61 char *command;
1506
94d929f91b06 return value of iconv fixed for glibc 2.1.3, using strrchr instead of basename, as basename is buggy
arpi
parents: 1505
diff changeset
62 char *encoding_name;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
63 char *font_path;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
64 //char *font_metrics;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
65 int append_mode = 0;
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
66 int unicode_desc = 0;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
67
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
68 unsigned char *bbuffer, *abuffer;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
69 int width, height;
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
70 int padding;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
71 static FT_ULong charset[max_charset_size]; /* characters we want to render; Unicode */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
72 static FT_ULong charcodes[max_charset_size]; /* character codes in 'encoding' */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
73 iconv_t cd; // iconv conversion descriptor
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
74
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
75
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
76
13186
c70e7ad9ef7c fix overcomplicated macros and a few warnings
rathann
parents: 12860
diff changeset
77 #define eprintf(...) fprintf(stderr, ##__VA_ARGS__)
c70e7ad9ef7c fix overcomplicated macros and a few warnings
rathann
parents: 12860
diff changeset
78 #define ERROR(msg, ...) eprintf("%s: error: " msg "\n", command, ##__VA_ARGS__),exit(1)
c70e7ad9ef7c fix overcomplicated macros and a few warnings
rathann
parents: 12860
diff changeset
79 #define WARNING(msg, ...) eprintf("%s: warning: " msg "\n", command, ##__VA_ARGS__)
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
80
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
81 #define f266ToInt(x) (((x)+32)>>6) // round fractional fixed point number to integer
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
82 // coordinates are in 26.6 pixels (i.e. 1/64th of pixels)
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
83 #define f266CeilToInt(x) (((x)+63)>>6) // ceiling
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
84 #define f266FloorToInt(x) ((x)>>6) // floor
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
85 #define f1616ToInt(x) (((x)+0x8000)>>16) // 16.16
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
86 #define floatTof266(x) ((int)((x)*(1<<6)+0.5))
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
87
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
88 #define ALIGN(x) (((x)+7)&~7) // 8 byte align
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
89
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
90
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
91
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
92 void paste_bitmap(FT_Bitmap *bitmap, int x, int y) {
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
93 int drow = x+y*width;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
94 int srow = 0;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
95 int sp, dp, w, h;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
96 if (bitmap->pixel_mode==ft_pixel_mode_mono)
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
97 for (h = bitmap->rows; h>0; --h, drow+=width, srow+=bitmap->pitch)
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
98 for (w = bitmap->width, sp=dp=0; w>0; --w, ++dp, ++sp)
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
99 bbuffer[drow+dp] = (bitmap->buffer[srow+sp/8] & (0x80>>(sp%8))) ? 255:0;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
100 else
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
101 for (h = bitmap->rows; h>0; --h, drow+=width, srow+=bitmap->pitch)
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
102 for (w = bitmap->width, sp=dp=0; w>0; --w, ++dp, ++sp)
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
103 bbuffer[drow+dp] = bitmap->buffer[srow+sp];
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
104 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
105
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
106
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
107 void write_header(FILE *f) {
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
108 static unsigned char header[800] = "mhwanh";
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
109 int i;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
110 header[7] = 4;
5928
48e91dc9534b .raw width>=65536 support by Georgi Georgiev <chutz@chubaka.homeip.net>
arpi
parents: 4935
diff changeset
111 if (width < 0x10000) { // are two bytes enough for the width?
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
112 header[8] = width>>8; header[9] = (unsigned char)width;
5928
48e91dc9534b .raw width>=65536 support by Georgi Georgiev <chutz@chubaka.homeip.net>
arpi
parents: 4935
diff changeset
113 } else { // store width using 4 bytes at the end of the header
48e91dc9534b .raw width>=65536 support by Georgi Georgiev <chutz@chubaka.homeip.net>
arpi
parents: 4935
diff changeset
114 header[8] = header[9] = 0;
48e91dc9534b .raw width>=65536 support by Georgi Georgiev <chutz@chubaka.homeip.net>
arpi
parents: 4935
diff changeset
115 header[28] = (width >> 030) & 0xFF;
48e91dc9534b .raw width>=65536 support by Georgi Georgiev <chutz@chubaka.homeip.net>
arpi
parents: 4935
diff changeset
116 header[29] = (width >> 020) & 0xFF;
48e91dc9534b .raw width>=65536 support by Georgi Georgiev <chutz@chubaka.homeip.net>
arpi
parents: 4935
diff changeset
117 header[30] = (width >> 010) & 0xFF;
48e91dc9534b .raw width>=65536 support by Georgi Georgiev <chutz@chubaka.homeip.net>
arpi
parents: 4935
diff changeset
118 header[31] = (width ) & 0xFF;
48e91dc9534b .raw width>=65536 support by Georgi Georgiev <chutz@chubaka.homeip.net>
arpi
parents: 4935
diff changeset
119 }
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
120 header[10] = height>>8; header[11] = (unsigned char)height;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
121 header[12] = colors>>8; header[13] = (unsigned char)colors;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
122 for (i = 32; i<800; ++i) header[i] = (i-32)/3;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
123 fwrite(header, 1, 800, f);
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
124 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
125
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
126
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
127 void write_bitmap(void *buffer, char type) {
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
128 FILE *f;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
129 int const max_name = 128;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
130 char name[max_name];
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
131
4935
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
132 snprintf(name, max_name, "%s/%s-%c.raw", outdir, encoding_name, type);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
133 f = fopen(name, "wb");
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
134 if (f==NULL) ERROR("fopen failed.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
135 write_header(f);
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
136 fwrite(buffer, 1, width*height, f);
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
137 fclose(f);
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
138 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
139
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
140
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
141 void render() {
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
142 FT_Library library;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
143 FT_Face face;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
144 FT_Error error;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
145 FT_Glyph *glyphs;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
146 FT_BitmapGlyph glyph;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
147 FILE *f;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
148 int const load_flags = FT_LOAD_DEFAULT | FT_LOAD_NO_HINTING;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
149 int pen_x = 0, pen_xa;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
150 int ymin = INT_MAX, ymax = INT_MIN;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
151 int i, uni_charmap = 1;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
152 int baseline, space_advance = 20;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
153 int glyphs_count = 0;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
154
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
155
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
156 /* initialize freetype */
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
157 error = FT_Init_FreeType(&library);
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
158 if (error) ERROR("Init_FreeType failed.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
159 error = FT_New_Face(library, font_path, 0, &face);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
160 if (error) ERROR("New_Face failed. Maybe the font path `%s' is wrong.", font_path);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
161
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
162 /*
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
163 if (font_metrics) {
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
164 error = FT_Attach_File(face, font_metrics);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
165 if (error) WARNING("FT_Attach_File failed.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
166 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
167 */
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
168
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
169
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
170 #if 0
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
171 /************************************************************/
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
172 eprintf("Font encodings:\n");
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
173 for (i = 0; i<face->num_charmaps; ++i)
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
174 eprintf("'%.4s'\n", (char*)&face->charmaps[i]->encoding);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
175
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
176 //error = FT_Select_Charmap(face, ft_encoding_unicode);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
177 //error = FT_Select_Charmap(face, ft_encoding_adobe_standard);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
178 //error = FT_Select_Charmap(face, ft_encoding_adobe_custom);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
179 //error = FT_Set_Charmap(face, face->charmaps[1]);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
180 //if (error) WARNING("FT_Select_Charmap failed.");
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
181 #endif
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
182
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
183
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
184 #if 0
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
185 /************************************************************/
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
186 if (FT_HAS_GLYPH_NAMES(face)) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
187 int const max_gname = 128;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
188 char gname[max_gname];
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
189 for (i = 0; i<face->num_glyphs; ++i) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
190 FT_Get_Glyph_Name(face, i, gname, max_gname);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
191 eprintf("%02x `%s'\n", i, gname);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
192 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
193
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
194 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
195 #endif
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
196
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
197
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
198 if (face->charmap==NULL || face->charmap->encoding!=ft_encoding_unicode) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
199 WARNING("Unicode charmap not available for this font. Very bad!");
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
200 uni_charmap = 0;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
201 error = FT_Set_Charmap(face, face->charmaps[0]);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
202 if (error) WARNING("No charmaps! Strange.");
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
203 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
204
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
205
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
206
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
207 /* set size */
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
208 if (FT_IS_SCALABLE(face)) {
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
209 error = FT_Set_Char_Size(face, floatTof266(ppem), 0, 0, 0);
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
210 if (error) WARNING("FT_Set_Char_Size failed.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
211 } else {
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
212 int j = 0;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
213 int jppem = face->available_sizes[0].height;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
214 /* find closest size */
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
215 for (i = 0; i<face->num_fixed_sizes; ++i) {
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
216 if (fabs(face->available_sizes[i].height - ppem) < abs(face->available_sizes[i].height - jppem)) {
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
217 j = i;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
218 jppem = face->available_sizes[i].height;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
219 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
220 }
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
221 WARNING("Selected font is not scalable. Using ppem=%i.", face->available_sizes[j].height);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
222 error = FT_Set_Pixel_Sizes(face, face->available_sizes[j].width, face->available_sizes[j].height);
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
223 if (error) WARNING("FT_Set_Pixel_Sizes failed.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
224 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
225
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
226
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
227 if (FT_IS_FIXED_WIDTH(face))
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
228 WARNING("Selected font is fixed-width.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
229
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
230
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
231 /* compute space advance */
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
232 error = FT_Load_Char(face, ' ', load_flags);
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
233 if (error) WARNING("spacewidth set to default.");
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
234 else space_advance = f266ToInt(face->glyph->advance.x);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
235
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
236
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
237 /* create font.desc */
4935
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
238 {
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
239 int const max_name = 128;
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
240 char name[max_name];
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
241
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
242 snprintf(name, max_name, "%s/%s", outdir, font_desc);
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
243 f = fopen(name, append_mode ? "a":"w");
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
244 }
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
245 if (f==NULL) ERROR("fopen failed.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
246
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
247
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
248 /* print font.desc header */
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
249 if (append_mode) {
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
250 fprintf(f, "\n\n# ");
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
251 } else {
12860
03d3ab9f6400 embarassing typo
diego
parents: 10422
diff changeset
252 fprintf(f, "# This file was generated with subfont for MPlayer.\n"
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
253 "# Subfont by Artur Zaprzala <zybi@fanthom.irc.pl>.\n\n");
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
254 fprintf(f, "[info]\n");
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
255 }
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
256
10422
6c2523d7f03b putting blur and outline to the font.desc too
alex
parents: 10211
diff changeset
257 fprintf(f, "name 'Subtitle font for %s %s, \"%s%s%s\" face, size: %.1f pixels, blur: %.1f, outline: %.1f'\n",
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
258 encoding_name,
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
259 unicode_desc ? "charset, Unicode encoding":"encoding",
6788
alex
parents: 5928
diff changeset
260 face->family_name ? face->family_name : font_path,
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
261 face->style_name ? " ":"", face->style_name ? face->style_name:"",
10422
6c2523d7f03b putting blur and outline to the font.desc too
alex
parents: 10211
diff changeset
262 ppem, radius, thickness);
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
263
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
264 if (!append_mode) {
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
265 #ifdef NEW_DESC
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
266 fprintf(f, "descversion 2\n");
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
267 #else
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
268 fprintf(f, "descversion 1\n");
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
269 #endif
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
270 fprintf(f, "spacewidth %i\n", 2*padding + space_advance);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
271 #ifndef NEW_DESC
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
272 fprintf(f, "charspace %i\n", -2*padding);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
273 #endif
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7040
diff changeset
274 fprintf(f, "height %li\n", f266ToInt(face->size->metrics.height));
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
275 #ifdef NEW_DESC
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
276 fprintf(f, "ascender %i\n", f266CeilToInt(face->size->metrics.ascender));
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
277 fprintf(f, "descender %i\n", f266FloorToInt(face->size->metrics.descender));
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
278 #endif
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
279 }
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
280 fprintf(f, "\n[files]\n");
1506
94d929f91b06 return value of iconv fixed for glibc 2.1.3, using strrchr instead of basename, as basename is buggy
arpi
parents: 1505
diff changeset
281 fprintf(f, "alpha %s-a.raw\n", encoding_name);
94d929f91b06 return value of iconv fixed for glibc 2.1.3, using strrchr instead of basename, as basename is buggy
arpi
parents: 1505
diff changeset
282 fprintf(f, "bitmap %s-b.raw\n", encoding_name);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
283 fprintf(f, "\n[characters]\n");
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
284
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
285
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
286 // render glyphs, compute bitmap size and [characters] section
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
287 glyphs = (FT_Glyph*)malloc(charset_size*sizeof(FT_Glyph*));
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
288 for (i= 0; i<charset_size; ++i) {
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
289 FT_GlyphSlot slot;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
290 FT_ULong character, code;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
291 FT_UInt glyph_index;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
292 FT_BBox bbox;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
293
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
294 character = charset[i];
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
295 code = charcodes[i];
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
296
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
297 // get glyph index
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
298 if (character==0)
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
299 glyph_index = 0;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
300 else {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
301 glyph_index = FT_Get_Char_Index(face, uni_charmap ? character:code);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
302 if (glyph_index==0) {
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7040
diff changeset
303 WARNING("Glyph for char 0x%02lx|U+%04lX|%c not found.", code, character,
13186
c70e7ad9ef7c fix overcomplicated macros and a few warnings
rathann
parents: 12860
diff changeset
304 code<' '||code>255 ? '.':(char)code);
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
305 continue;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
306 }
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
307 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
308
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
309 // load glyph
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
310 error = FT_Load_Glyph(face, glyph_index, load_flags);
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
311 if (error) {
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7040
diff changeset
312 WARNING("FT_Load_Glyph 0x%02x (char 0x%02lx|U+%04lX) failed.", glyph_index, code, character);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
313 continue;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
314 }
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
315 slot = face->glyph;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
316
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
317 // render glyph
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
318 if (slot->format != ft_glyph_format_bitmap) {
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
319 error = FT_Render_Glyph(slot, ft_render_mode_normal);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
320 if (error) {
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7040
diff changeset
321 WARNING("FT_Render_Glyph 0x%04x (char 0x%02lx|U+%04lX) failed.", glyph_index, code, character);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
322 continue;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
323 }
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
324 }
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
325
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
326 // extract glyph image
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
327 error = FT_Get_Glyph(slot, (FT_Glyph*)&glyph);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
328 if (error) {
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7040
diff changeset
329 WARNING("FT_Get_Glyph 0x%04x (char 0x%02lx|U+%04lX) failed.", glyph_index, code, character);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
330 continue;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
331 }
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
332 glyphs[glyphs_count++] = (FT_Glyph)glyph;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
333
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
334 #ifdef NEW_DESC
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
335 // max height
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
336 if (glyph->bitmap.rows > height) height = glyph->bitmap.rows;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
337
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
338 // advance pen
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
339 pen_xa = pen_x + glyph->bitmap.width + 2*padding;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
340
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
341 // font.desc
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
342 fprintf(f, "0x%04x %i %i %i %i %i %i;\tU+%04X|%c\n", unicode_desc ? character:code,
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
343 pen_x, // bitmap start
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
344 glyph->bitmap.width + 2*padding, // bitmap width
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
345 glyph->bitmap.rows + 2*padding, // bitmap height
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
346 glyph->left - padding, // left bearing
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
347 glyph->top + padding, // top bearing
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
348 f266ToInt(slot->advance.x), // advance
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
349 character, code<' '||code>255 ? '.':code);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
350 #else
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
351 // max height
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
352 if (glyph->top > ymax) {
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
353 ymax = glyph->top;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
354 //eprintf("%3i: ymax %i (%c)\n", code, ymax, code);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
355 }
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
356 if (glyph->top - glyph->bitmap.rows < ymin) {
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
357 ymin = glyph->top - glyph->bitmap.rows;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
358 //eprintf("%3i: ymin %i (%c)\n", code, ymin, code);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
359 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
360
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
361 /* advance pen */
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
362 pen_xa = pen_x + f266ToInt(slot->advance.x) + 2*padding;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
363
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
364 /* font.desc */
8451
fb88ccbc5ccc compiler warning fixes
arpi
parents: 7040
diff changeset
365 fprintf(f, "0x%04lx %i %i;\tU+%04lX|%c\n", unicode_desc ? character:code,
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
366 pen_x, // bitmap start
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
367 pen_xa-1, // bitmap end
13186
c70e7ad9ef7c fix overcomplicated macros and a few warnings
rathann
parents: 12860
diff changeset
368 character, code<' '||code>255 ? '.':(char)code);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
369 #endif
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
370 pen_x = ALIGN(pen_xa);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
371 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
372
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
373
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
374 width = pen_x;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
375 pen_x = 0;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
376 #ifdef NEW_DESC
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
377 if (height<=0) ERROR("Something went wrong. Use the source!");
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
378 height += 2*padding;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
379 #else
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
380 if (ymax<=ymin) ERROR("Something went wrong. Use the source!");
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
381 height = ymax - ymin + 2*padding;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
382 baseline = ymax + padding;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
383 #endif
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
384
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
385 // end of font.desc
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
386 if (DEBUG) eprintf("bitmap size: %ix%i\n", width, height);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
387 fprintf(f, "# bitmap size: %ix%i\n", width, height);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
388 fclose(f);
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
389
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
390 bbuffer = (unsigned char*)malloc(width*height);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
391 if (bbuffer==NULL) ERROR("malloc failed.");
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
392 memset(bbuffer, 0, width*height);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
393
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
394
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
395 /* paste glyphs */
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
396 for (i= 0; i<glyphs_count; ++i) {
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
397 glyph = (FT_BitmapGlyph)glyphs[i];
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
398 #ifdef NEW_DESC
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
399 paste_bitmap(&glyph->bitmap,
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
400 pen_x + padding,
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
401 padding);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
402
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
403 /* advance pen */
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
404 pen_x += glyph->bitmap.width + 2*padding;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
405 #else
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
406 paste_bitmap(&glyph->bitmap,
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
407 pen_x + padding + glyph->left,
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
408 baseline - glyph->top);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
409
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
410 /* advance pen */
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
411 pen_x += f1616ToInt(glyph->root.advance.x) + 2*padding;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
412 #endif
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
413 pen_x = ALIGN(pen_x);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
414
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
415 FT_Done_Glyph((FT_Glyph)glyph);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
416 }
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
417 free(glyphs);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
418
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
419
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
420 error = FT_Done_FreeType(library);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
421 if (error) ERROR("FT_Done_FreeType failed.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
422 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
423
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
424
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
425 /* decode from 'encoding' to unicode */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
426 FT_ULong decode_char(char c) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
427 FT_ULong o;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
428 char *inbuf = &c;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
429 char *outbuf = (char*)&o;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
430 int inbytesleft = 1;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
431 int outbytesleft = sizeof(FT_ULong);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
432
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
433 size_t count = iconv(cd, &inbuf, &inbytesleft, &outbuf, &outbytesleft);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
434
1677
1bf2c3dbc36e Resolved endianess issues.
zybi
parents: 1675
diff changeset
435 /* convert unicode BigEndian -> MachineEndian */
1bf2c3dbc36e Resolved endianess issues.
zybi
parents: 1675
diff changeset
436 o = be2me_32(o);
1bf2c3dbc36e Resolved endianess issues.
zybi
parents: 1675
diff changeset
437
1bf2c3dbc36e Resolved endianess issues.
zybi
parents: 1675
diff changeset
438 // if (count==-1) o = 0; // not OK, at least my iconv() returns E2BIG for all
1bf2c3dbc36e Resolved endianess issues.
zybi
parents: 1675
diff changeset
439 if (outbytesleft!=0) o = 0;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
440
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
441 /* we don't want control characters */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
442 if (o>=0x7f && o<0xa0) o = 0;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
443 return o;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
444 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
445
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
446
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
447 void prepare_charset() {
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
448 FILE *f;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
449 FT_ULong i;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
450
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
451 f = fopen(encoding, "r"); // try to read custom encoding
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
452 if (f==NULL) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
453 int count = 0;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
454 // check if ucs-4 is available
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
455 cd = iconv_open(charmap, charmap);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
456 if (cd==(iconv_t)-1) ERROR("iconv doesn't know %s encoding. Use the source!", charmap);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
457 iconv_close(cd);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
458
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
459 cd = iconv_open(charmap, encoding);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
460 if (cd==(iconv_t)-1) ERROR("Unsupported encoding `%s', use iconv --list to list character sets known on your system.", encoding);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
461
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
462 charset_size = 256 - first_char;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
463 for (i = 0; i<charset_size; ++i) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
464 charcodes[count] = i+first_char;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
465 charset[count] = decode_char(i+first_char);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
466 //eprintf("%04X U%04X\n", charcodes[count], charset[count]);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
467 if (charset[count]!=0) ++count;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
468 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
469 charcodes[count] = charset[count] = 0; ++count;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
470 charset_size = count;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
471
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
472 iconv_close(cd);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
473 } else {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
474 unsigned int character, code;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
475 int count;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
476
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
477 eprintf("Reading custom encoding from file '%s'.\n", encoding);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
478
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
479 while ((count = fscanf(f, "%x%*[ \t]%x", &character, &code)) != EOF) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
480 if (charset_size==max_charset_size) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
481 WARNING("There is no place for more than %i characters. Use the source!", max_charset_size);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
482 break;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
483 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
484 if (count==0) ERROR("Unable to parse custom encoding file.");
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
485 if (character<32) continue; // skip control characters
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
486 charset[charset_size] = character;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
487 charcodes[charset_size] = count==2 ? code : character;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
488 ++charset_size;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
489 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
490 fclose(f);
1506
94d929f91b06 return value of iconv fixed for glibc 2.1.3, using strrchr instead of basename, as basename is buggy
arpi
parents: 1505
diff changeset
491 // encoding = basename(encoding);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
492 }
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
493 if (charset_size==0) ERROR("No characters to render!");
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
494 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
495
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
496
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
497 // general outline
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
498 void outline(
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
499 unsigned char *s,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
500 unsigned char *t,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
501 int width,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
502 int height,
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
503 unsigned char *m,
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
504 int r,
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
505 int mwidth,
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
506 int msize) {
1471
00a1f4b77803 dirty fix to get it work with glibc 2.1.x, and changed blur algorithm
arpi
parents: 1470
diff changeset
507
1507
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
508 int x, y;
7018
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
509 #if 1
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
510 for (y = 0; y<height; y++) {
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
511 for (x = 0; x<width; x++) {
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
512 const int src= s[x];
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
513 if(src==0) continue;
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
514 #if 0
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
515 if(src==255 && x>0 && y>0 && x+1<width && y+1<height
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
516 && s[x-1]==255 && s[x+1]==255 && s[x-width]==255 && s[x+width]==255){
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
517 t[x + y*width]=255;
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
518 }else
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
519 #endif
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
520 {
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
521 const int x1=(x<r) ? r-x : 0;
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
522 const int y1=(y<r) ? r-y : 0;
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
523 const int x2=(x+r>=width ) ? r+width -x : 2*r+1;
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
524 const int y2=(y+r>=height) ? r+height-y : 2*r+1;
7021
d27dd694e5ea more (~40%) speedup :)
arpi
parents: 7018
diff changeset
525 register unsigned char *dstp= t + (y1+y-r)* width + x-r;
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
526 //register int *mp = m + y1 *mwidth;
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
527 register unsigned char *mp= m + msize*src + y1*mwidth;
7018
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
528 int my;
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
529
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
530 for(my= y1; my<y2; my++){
7021
d27dd694e5ea more (~40%) speedup :)
arpi
parents: 7018
diff changeset
531 // unsigned char *dstp= t + (my+y-r)* width + x-r;
d27dd694e5ea more (~40%) speedup :)
arpi
parents: 7018
diff changeset
532 // int *mp = m + my *mwidth;
d27dd694e5ea more (~40%) speedup :)
arpi
parents: 7018
diff changeset
533 register int mx;
7018
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
534 for(mx= x1; mx<x2; mx++){
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
535 // const int tmp= (src*mp[mx] + 128)>>8;
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
536 // if(dstp[mx] < tmp) dstp[mx]= tmp;
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
537 if(dstp[mx] < mp[mx]) dstp[mx]= mp[mx];
7018
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
538 }
7021
d27dd694e5ea more (~40%) speedup :)
arpi
parents: 7018
diff changeset
539 dstp+=width;
d27dd694e5ea more (~40%) speedup :)
arpi
parents: 7018
diff changeset
540 mp+=mwidth;
7018
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
541 }
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
542 }
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
543 }
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
544 s+= width;
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
545 }
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
546 #else
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
547 for (y = 0; y<height; ++y) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
548 for (x = 0; x<width; ++x, ++s, ++t) {
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
549 //if(s[0]>=192) printf("%d\n",s[0]);
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
550 if(s[0]!=255){
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
551 unsigned max = 0;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
552 unsigned *mrow = m + r;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
553 unsigned char *srow = s -r*width;
1507
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
554 int x1=(x<r)?-x:-r;
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
555 int x2=(x+r>=width)?(width-x-1):r;
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
556 int my;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
557
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
558 for (my = -r; my<=r; ++my, srow+= width, mrow+= mwidth) {
1507
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
559 int mx;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
560 if (y+my < 0) continue;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
561 if (y+my >= height) break;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
562
1507
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
563 for (mx = x1; mx<=x2; ++mx) {
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
564 unsigned v = srow[mx] * mrow[mx];
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
565 if (v>max) max = v;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
566 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
567 }
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
568 // if(!max) *t = 0; else
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
569 *t = (max + base/2) / base;
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
570 } else
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
571 *t = 255;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
572 }
1471
00a1f4b77803 dirty fix to get it work with glibc 2.1.x, and changed blur algorithm
arpi
parents: 1470
diff changeset
573 }
7018
89c0f67785d0 skip black in outline (white skip code is #if 0 as there is no speed difference)
michael
parents: 7016
diff changeset
574 #endif
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
575 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
576
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
577
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
578 // 1 pixel outline
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
579 void outline1(
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
580 unsigned char *s,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
581 unsigned char *t,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
582 int width,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
583 int height) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
584
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
585 int x, y, mx, my;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
586
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
587 for (x = 0; x<width; ++x, ++s, ++t) *t = *s;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
588 for (y = 1; y<height-1; ++y) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
589 *t++ = *s++;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
590 for (x = 1; x<width-1; ++x, ++s, ++t) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
591 unsigned v = (
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
592 s[-1-width]+
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
593 s[-1+width]+
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
594 s[+1-width]+
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
595 s[+1+width]
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
596 )/2 + (
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
597 s[-1]+
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
598 s[+1]+
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
599 s[-width]+
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
600 s[+width]+
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
601 s[0]
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
602 );
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
603 *t = v>maxcolor ? maxcolor : v;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
604 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
605 *t++ = *s++;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
606 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
607 for (x = 0; x<width; ++x, ++s, ++t) *t = *s;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
608 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
609
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
610
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
611 // gaussian blur
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
612 void blur(
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
613 unsigned char *buffer,
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
614 unsigned short *tmp2,
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
615 int width,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
616 int height,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
617 int *m,
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
618 int *m2,
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
619 int r,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
620 int mwidth,
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
621 unsigned volume) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
622
1507
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
623 int x, y;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
624
7030
michael
parents: 7028
diff changeset
625 #if 1
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
626 unsigned char *s = buffer;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
627 unsigned short *t = tmp2+1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
628 for(y=0; y<height; y++){
7040
94a56b859b04 10l patch by Jindrich Makovicka <makovick at KMLinux dot fjfi dot cvut dot cz>
michael
parents: 7030
diff changeset
629 memset(t-1, 0, (width+1)*sizeof(short));
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
630 // for(x=0; x<width+1; x++)
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
631 // t[x]= 128;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
632
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
633 for(x=0; x<r; x++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
634 const int src= s[x];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
635 if(src){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
636 register unsigned short *dstp= t + x-r;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
637 int mx;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
638 unsigned *m3= m2 + src*mwidth;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
639 for(mx=r-x; mx<mwidth; mx++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
640 dstp[mx]+= m3[mx];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
641 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
642 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
643 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
644 for(; x<width-r; x++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
645 const int src= s[x];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
646 if(src){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
647 register unsigned short *dstp= t + x-r;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
648 int mx;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
649 unsigned *m3= m2 + src*mwidth;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
650 for(mx=0; mx<mwidth; mx++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
651 dstp[mx]+= m3[mx];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
652 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
653 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
654 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
655 for(; x<width; x++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
656 const int src= s[x];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
657 if(src){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
658 register unsigned short *dstp= t + x-r;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
659 int mx;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
660 const int x2= r+width -x;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
661 const int off= src*mwidth;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
662 unsigned *m3= m2 + src*mwidth;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
663 for(mx=0; mx<x2; mx++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
664 dstp[mx]+= m3[mx];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
665 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
666 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
667 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
668 s+= width;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
669 t+= width + 1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
670 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
671
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
672 t = tmp2;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
673 for(x=0; x<width; x++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
674 for(y=0; y<r; y++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
675 unsigned short *srcp= t + y*(width+1) + 1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
676 int src= *srcp;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
677 if(src){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
678 register unsigned short *dstp= srcp - 1 + width+1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
679 const int src2= (src + 128)>>8;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
680 unsigned *m3= m2 + src2*mwidth;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
681
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
682 int mx;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
683 *srcp= 128;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
684 for(mx=r-1; mx<mwidth; mx++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
685 *dstp += m3[mx];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
686 dstp+= width+1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
687 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
688 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
689 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
690 for(; y<height-r; y++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
691 unsigned short *srcp= t + y*(width+1) + 1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
692 int src= *srcp;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
693 if(src){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
694 register unsigned short *dstp= srcp - 1 - r*(width+1);
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
695 const int src2= (src + 128)>>8;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
696 unsigned *m3= m2 + src2*mwidth;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
697
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
698 int mx;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
699 *srcp= 128;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
700 for(mx=0; mx<mwidth; mx++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
701 *dstp += m3[mx];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
702 dstp+= width+1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
703 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
704 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
705 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
706 for(; y<height; y++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
707 unsigned short *srcp= t + y*(width+1) + 1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
708 int src= *srcp;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
709 if(src){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
710 const int y2=r+height-y;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
711 register unsigned short *dstp= srcp - 1 - r*(width+1);
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
712 const int src2= (src + 128)>>8;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
713 unsigned *m3= m2 + src2*mwidth;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
714
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
715 int mx;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
716 *srcp= 128;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
717 for(mx=0; mx<y2; mx++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
718 *dstp += m3[mx];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
719 dstp+= width+1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
720 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
721 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
722 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
723 t++;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
724 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
725
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
726 t = tmp2;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
727 s = buffer;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
728 for(y=0; y<height; y++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
729 for(x=0; x<width; x++){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
730 s[x]= t[x]>>8;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
731 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
732 s+= width;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
733 t+= width + 1;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
734 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
735 #else
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
736 unsigned char *tmp = (unsigned char*)tmp2;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
737 unsigned char *s = buffer - r;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
738 unsigned char *t = tmp;
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
739
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
740 int *m_end=m+256*mwidth;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
741
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
742 for (y = 0; y<height; ++y) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
743 for (x = 0; x<width; ++x, ++s, ++t) {
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
744 unsigned sum = 65536/2;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
745 int x1 = (x<r) ? r-x:0;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
746 int x2 = (x+r>=width) ? (r+width-x):mwidth;
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
747 unsigned* mp = m + 256*x1;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
748 int mx;
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
749
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
750 for (mx = x1; mx<x2; ++mx, mp+=256) sum+= mp[s[mx]];
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
751 *t = sum>>16;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
752 }
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
753 }
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
754
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
755 tmp -= r*width;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
756 for (x = 0; x<width; ++x, ++tmp, ++buffer) {
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
757 int y1max=(r<height)?r:height;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
758 int y2min=height-r;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
759 if(y2min<y1max) y2min=y1max;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
760 s = tmp;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
761 t = buffer;
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
762 #if 0
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
763 for (y = 0; y<height; ++y, s+= width, t+= width) {
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
764 unsigned sum = 65536/2;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
765 int y1 = (y<r) ? r-y:0;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
766 int y2 = (y+r>=height) ? (r+height-y):mwidth;
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
767 register unsigned *mp = m + 256*y1;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
768 register unsigned char *smy = s + y1*width;
1507
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
769 int my;
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
770 for (my = y1; my<y2; ++my, smy+= width, mp+=256)
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
771 sum+= mp[*smy];
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
772 *t = sum>>16;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
773 }
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
774 #else
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
775 // pass 1: 0..r
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
776 for (y = 0; y<y1max; ++y, s+= width, t+= width) {
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
777 unsigned sum = 65536/2;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
778 int y1 = r-y;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
779 int my = y1;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
780 int y2 = (y+r>=height) ? (r+height-y):mwidth;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
781 unsigned char *smy = s + y1*width;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
782 unsigned* mp = m + 256*y1;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
783 for (; my<y2; ++my, smy+= width, mp+=256) sum+=mp[*smy];
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
784 *t = sum>>16;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
785 }
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
786 // pass 2: r..(height-r)
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
787 for (; y<y2min; ++y, s+= width, t+= width) {
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
788 unsigned sum = 65536/2;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
789 unsigned char *smy = s;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
790 unsigned* mp = m;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
791 // int my=0;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
792 // for (; my<mwidth; ++my, smy+=width, mp+=256) sum+=mp[*smy];
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
793 for (; mp<m_end; smy+=width, mp+=256) sum+=mp[*smy];
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
794 *t = sum>>16;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
795 }
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
796 // pass 3: (height-r)..height
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
797 for (; y<height; ++y, s+= width, t+= width) {
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
798 unsigned sum = 65536/2;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
799 int y2 = r+height-y;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
800 unsigned char *smy = s;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
801 unsigned* mp = m;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
802 int my=0;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
803 for (; my<y2; ++my, smy+= width, mp+=256) sum+=mp[*smy];
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
804 *t = sum>>16;
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
805 }
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
806 #endif
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
807 }
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
808 #endif
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
809 }
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
810
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
811
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
812 // Gaussian matrix
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
813 // Maybe for future use.
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
814 unsigned gmatrix(unsigned *m, int r, int w, double const A) {
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
815 unsigned volume = 0; // volume under Gaussian area is exactly -pi*base/A
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
816 int mx, my;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
817
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
818 for (my = 0; my<w; ++my) {
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
819 for (mx = 0; mx<w; ++mx) {
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
820 m[mx+my*w] = (unsigned)(exp(A * ((mx-r)*(mx-r)+(my-r)*(my-r))) * base + .5);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
821 volume+= m[mx+my*w];
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
822 if (DEBUG) eprintf("%3i ", m[mx+my*w]);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
823 }
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
824 if (DEBUG) eprintf("\n");
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
825 }
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
826 if (DEBUG) {
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
827 eprintf("A= %f\n", A);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
828 eprintf("volume: %i; exact: %.0f; volume/exact: %.6f\n\n", volume, -M_PI*base/A, volume/(-M_PI*base/A));
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
829 }
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
830 return volume;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
831 }
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
832
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
833
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
834 void alpha() {
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
835 unsigned int ttime;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
836 int const g_r = ceil(radius);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
837 int const o_r = ceil(thickness);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
838 int const g_w = 2*g_r+1; // matrix size
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
839 int const o_w = 2*o_r+1; // matrix size
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
840 int const o_size = o_w * o_w;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
841 double const A = log(1.0/base)/(radius*radius*2);
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
842 double volume_factor=0.0;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
843 double volume_diff;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
844
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
845 int mx, my, i;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
846 unsigned volume = 0; // volume under Gaussian area is exactly -pi*base/A
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
847
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
848 unsigned *g = (unsigned*)malloc(g_w * sizeof(unsigned));
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
849 unsigned *gt = (unsigned*)malloc(256 * g_w * sizeof(unsigned));
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
850 unsigned *gt2 = (unsigned*)malloc(256 * g_w * sizeof(unsigned));
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
851 unsigned *om = (unsigned*)malloc(o_w*o_w * sizeof(unsigned));
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
852 unsigned char *omt = malloc(o_size*256);
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
853 unsigned char *omtp = omt;
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
854 unsigned short *tmp = malloc((width+1)*height*sizeof(short));
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
855
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
856 if (g==NULL || gt==NULL || gt2==NULL || om==NULL || omt==NULL) ERROR("malloc failed.");
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
857
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
858 // gaussian curve with volume = 256
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
859 for (volume_diff=10000000; volume_diff>0.0000001; volume_diff*=0.5){
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
860 volume_factor+= volume_diff;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
861 volume=0;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
862 for (i = 0; i<g_w; ++i) {
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
863 g[i] = (unsigned)(exp(A * (i-g_r)*(i-g_r)) * volume_factor + .5);
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
864 volume+= g[i];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
865 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
866 if(volume>256) volume_factor-= volume_diff;
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
867 }
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
868 volume=0;
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
869 for (i = 0; i<g_w; ++i) {
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
870 g[i] = (unsigned)(exp(A * (i-g_r)*(i-g_r)) * volume_factor + .5);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
871 volume+= g[i];
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
872 if (DEBUG) eprintf("%3i ", g[i]);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
873 }
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
874
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
875 //volume *= volume;
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
876 if (DEBUG) eprintf("\n");
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
877
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
878 // gauss table:
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
879 for(mx=0;mx<g_w;mx++){
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
880 for(i=0;i<256;i++){
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
881 gt[256*mx+i] = (i*g[mx]*65536+(volume/2))/volume;
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
882 gt2[mx+i*g_w] = i*g[mx];
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
883 }
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
884 }
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
885
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
886 /* outline matrix */
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
887 for (my = 0; my<o_w; ++my) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
888 for (mx = 0; mx<o_w; ++mx) {
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
889 // antialiased circle would be perfect here, but this one is good enough
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
890 double d = thickness + 1 - sqrt((mx-o_r)*(mx-o_r)+(my-o_r)*(my-o_r));
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
891 om[mx+my*o_w] = d>=1 ? base : d<=0 ? 0 : (d*base + .5);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
892 if (DEBUG) eprintf("%3i ", om[mx+my*o_w]);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
893 }
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
894 if (DEBUG) eprintf("\n");
1471
00a1f4b77803 dirty fix to get it work with glibc 2.1.x, and changed blur algorithm
arpi
parents: 1470
diff changeset
895 }
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
896 if (DEBUG) eprintf("\n");
1474
529a65694e40 more optimization
arpi
parents: 1472
diff changeset
897
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
898 // outline table:
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
899 for(i=0;i<256;i++){
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
900 for(mx=0;mx<o_size;mx++) *(omtp++) = (i*om[mx] + (base/2))/base;
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
901 }
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
902
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
903 ttime=GetTimer();
1507
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
904 if(thickness==1.0)
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
905 outline1(bbuffer, abuffer, width, height); // FAST solid 1 pixel outline
1507
47a49d6d7132 speed optimized :)
arpi
parents: 1506
diff changeset
906 else
7022
ef9f4c1a3345 using precalculated src*om[][] table -> 25% faster.
arpi
parents: 7021
diff changeset
907 outline(bbuffer, abuffer, width, height, omt, o_r, o_w, o_size); // solid outline
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
908 //outline(bbuffer, abuffer, width, height, gm, g_r, g_w); // Gaussian outline
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
909 ttime=GetTimer()-ttime;
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
910 printf("outline: %7d us\n",ttime);
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
911
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
912 ttime=GetTimer();
7023
273e374311c6 speedup of gauss
arpi
parents: 7022
diff changeset
913 // blur(abuffer, bbuffer, width, height, g, g_r, g_w, volume);
7028
9d4273713562 40% faster blur
michael
parents: 7023
diff changeset
914 blur(abuffer, tmp, width, height, gt, gt2, g_r, g_w, volume);
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
915 ttime=GetTimer()-ttime;
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
916 printf("gauss: %7d us\n",ttime);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
917
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
918 free(g);
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
919 free(om);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
920 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
921
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
922
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
923 void usage() {
4935
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
924 printf("Usage: %s [--outdir dir] [--append] [--unicode] [--blur b] [--outline o] encoding ppem font\n", command);
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
925 printf("\n"
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
926 " Program creates 3 files: font.desc, <encoding>-a.raw, <encoding>-b.raw.\n"
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
927 "\n"
4935
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
928 " --outdir output directory to place files.\n"
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
929 " --append append results to existing font.desc, suppress info header.\n"
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
930 " --unicode use Unicode in font.desc. This will work with -utf8 option of mplayer.\n"
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
931 " --blur b specify blur radius, float.\n"
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
932 " --outline o specify outline thickness, float.\n"
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
933 " encoding must be an 8 bit encoding, like iso-8859-2, or path to custom encoding file (see README).\n"
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
934 " To list encodings available on your system use iconv --list.\n"
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
935 " ppem Font size in pixels (default 24), float.\n"
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
936 " font Font file path. Any format supported by the freetype library (*.ttf, *.pfb, ...).\n"
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
937 );
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
938 exit(1);
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
939 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
940
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
941
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
942 void parse_args(int argc, char **argv) {
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
943 int i, a = 0;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
944 double d;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
945
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
946 command = strrchr(argv[a], '/');
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
947 if (command==NULL) command = argv[a];
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
948 else ++command;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
949 ++a; --argc;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
950
4935
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
951 if (argc>=1 && strcmp(argv[a], "--outdir")==0) {
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
952 ++a; --argc;
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
953 if (argc==0) usage();
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
954
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
955 outdir = strdup(argv[a]);
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
956 ++a; --argc;
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
957 }
958bcb3b5725 --outdir added
alex
parents: 1677
diff changeset
958
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
959 if (argc>=1 && strcmp(argv[a], "--append")==0) {
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
960 append_mode = 1;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
961 ++a; --argc;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
962 }
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
963
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
964 if (argc>=1 && strcmp(argv[a], "--unicode")==0) {
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
965 unicode_desc = 1;
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
966 ++a; --argc;
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
967 }
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
968
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
969 if (argc>=1 && strcmp(argv[a], "--blur")==0) {
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
970 ++a; --argc;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
971 if (argc==0) usage();
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
972
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
973 d = atof(argv[a]);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
974 if (d>=0 && d<20) radius = d;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
975 else WARNING("using default blur radius.");
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
976 ++a; --argc;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
977 }
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
978
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
979 if (argc>=1 && strcmp(argv[a], "--outline")==0) {
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
980 ++a; --argc;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
981 if (argc==0) usage();
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
982
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
983 d = atof(argv[a]);
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
984 if (d>=0 && d<20) thickness = d;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
985 else WARNING("using default outline thickness.");
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
986 ++a; --argc;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
987 }
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
988
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
989 if (argc<3) usage();
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
990
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
991 // encoding
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
992 if (argv[a][0]!=0)
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
993 encoding = argv[a];
1506
94d929f91b06 return value of iconv fixed for glibc 2.1.3, using strrchr instead of basename, as basename is buggy
arpi
parents: 1505
diff changeset
994 encoding_name = strrchr(encoding, '/');
94d929f91b06 return value of iconv fixed for glibc 2.1.3, using strrchr instead of basename, as basename is buggy
arpi
parents: 1505
diff changeset
995 if (!encoding_name) encoding_name=encoding;
94d929f91b06 return value of iconv fixed for glibc 2.1.3, using strrchr instead of basename, as basename is buggy
arpi
parents: 1505
diff changeset
996 else ++encoding_name;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
997 ++a; --argc;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
998
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
999 // ppem
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
1000 d = atof(argv[a]);
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
1001 if (d>2.) ppem = d;
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
1002 ++a; --argc;
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
1003
1675
8ccac62ddfb7 Added --unicode switch. This is for UTF-8 encoded subtitles.
zybi
parents: 1607
diff changeset
1004 // font
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
1005 font_path = argv[a];
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
1006 ++a; --argc;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1007 }
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1008
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
1009
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1010 int main(int argc, char **argv) {
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
1011 unsigned int ttime;
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1012 parse_args(argc, argv);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
1013
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
1014 padding = ceil(radius) + ceil(thickness);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1015
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
1016 ttime=GetTimer();
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1017 prepare_charset();
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
1018 ttime=GetTimer()-ttime;
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
1019 printf("charset: %7d us\n",ttime);
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
1020
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
1021 ttime=GetTimer();
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1022 render();
7016
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
1023 ttime=GetTimer()-ttime;
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
1024 printf("render: %7d us\n",ttime);
44ce5a673be2 added gettimeofday-based profiling/timing
arpi
parents: 6788
diff changeset
1025
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
1026 write_bitmap(bbuffer, 'b');
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
1027
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
1028 abuffer = (unsigned char*)malloc(width*height);
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
1029 if (abuffer==NULL) ERROR("malloc failed.");
8765
arpi
parents: 8451
diff changeset
1030 memset(abuffer, 0, width*height);
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
1031 alpha();
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
1032 write_bitmap(abuffer, 'a');
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1033
1607
7336606415f2 Implemented new Gaussian blur algorithm, extended font.desc format, optimized for speed and memory usage.
zybi
parents: 1507
diff changeset
1034 free(bbuffer);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1035 free(abuffer);
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1036
1505
842c29861e25 upgraded to 1.0b version by Artur Zaprzala <artur.zaprzala@talex.com.pl>
arpi
parents: 1474
diff changeset
1037 // fflush(stderr);
1470
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1038 return 0;
2c7b0478db0c mplayer font-generator using FreeType 2.x by Artur Zaprzala <zybi@fanthom.irc.pl>
arpi
parents:
diff changeset
1039 }