- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- if (ParseColor(optarg, ci->fgcolor) == -1)
- {
- fprintf(stderr, "ERROR: Invalid foreground color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -c #ffffff (for white foreground)\n",optarg);
- return -1;
- }
- break;
+ if (ParseColor(optarg, ci->fgcolor) == -1)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Invalid foreground color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -c #ffffff (for white foreground)\n", optarg);
+ return -1;
+ }
+ break;
- if (ParseColor(optarg, ci->bgcolor) == -1)
- {
- fprintf(stderr, "ERROR: Invalid foreground color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -c #ffffff (for white foreground)\n",optarg);
- return -1;
- }
- break;
+ if (ParseColor(optarg, ci->bgcolor) == -1)
+ {
+ av_log(NULL, AV_LOG_ERROR, "Invalid foreground color: '%s'. You must specify the color in the internet way(packaged hex): #RRGGBB, ie: -c #ffffff (for white foreground)\n", optarg);
+ return -1;
+ }
+ break;
- /* Load char */
- error = FT_Load_Char( ci->face, (unsigned char) c, FT_LOAD_RENDER | FT_LOAD_MONOCHROME );
- if (error) continue; /* ignore errors */
-
- /* Save bitmap */
- ci->bitmaps[c] = ci->face->glyph->bitmap;
- /* Save bitmap left */
- ci->bitmap_left[c] = ci->face->glyph->bitmap_left;
- /* Save bitmap top */
- ci->bitmap_top[c] = ci->face->glyph->bitmap_top;
-
- /* Save advance */
- ci->advance[c] = ci->face->glyph->advance.x >> 6;
-
- /* Save glyph */
- error = FT_Get_Glyph( ci->face->glyph, &(ci->glyphs[c]) );
- /* Save glyph index */
- ci->glyphs_index[c] = FT_Get_Char_Index( ci->face, (unsigned char) c );
-
- /* Measure text height to calculate text_height (or the maximum text height) */
- FT_Glyph_Get_CBox( ci->glyphs[ c ], ft_glyph_bbox_pixels, &bbox );
- if (bbox.yMax > yMax)
- yMax = bbox.yMax;
- if (bbox.yMin < yMin)
- yMin = bbox.yMin;
-
+ /* Load char */
+ error = FT_Load_Char( ci->face, (unsigned char) c, FT_LOAD_RENDER | FT_LOAD_MONOCHROME );
+ if (error) continue; /* ignore errors */
+
+ /* Save bitmap */
+ ci->bitmaps[c] = ci->face->glyph->bitmap;
+ /* Save bitmap left */
+ ci->bitmap_left[c] = ci->face->glyph->bitmap_left;
+ /* Save bitmap top */
+ ci->bitmap_top[c] = ci->face->glyph->bitmap_top;
+
+ /* Save advance */
+ ci->advance[c] = ci->face->glyph->advance.x >> 6;
+
+ /* Save glyph */
+ error = FT_Get_Glyph( ci->face->glyph, &(ci->glyphs[c]) );
+ /* Save glyph index */
+ ci->glyphs_index[c] = FT_Get_Char_Index( ci->face, (unsigned char) c );
+
+ /* Measure text height to calculate text_height (or the maximum text height) */
+ FT_Glyph_Get_CBox( ci->glyphs[ c ], ft_glyph_bbox_pixels, &bbox );
+ if (bbox.yMax > yMax)
+ yMax = bbox.yMax;
+ if (bbox.yMin < yMin)
+ yMin = bbox.yMin;
+
-inline void draw_glyph(AVPicture *picture, FT_Bitmap *bitmap, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned char yuv_fgcolor[3], unsigned char yuv_bgcolor[3], int outline)
+static inline void draw_glyph(AVPicture *picture, FT_Bitmap *bitmap, unsigned int x, unsigned int y, unsigned int width, unsigned int height, unsigned char yuv_fgcolor[3], unsigned char yuv_bgcolor[3], int outline)
- {
- for (c=0; (c < bitmap->width) && (c+x < width); c++)
- {
- /* pixel in the picture (destination) */
- GET_PIXEL(picture, dpixel, (c+x), (y+r));
-
- /* pixel in the glyph bitmap (source) */
- spixel = bitmap->buffer[r*bitmap->pitch +c/8] & (0x80>>(c%8));
-
- if (spixel)
- COPY_3(dpixel, yuv_fgcolor);
-
- if (outline)
- {
- /* border detection: */
- if ( (!in_glyph) && (spixel) )
- /* left border detected */
- {
- in_glyph = 1;
- /* draw left pixel border */
- if (c-1 >= 0)
- SET_PIXEL(picture, yuv_bgcolor, (c+x-1), (y+r));
- }
- else if ( (in_glyph) && (!spixel) )
- /* right border detected */
- {
- in_glyph = 0;
- /* 'draw' right pixel border */
- COPY_3(dpixel, yuv_bgcolor);
- }
-
- if (in_glyph)
- /* see if we have a top/bottom border */
- {
- /* top */
- if ( (r-1 >= 0) && (! bitmap->buffer[(r-1)*bitmap->pitch +c/8] & (0x80>>(c%8))) )
- /* we have a top border */
- SET_PIXEL(picture, yuv_bgcolor, (c+x), (y+r-1));
-
- /* bottom */
- if ( (r+1 < height) && (! bitmap->buffer[(r+1)*bitmap->pitch +c/8] & (0x80>>(c%8))) )
- /* we have a bottom border */
- SET_PIXEL(picture, yuv_bgcolor, (c+x), (y+r+1));
-
- }
- }
-
- SET_PIXEL(picture, dpixel, (c+x), (y+r));
- }
- }
+ {
+ for (c=0; (c < bitmap->width) && (c+x < width); c++)
+ {
+ /* pixel in the picture (destination) */
+ GET_PIXEL(picture, dpixel, (c+x), (y+r));
+
+ /* pixel in the glyph bitmap (source) */
+ spixel = bitmap->buffer[r*bitmap->pitch +c/8] & (0x80>>(c%8));
+
+ if (spixel)
+ COPY_3(dpixel, yuv_fgcolor);
+
+ if (outline)
+ {
+ /* border detection: */
+ if ( (!in_glyph) && (spixel) )
+ /* left border detected */
+ {
+ in_glyph = 1;
+ /* draw left pixel border */
+ if (c-1 >= 0)
+ SET_PIXEL(picture, yuv_bgcolor, (c+x-1), (y+r));
+ }
+ else if ( (in_glyph) && (!spixel) )
+ /* right border detected */
+ {
+ in_glyph = 0;
+ /* 'draw' right pixel border */
+ COPY_3(dpixel, yuv_bgcolor);
+ }
+
+ if (in_glyph)
+ /* see if we have a top/bottom border */
+ {
+ /* top */
+ if ( (r-1 >= 0) && (! bitmap->buffer[(r-1)*bitmap->pitch +c/8] & (0x80>>(c%8))) )
+ /* we have a top border */
+ SET_PIXEL(picture, yuv_bgcolor, (c+x), (y+r-1));
+
+ /* bottom */
+ if ( (r+1 < height) && (! bitmap->buffer[(r+1)*bitmap->pitch +c/8] & (0x80>>(c%8))) )
+ /* we have a bottom border */
+ SET_PIXEL(picture, yuv_bgcolor, (c+x), (y+r+1));
+
+ }
+ }
+
+ SET_PIXEL(picture, dpixel, (c+x), (y+r));
+ }
+ }
-
- if (fd < 0)
- {
- text = ci->text;
- perror("WARNING: the file could not be opened. Using text provided with -t switch. ");
- }
- else
- {
- int l = read(fd, tbuff, sizeof(tbuff) - 1);
-
- if (l >= 0)
- {
- tbuff[l] = 0;
- text = tbuff;
- }
- else
- {
- text = ci->text;
- perror("WARNING: the file could not be opened. Using text provided with -t switch. ");
- }
- close(fd);
- }
+
+ if (fd < 0)
+ {
+ text = ci->text;
+ av_log(NULL, AV_LOG_INFO, "WARNING: The file could not be opened. Using text provided with -t switch: %s", strerror(errno));
+ }
+ else
+ {
+ int l = read(fd, tbuff, sizeof(tbuff) - 1);
+
+ if (l >= 0)
+ {
+ tbuff[l] = 0;
+ text = tbuff;
+ }
+ else
+ {
+ text = ci->text;
+ av_log(NULL, AV_LOG_INFO, "WARNING: The file could not be read. Using text provided with -t switch: %s", strerror(errno));
+ }
+ close(fd);
+ }
- ( (c == '_') && (text == ci->text) ) || /* skip '_' (consider as space)
- IF text was specified in cmd line
- (which doesn't like neasted quotes) */
- ( c == '\n' ) /* Skip new line char, just go to new line */
- )
- continue;
-
- /* now, draw to our target surface */
- draw_glyph( picture,
- &(ci->bitmaps[ c ]),
- pos[i].x,
- pos[i].y,
- width,
- height,
- ci->fgcolor,
- ci->bgcolor,
- ci->outline );
-
+ ( (c == '_') && (text == ci->text) ) || /* skip '_' (consider as space)
+ IF text was specified in cmd line
+ (which doesn't like neasted quotes) */
+ ( c == '\n' ) /* Skip new line char, just go to new line */
+ )
+ continue;
+
+ /* now, draw to our target surface */
+ draw_glyph( picture,
+ &(ci->bitmaps[ c ]),
+ pos[i].x,
+ pos[i].y,
+ width,
+ height,
+ ci->fgcolor,
+ ci->bgcolor,
+ ci->outline );
+