Mercurial > mplayer.hg
comparison libass/ass_render.c @ 22213:66abe12ad374
Move conversions between 16.16, 26.6 fixed point and int, double to separate
functions. Some rounding errors are fixed along the way.
author | eugeni |
---|---|
date | Fri, 16 Feb 2007 17:49:35 +0000 |
parents | 5add218bb6c3 |
children | 218f486c544d |
comparison
equal
deleted
inserted
replaced
22212:f45084fb38dc | 22213:66abe12ad374 |
---|---|
495 int i; | 495 int i; |
496 | 496 |
497 if (text_info.length > 0) { | 497 if (text_info.length > 0) { |
498 bbox.xMin = 32000; | 498 bbox.xMin = 32000; |
499 bbox.xMax = -32000; | 499 bbox.xMax = -32000; |
500 bbox.yMin = - (text_info.lines[0].asc >> 6) + text_info.glyphs[0].pos.y; | 500 bbox.yMin = - d6_to_int(text_info.lines[0].asc) + text_info.glyphs[0].pos.y; |
501 bbox.yMax = ((text_info.height - text_info.lines[0].asc) >> 6) + text_info.glyphs[0].pos.y; | 501 bbox.yMax = d6_to_int(text_info.height - text_info.lines[0].asc) + text_info.glyphs[0].pos.y; |
502 | 502 |
503 for (i = 0; i < text_info.length; ++i) { | 503 for (i = 0; i < text_info.length; ++i) { |
504 int s = text_info.glyphs[i].pos.x; | 504 int s = text_info.glyphs[i].pos.x; |
505 int e = s + (text_info.glyphs[i].advance.x >> 6); | 505 int e = s + d6_to_int(text_info.glyphs[i].advance.x); |
506 bbox.xMin = FFMIN(bbox.xMin, s); | 506 bbox.xMin = FFMIN(bbox.xMin, s); |
507 bbox.xMax = FFMAX(bbox.xMax, e); | 507 bbox.xMax = FFMAX(bbox.xMax, e); |
508 } | 508 } |
509 } else | 509 } else |
510 bbox.xMin = bbox.xMax = bbox.yMin = bbox.yMax = 0; | 510 bbox.xMin = bbox.xMax = bbox.yMin = bbox.yMax = 0; |
1239 | 1239 |
1240 info->glyph = ass_font_get_glyph(frame_context.ass_priv->fontconfig_priv, render_context.font, symbol); | 1240 info->glyph = ass_font_get_glyph(frame_context.ass_priv->fontconfig_priv, render_context.font, symbol); |
1241 if (!info->glyph) | 1241 if (!info->glyph) |
1242 return 0; | 1242 return 0; |
1243 | 1243 |
1244 info->advance.x = info->glyph->advance.x >> 10; | 1244 info->advance.x = d16_to_d6(info->glyph->advance.x); |
1245 info->advance.y = info->glyph->advance.y >> 10; | 1245 info->advance.y = d16_to_d6(info->glyph->advance.y); |
1246 | 1246 |
1247 if (render_context.stroker) { | 1247 if (render_context.stroker) { |
1248 info->outline_glyph = info->glyph; | 1248 info->outline_glyph = info->glyph; |
1249 error = FT_Glyph_Stroke( &(info->outline_glyph), render_context.stroker, 0 ); // don't destroy original | 1249 error = FT_Glyph_Stroke( &(info->outline_glyph), render_context.stroker, 0 ); // don't destroy original |
1250 if (error) { | 1250 if (error) { |
1408 cur = text_info.glyphs + i; | 1408 cur = text_info.glyphs + i; |
1409 if (cur->linebreak) { | 1409 if (cur->linebreak) { |
1410 int height = text_info.lines[cur_line - 1].desc + text_info.lines[cur_line].asc; | 1410 int height = text_info.lines[cur_line - 1].desc + text_info.lines[cur_line].asc; |
1411 cur_line ++; | 1411 cur_line ++; |
1412 pen_shift_x = - cur->pos.x; | 1412 pen_shift_x = - cur->pos.x; |
1413 pen_shift_y += (height >> 6) + global_settings->line_spacing; | 1413 pen_shift_y += d6_to_int(height) + global_settings->line_spacing; |
1414 mp_msg(MSGT_ASS, MSGL_DBG2, "shifting from %d to %d by (%d, %d)\n", i, text_info.length - 1, pen_shift_x, pen_shift_y); | 1414 mp_msg(MSGT_ASS, MSGL_DBG2, "shifting from %d to %d by (%d, %d)\n", i, text_info.length - 1, pen_shift_x, pen_shift_y); |
1415 } | 1415 } |
1416 cur->pos.x += pen_shift_x; | 1416 cur->pos.x += pen_shift_x; |
1417 cur->pos.y += pen_shift_y; | 1417 cur->pos.y += pen_shift_y; |
1418 } | 1418 } |
1604 | 1604 |
1605 if (error) { | 1605 if (error) { |
1606 continue; | 1606 continue; |
1607 } | 1607 } |
1608 | 1608 |
1609 text_info.glyphs[text_info.length].pos.x = pen.x >> 6; | 1609 text_info.glyphs[text_info.length].pos.x = d6_to_int(pen.x); |
1610 text_info.glyphs[text_info.length].pos.y = pen.y >> 6; | 1610 text_info.glyphs[text_info.length].pos.y = d6_to_int(pen.y); |
1611 | 1611 |
1612 pen.x += text_info.glyphs[text_info.length].advance.x; | 1612 pen.x += text_info.glyphs[text_info.length].advance.x; |
1613 pen.x += render_context.hspacing; | 1613 pen.x += render_context.hspacing; |
1614 pen.y += text_info.glyphs[text_info.length].advance.y; | 1614 pen.y += text_info.glyphs[text_info.length].advance.y; |
1615 | 1615 |
1720 | 1720 |
1721 // y coordinate for everything except positioned events | 1721 // y coordinate for everything except positioned events |
1722 if (render_context.evt_type == EVENT_NORMAL || | 1722 if (render_context.evt_type == EVENT_NORMAL || |
1723 render_context.evt_type == EVENT_HSCROLL) { | 1723 render_context.evt_type == EVENT_HSCROLL) { |
1724 if (valign == VALIGN_TOP) { // toptitle | 1724 if (valign == VALIGN_TOP) { // toptitle |
1725 device_y = y2scr_top(MarginV) + (text_info.lines[0].asc >> 6); | 1725 device_y = y2scr_top(MarginV) + d6_to_int(text_info.lines[0].asc); |
1726 } else if (valign == VALIGN_CENTER) { // midtitle | 1726 } else if (valign == VALIGN_CENTER) { // midtitle |
1727 int scr_y = y2scr(frame_context.track->PlayResY / 2); | 1727 int scr_y = y2scr(frame_context.track->PlayResY / 2); |
1728 device_y = scr_y - (bbox.yMax - bbox.yMin) / 2; | 1728 device_y = scr_y - (bbox.yMax - bbox.yMin) / 2; |
1729 } else { // subtitle | 1729 } else { // subtitle |
1730 int scr_y; | 1730 int scr_y; |
1731 if (valign != VALIGN_SUB) | 1731 if (valign != VALIGN_SUB) |
1732 mp_msg(MSGT_ASS, MSGL_V, "Invalid valign, supposing 0 (subtitle)\n"); | 1732 mp_msg(MSGT_ASS, MSGL_V, "Invalid valign, supposing 0 (subtitle)\n"); |
1733 scr_y = y2scr_sub(frame_context.track->PlayResY - MarginV); | 1733 scr_y = y2scr_sub(frame_context.track->PlayResY - MarginV); |
1734 device_y = scr_y; | 1734 device_y = scr_y; |
1735 device_y -= (text_info.height >> 6); | 1735 device_y -= d6_to_int(text_info.height); |
1736 device_y += (text_info.lines[0].asc >> 6); | 1736 device_y += d6_to_int(text_info.lines[0].asc); |
1737 } | 1737 } |
1738 } else if (render_context.evt_type == EVENT_VSCROLL) { | 1738 } else if (render_context.evt_type == EVENT_VSCROLL) { |
1739 if (render_context.scroll_direction == SCROLL_TB) | 1739 if (render_context.scroll_direction == SCROLL_TB) |
1740 device_y = y2scr(render_context.clip_y0 + render_context.scroll_shift) - (bbox.yMax - bbox.yMin); | 1740 device_y = y2scr(render_context.clip_y0 + render_context.scroll_shift) - (bbox.yMax - bbox.yMin); |
1741 else if (render_context.scroll_direction == SCROLL_BT) | 1741 else if (render_context.scroll_direction == SCROLL_BT) |
1805 matrix_rotate.yy = (FT_Fixed)( cos( angle ) * 0x10000L ); | 1805 matrix_rotate.yy = (FT_Fixed)( cos( angle ) * 0x10000L ); |
1806 } | 1806 } |
1807 | 1807 |
1808 // calculating shift vector | 1808 // calculating shift vector |
1809 // shift = (position - center)*M - (position - center) | 1809 // shift = (position - center)*M - (position - center) |
1810 start.x = (info->pos.x + device_x - center.x) << 6; | 1810 start.x = int_to_d6(info->pos.x + device_x - center.x); |
1811 start.y = - (info->pos.y + device_y - center.y) << 6; | 1811 start.y = int_to_d6(info->pos.y + device_y - center.y); |
1812 start_old.x = start.x; | 1812 start_old.x = start.x; |
1813 start_old.y = start.y; | 1813 start_old.y = start.y; |
1814 | 1814 |
1815 FT_Vector_Transform(&start, &matrix_rotate); | 1815 FT_Vector_Transform(&start, &matrix_rotate); |
1816 | 1816 |
1817 start.x -= start_old.x; | 1817 start.x -= start_old.x; |
1818 start.y -= start_old.y; | 1818 start.y -= start_old.y; |
1819 | 1819 |
1820 info->pos.x += start.x >> 6; | 1820 info->pos.x += d6_to_int(start.x); |
1821 info->pos.y -= start.y >> 6; | 1821 info->pos.y -= d6_to_int(start.y); |
1822 | 1822 |
1823 if (info->glyph) | 1823 if (info->glyph) |
1824 FT_Glyph_Transform( info->glyph, &matrix_rotate, 0 ); | 1824 FT_Glyph_Transform( info->glyph, &matrix_rotate, 0 ); |
1825 if (info->outline_glyph) | 1825 if (info->outline_glyph) |
1826 FT_Glyph_Transform( info->outline_glyph, &matrix_rotate, 0 ); | 1826 FT_Glyph_Transform( info->outline_glyph, &matrix_rotate, 0 ); |
1827 } | 1827 } |
1828 } | 1828 } |
1829 | 1829 |
1830 event_images->top = device_y - (text_info.lines[0].asc >> 6); | 1830 event_images->top = device_y - d6_to_int(text_info.lines[0].asc); |
1831 event_images->height = text_info.height >> 6; | 1831 event_images->height = d6_to_int(text_info.height); |
1832 event_images->detect_collisions = render_context.detect_collisions; | 1832 event_images->detect_collisions = render_context.detect_collisions; |
1833 event_images->shift_direction = (valign == VALIGN_TOP) ? 1 : -1; | 1833 event_images->shift_direction = (valign == VALIGN_TOP) ? 1 : -1; |
1834 event_images->event = event; | 1834 event_images->event = event; |
1835 event_images->imgs = render_text(&text_info, device_x, device_y); | 1835 event_images->imgs = render_text(&text_info, device_x, device_y); |
1836 | 1836 |