~ubuntu-branches/ubuntu/oneiric/avidemux/oneiric-proposed

« back to all changes in this revision

Viewing changes to plugins/ADM_videoFilters/Ass/ADM_libAss/ass_utils.c

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2009-08-20 08:42:44 UTC
  • mfrom: (1.1.14 upstream)
  • Revision ID: james.westby@ubuntu.com-20090820084244-bhh15xxd7x2vbcuh
Tags: 1:2.5.1+repack-0ubuntu1
* New upstream bugfix release (LP: #416066):
  - Re-enabled several video and audio encoders (regression introduced
    in 2.5.0)
  - Updated the FFmpeg libraries
  - More video encoders are now plugins
  - DV video encoder now supports more profiles
  - Fixed loading and saving issues with LAME, x264 and Xvid options
    (regression introduced in 2.5.0)
  - Fraps video decoding support
  - Lowpass-5 mode added to libavcodec deinterlacer filter plugin
  - Fixed formatting of parameters for various filters on 64-bit platforms
  - Updated libass
  - Fixed sizing of the bitrate control on various video encoder configure
    windows (regression introduced in 2.5.0)
  - Improved filter dialog for GTK+ interface
  - New navigation icons for GTK+ interface
  - Fixed the behaviour of several GTK+ open/save dialogs (regression
    introduced in 2.5.0)
  - asharp filter's Block Adaptive mode can now be disabled using the Qt
    interface
  - Re-enabled the colour chooser dialog using the Qt interface (regression
    introduced in 2.5.0)
  - GCC 4.4 support
  - Fixed issues with CMake build scripts when using multiple make jobs
    (regression introduced in 2.5.0)
* Remove debian/patches dir and drop all patches, now applied by upstream.
* Drop quilt support.
* debian/libavidemux0.install: Also install missing libraries.
* Move debian/install to debian/avidemux.install.
* debian/rules:
  - Build the internal ffmpeg version properly (thanks to Christian Marillat).
  - A bit of cleanup.
* debian/control:
  - Bump Standards-Version.
  - Update Homepage field.
  - Adjust libavidemux0 short description.
  - gtk -> GTK, qt -> QT.
  - Set myself as Maintainer.
* Repack the tarball to remove the debian/ dir provided by upstream:
  - Create debian/README.source.
  - Update debian/watch.
  - Add get-orig-source target to debian/rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
 
3
 *
 
4
 * This file is part of libass.
 
5
 *
 
6
 * libass is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * libass is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License along
 
17
 * with libass; if not, write to the Free Software Foundation, Inc.,
 
18
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <inttypes.h>
 
26
#include <ft2build.h>
 
27
#include FT_GLYPH_H
 
28
 
 
29
#include "ass_library.h"
 
30
#include "ass.h"
 
31
#include "ass_utils.h"
 
32
 
 
33
int mystrtoi(char **p, int *res)
 
34
{
 
35
    double temp_res;
 
36
    char *start = *p;
 
37
    temp_res = strtod(*p, p);
 
38
    *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5));
 
39
    if (*p != start)
 
40
        return 1;
 
41
    else
 
42
        return 0;
 
43
}
 
44
 
 
45
int mystrtoll(char **p, long long *res)
 
46
{
 
47
    double temp_res;
 
48
    char *start = *p;
 
49
    temp_res = strtod(*p, p);
 
50
    *res = (int) (temp_res + (temp_res > 0 ? 0.5 : -0.5));
 
51
    if (*p != start)
 
52
        return 1;
 
53
    else
 
54
        return 0;
 
55
}
 
56
 
 
57
int mystrtou32(char **p, int base, uint32_t *res)
 
58
{
 
59
    char *start = *p;
 
60
    *res = strtoll(*p, p, base);
 
61
    if (*p != start)
 
62
        return 1;
 
63
    else
 
64
        return 0;
 
65
}
 
66
 
 
67
int mystrtod(char **p, double *res)
 
68
{
 
69
    char *start = *p;
 
70
    *res = strtod(*p, p);
 
71
    if (*p != start)
 
72
        return 1;
 
73
    else
 
74
        return 0;
 
75
}
 
76
 
 
77
int strtocolor(ass_library_t *library, char **q, uint32_t *res)
 
