Mercurial > mplayer.hg
comparison libass/ass_render.c @ 23179:eaed63bb5078
Update comments.
author | eugeni |
---|---|
date | Tue, 01 May 2007 15:54:00 +0000 |
parents | cfef9a468d75 |
children | 631dad12568b |
comparison
equal
deleted
inserted
replaced
23178:cfef9a468d75 | 23179:eaed63bb5078 |
---|---|
379 } | 379 } |
380 return tail; | 380 return tail; |
381 } | 381 } |
382 | 382 |
383 /** | 383 /** |
384 * \brief Render text_info_t struct into ass_image_t list | 384 * \brief Convert text_info_t struct to ass_image_t list |
385 * Rasterize glyphs and put them in glyph cache. | 385 * Splits glyphs in halves when needed (for \kf karaoke). |
386 */ | 386 */ |
387 static ass_image_t* render_text(text_info_t* text_info, int dst_x, int dst_y) | 387 static ass_image_t* render_text(text_info_t* text_info, int dst_x, int dst_y) |
388 { | 388 { |
389 int pen_x, pen_y; | 389 int pen_x, pen_y; |
390 int i; | 390 int i; |
1195 | 1195 |
1196 static void free_render_context(void) | 1196 static void free_render_context(void) |
1197 { | 1197 { |
1198 } | 1198 } |
1199 | 1199 |
1200 /** | |
1201 * \brief Get normal and outline (border) glyphs | |
1202 * \param symbol ucs4 char | |
1203 * \param info out: struct filled with extracted data | |
1204 * \param advance subpixel shift vector used for cache lookup | |
1205 * Tries to get both glyphs from cache. | |
1206 * If they can't be found, gets a glyph from font face, generates outline with FT_Stroker, | |
1207 * and add them to cache. | |
1208 * The glyphs are returned in info->glyph and info->outline_glyph | |
1209 */ | |
1200 static void get_outline_glyph(int symbol, glyph_info_t* info, FT_Vector* advance) | 1210 static void get_outline_glyph(int symbol, glyph_info_t* info, FT_Vector* advance) |
1201 { | 1211 { |
1202 int error; | 1212 int error; |
1203 glyph_hash_val_t* val; | 1213 glyph_hash_val_t* val; |
1204 glyph_hash_key_t key; | 1214 glyph_hash_key_t key; |
1250 } | 1260 } |
1251 | 1261 |
1252 static void transform_3d(FT_Vector shift, FT_Glyph* glyph, FT_Glyph* glyph2, double frx, double fry, double frz); | 1262 static void transform_3d(FT_Vector shift, FT_Glyph* glyph, FT_Glyph* glyph2, double frx, double fry, double frz); |
1253 | 1263 |
1254 /** | 1264 /** |
1255 * \brief Get normal and outline glyphs from cache (if possible) or font face | 1265 * \brief Get bitmaps for a glyph |
1256 * \param index face glyph index | 1266 * \param info glyph info |
1257 * \param symbol ucs4 char | 1267 * Tries to get glyph bitmaps from bitmap cache. |
1258 * \param info out: struct filled with extracted data | 1268 * If they can't be found, they are generated by rotating and rendering the glyph. |
1259 * \param advance advance vector of the extracted glyph | 1269 * After that, bitmaps are added to the cache. |
1260 * \return 0 on success | 1270 * They are returned in info->bm (glyph), info->bm_o (outline) and info->bm_s (shadow). |
1261 */ | 1271 */ |
1262 static void get_bitmap_glyph(glyph_info_t* info) | 1272 static void get_bitmap_glyph(glyph_info_t* info) |
1263 { | 1273 { |
1264 bitmap_hash_val_t* val; | 1274 bitmap_hash_val_t* val; |
1265 bitmap_hash_key_t* key = &info->hash_key; | 1275 bitmap_hash_key_t* key = &info->hash_key; |
1275 FT_Vector shift; | 1285 FT_Vector shift; |
1276 bitmap_hash_val_t hash_val; | 1286 bitmap_hash_val_t hash_val; |
1277 int error; | 1287 int error; |
1278 info->bm = info->bm_o = info->bm_s = 0; | 1288 info->bm = info->bm_o = info->bm_s = 0; |
1279 if (info->glyph && info->symbol != '\n' && info->symbol != 0) { | 1289 if (info->glyph && info->symbol != '\n' && info->symbol != 0) { |
1280 // calculating shift vector | 1290 // calculating rotation shift vector (from rotation origin to the glyph basepoint) |
1281 shift.x = int_to_d6(info->hash_key.shift_x); | 1291 shift.x = int_to_d6(info->hash_key.shift_x); |
1282 shift.y = int_to_d6(info->hash_key.shift_y); | 1292 shift.y = int_to_d6(info->hash_key.shift_y); |
1293 // apply rotation | |
1283 transform_3d(shift, &info->glyph, &info->outline_glyph, info->frx, info->fry, info->frz); | 1294 transform_3d(shift, &info->glyph, &info->outline_glyph, info->frx, info->fry, info->frz); |
1284 | 1295 |
1296 // render glyph | |
1285 error = glyph_to_bitmap(ass_renderer->synth_priv, | 1297 error = glyph_to_bitmap(ass_renderer->synth_priv, |
1286 info->glyph, info->outline_glyph, | 1298 info->glyph, info->outline_glyph, |
1287 &info->bm, &info->bm_o, | 1299 &info->bm, &info->bm_o, |
1288 &info->bm_s, info->be); | 1300 &info->bm_s, info->be); |
1289 if (error) | 1301 if (error) |
1290 info->symbol = 0; | 1302 info->symbol = 0; |
1291 | 1303 |
1292 // cache | 1304 // add bitmaps to cache |
1293 hash_val.bm_o = info->bm_o; | 1305 hash_val.bm_o = info->bm_o; |
1294 hash_val.bm = info->bm; | 1306 hash_val.bm = info->bm; |
1295 hash_val.bm_s = info->bm_s; | 1307 hash_val.bm_s = info->bm_s; |
1296 cache_add_bitmap(&(info->hash_key), &hash_val); | 1308 cache_add_bitmap(&(info->hash_key), &hash_val); |
1297 } | 1309 } |
1310 // deallocate glyphs | |
1298 if (info->glyph) | 1311 if (info->glyph) |
1299 FT_Done_Glyph(info->glyph); | 1312 FT_Done_Glyph(info->glyph); |
1300 if (info->outline_glyph) | 1313 if (info->outline_glyph) |
1301 FT_Done_Glyph(info->outline_glyph); | 1314 FT_Done_Glyph(info->outline_glyph); |
1302 } | 1315 } |
1934 } else if (render_context.evt_type == EVENT_POSITIONED) { | 1947 } else if (render_context.evt_type == EVENT_POSITIONED) { |
1935 render_context.clip_y0 = y2scr(render_context.clip_y0); | 1948 render_context.clip_y0 = y2scr(render_context.clip_y0); |
1936 render_context.clip_y1 = y2scr(render_context.clip_y1); | 1949 render_context.clip_y1 = y2scr(render_context.clip_y1); |
1937 } | 1950 } |
1938 | 1951 |
1939 // rotate glyphs if needed | 1952 // calculate rotation parameters |
1940 { | 1953 { |
1941 FT_Vector center; | 1954 FT_Vector center; |
1942 | 1955 |
1943 if (render_context.have_origin) { | 1956 if (render_context.have_origin) { |
1944 center.x = x2scr(render_context.org_x); | 1957 center.x = x2scr(render_context.org_x); |
1961 info->hash_key.shift_y = 0; | 1974 info->hash_key.shift_y = 0; |
1962 } | 1975 } |
1963 } | 1976 } |
1964 } | 1977 } |
1965 | 1978 |
1979 // convert glyphs to bitmaps | |
1966 for (i = 0; i < text_info.length; ++i) | 1980 for (i = 0; i < text_info.length; ++i) |
1967 get_bitmap_glyph(text_info.glyphs + i); | 1981 get_bitmap_glyph(text_info.glyphs + i); |
1968 | 1982 |
1969 event_images->top = device_y - d6_to_int(text_info.lines[0].asc); | 1983 event_images->top = device_y - d6_to_int(text_info.lines[0].asc); |
1970 event_images->height = d6_to_int(text_info.height); | 1984 event_images->height = d6_to_int(text_info.height); |