3 * /author Zachary Drew, Copyright 2004
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include <framework/mlt_frame.h>
21 #include "arrow_code.h"
28 #define MIN(a,b) ((a) > (b) ? (b) : (a))
30 #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b))
31 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
38 static mlt_image_format format;
40 int init_arrows( mlt_image_format *image_format, int width, int height )
44 format = *image_format;
45 switch( *image_format ) {
46 case mlt_image_yuv422:
48 ystride = xstride * w;
59 static inline int clip(int a, int amin, int amax)
71 * draws an line from (ex, ey) -> (sx, sy).
72 * Credits: modified from ffmpeg project
73 * @param ystride stride/linesize of the image
74 * @param xstride stride/element size of the image
75 * @param color color of the arrow
77 void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int color)
87 buf[sy*ystride + sx*xstride]+= color;
89 if(ABS(ex - sx) > ABS(ey - sy)){
94 buf+= sx*xstride + sy*ystride;
97 for(x= 0; x <= ex; x++){
100 buf[ y *ystride + x*xstride]+= (color*(0x10000-fr))>>16;
101 buf[(y+1)*ystride + x*xstride]+= (color* fr )>>16;
108 buf+= sx*xstride + sy*ystride;
110 if(ey) f= ((ex-sx)<<16)/ey;
112 for(y= 0; y <= ey; y++){
115 buf[y*ystride + x *xstride]+= (color*(0x10000-fr))>>16;;
116 buf[y*ystride + (x+1)*xstride]+= (color* fr )>>16;;
121 void draw_rectangle_fill(uint8_t *buf, int x, int y, int w, int h, int color)
124 for ( i = 0; i < w; i++ )
125 for ( j = 0; j < h; j++ )
126 buf[ (y+j)*ystride + (x+i)*xstride] = color;
129 void draw_rectangle_outline(uint8_t *buf, int x, int y, int w, int h, int color)
132 for ( i = 0; i < w; i++ ) {
133 buf[ y*ystride + (x+i)*xstride ] += color;
134 buf[ (y+h)*ystride + (x+i)*xstride ] += color;
136 for ( j = 1; j < h+1; j++ ) {
137 buf[ (y+j)*ystride + x*xstride ] += color;
138 buf[ (y+j)*ystride + (x+w)*xstride ] += color;
142 * draws an arrow from (ex, ey) -> (sx, sy).
143 * Credits: modified from ffmpeg project
144 * @param stride stride/linesize of the image
145 * @param color color of the arrow
147 void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int color){
153 if(dx*dx + dy*dy > 3*3){
156 int length= sqrt((rx*rx + ry*ry)<<8);
158 rx= ROUNDED_DIV(rx*3<<4, length);
159 ry= ROUNDED_DIV(ry*3<<4, length);
161 draw_line(buf, sx, sy, sx + rx, sy + ry, color);
162 draw_line(buf, sx, sy, sx - ry, sy + rx, color);
164 draw_line(buf, sx, sy, ex, ey, color);