78
{
 
79
    uint32_t color = 0;
 
80
    int result;
 
81
    char *p = *q;
 
82
 
 
83
    if (*p == '&')
 
84
        ++p;
 
85
    else
 
86
        ass_msg(library, MSGL_DBG2, "suspicious color format: \"%s\"\n", p);
 
87
 
 
88
    if (*p == 'H' || *p == 'h') {
 
89
        ++p;
 
90
        result = mystrtou32(&p, 16, &color);
 
91
    } else {
 
92
        result = mystrtou32(&p, 0, &color);
 
93
    }
 
94
 
 
95
    {
 
96
        unsigned char *tmp = (unsigned char *) (&color);
 
97
        unsigned char b;
 
98
        b = tmp[0];
 
99
        tmp[0] = tmp[3];
 
100
        tmp[3] = b;
 
101
        b = tmp[1];
 
102
        tmp[1] = tmp[2];
 
103
        tmp[2] = b;
 
104
    }
 
105
    if (*p == '&')
 
106
        ++p;
 
107
    *q = p;
 
108
 
 
109
    *res = color;
 
110
    return result;
 
111
}
 
112
 
 
113
// Return a boolean value for a string
 
114
char parse_bool(char *str)
 
115
{
 
116
    while (*str == ' ' || *str == '\t')
 
117
        str++;
 
118
    if (!strncasecmp(str, "yes", 3))
 
119
        return 1;
 
120
    else if (strtol(str, NULL, 10) > 0)
 
121
        return 1;
 
122
    return 0;
 
123
}
 
124
 
 
125
void ass_msg(ass_library_t *priv, int lvl, char *fmt, ...)
 
126
{
 
127
    va_list va;
 
128
    va_start(va, fmt);
 
129
    priv->msg_callback(lvl, fmt, va, priv->msg_callback_data);
 
130
    va_end(va);
 
131
}
 
132
 
 
133
unsigned ass_utf8_get_char(char **str)
 
134
{
 
135
    uint8_t *strp = (uint8_t *) * str;
 
136
    unsigned c = *strp++;
 
137
    unsigned mask = 0x80;
 
138
    int len = -1;
 
139
    while (c & mask) {
 
140
        mask >>= 1;
 
141
        len++;
 
142
    }
 
143
    if (len <= 0 || len > 4)
 
144
        goto no_utf8;
 
145
    c &= mask - 1;
 
146
    while ((*strp & 0xc0) == 0x80) {
 
147
        if (len-- <= 0)
 
148
            goto no_utf8;
 
149
        c = (c << 6) | (*strp++ & 0x3f);
 
150
    }
 
151
    if (len)
 
152
        goto no_utf8;
 
153
    *str = (char *) strp;
 
154
    return c;
 
155
 
 
156
  no_utf8:
 
157
    strp = (uint8_t *) * str;
 
158
    c = *strp++;
 
159
    *str = (char *) strp;
 
160
    return c;
 
161
}
 
162
 
 
163
#ifdef CONFIG_ENCA
 
164
void *ass_guess_buffer_cp(ass_library_t *library, unsigned char *buffer,
 
165
                          int buflen, char *preferred_language,
 
166
                          char *fallback)
 
167
{
 
168
    const char **languages;
 
169
    size_t langcnt;
 
170
    EncaAnalyser analyser;
 
171
    EncaEncoding encoding;
 
172
    char *detected_sub_cp = NULL;
 
173
    int i;
 
174
 
 
175
    languages = enca_get_languages(&langcnt);
 
176
    ass_msg(library, MSGL_V, "ENCA supported languages");
 
177
    for (i = 0; i < langcnt; i++) {
 
178
        ass_msg(library, MSGL_V, "lang %s", languages[i]);
 
179
    }
 
180
 
 
181
    for (i = 0; i < langcnt; i++) {
 
182
        const char *tmp;
 
183
 
 
184
        if (strcasecmp(languages[i], preferred_language) != 0)
 
185
            continue;
 
186
        analyser = enca_analyser_alloc(languages[i]);
 
187
        encoding = enca_analyse_const(analyser, buffer, buflen);
 
188
        tmp = enca_charset_name(encoding.charset, ENCA_NAME_STYLE_ICONV);
 
189
        if (tmp && encoding.charset != ENCA_CS_UNKNOWN) {
 
190
            detected_sub_cp = strdup(tmp);
 
191
            ass_msg(library, MSGL_INFO, "ENCA detected charset: %s", tmp);
 
192
        }
 
193
        enca_analyser_free(analyser);
 
194
    }
 
195
 
 
196
    free(languages);
 
197
 
 
198
    if (!detected_sub_cp) {
 
199
        detected_sub_cp = strdup(fallback);
 
200
        ass_msg(library, MSGL_INFO,
 
201
               "ENCA detection failed: fallback to %s", fallback);
 
202
    }
 
203
 
 
204
    return detected_sub_cp;
 
205
}
 
206
#endif