Mercurial > mplayer.hg
annotate libmpcodecs/vf_remove_logo.c @ 17414:eb5a933b8fcd
Remove multi-language setting specification, it has little use.
author | diego |
---|---|
date | Tue, 17 Jan 2006 00:24:07 +0000 |
parents | 934380353fd6 |
children | 20aca9baf5d8 |
rev | line source |
---|---|
15693
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
1 /* |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
2 Copyright 2005 Robert Edele. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
3 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
4 e-mail: yartrebo@earthlink.net |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
5 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
6 This program is free software; you can redistribute it and/or modify it |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
7 under the terms of the GNU General Public License as published by the Free |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
8 Software Foundation; either version 2 of the License, or (at your option) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
9 any later version. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
10 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
11 This program is distributed in the hope that it will be useful, but |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
12 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Public License for more |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
14 details. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
15 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
16 You should have reveived a copy of the GNU General Public License |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
17 along with this program; if not, write to the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
19 02111-1307 USA |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
20 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
21 __________________________________________________________________________ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
22 | Robert Edele Fri. 4-Feb-2005 | |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
23 | This program loads a .pgm mask file showing where a logo is and uses | |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
24 | a blur transform to remove the logo. | |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
25 |________________________________________________________________________| |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
26 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
27 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
28 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
29 * \file vf_remove_logo.c |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
30 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
31 * \brief Advanced blur-based logo removing filter. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
32 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
33 * Hello and welcome. This code implements a filter to remove annoying TV |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
34 * logos and other annoying images placed onto a video stream. It works by filling |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
35 * in the pixels that comprise the logo with neighboring pixels. The transform is |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
36 * very loosely based on a gaussian blur, but it is different enough to merit its |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
37 * own paragraph later on. It is a major improvement on the old delogo filter as |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
38 * it both uses a better blurring algorithm and uses a bitmap to use an arbitrary |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
39 * and generally much tighter fitting shape than a rectangle. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
40 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
41 * The filter requires 1 argument and has no optional arguments. It requires |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
42 * a filter bitmap, which must be in PGM or PPM format. A sample invocation would |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
43 * be -vf remove_logo=/home/username/logo_bitmaps/xyz.pgm. Pixels with a value of |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
44 * zero are not part of the logo, and non-zero pixels are part of the logo. If you |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
45 * use white (255) for the logo and black (0) for the rest, you will be safe. For |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
46 * making the filter bitmap, I recommend taking a screen capture of a black frame |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
47 * with the logo visible, and then using The GIMP's threshold filter followed by |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
48 * the erode filter once or twice. If needed, little splotches can be fixed |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
49 * manually. Remember that if logo pixels are not covered, the filter quality will |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
50 * be much reduced. Marking too many pixels as part of the logo doesn't hurt as |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
51 * much, but it will increase the amount of blurring needed to cover over the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
52 * image and will destroy more information than necessary. Additionally, this blur |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
53 * algorithm is O(n) = n^4, where n is the width and height of a hypothetical |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
54 * square logo, so extra pixels will slow things down on a large lo |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
55 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
56 * The logo removal algorithm has two key points. The first is that it |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
57 * distinguishes between pixels in the logo and those not in the logo by using the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
58 * passed-in bitmap. Pixels not in the logo are copied over directly without being |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
59 * modified and they also serve as source pixels for the logo fill-in. Pixels |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
60 * inside the logo have the mask applied. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
61 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
62 * At init-time the bitmap is reprocessed internally, and the distance to the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
63 * nearest edge of the logo (Manhattan distance), along with a little extra to |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
64 * remove rough edges, is stored in each pixel. This is done using an in-place |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
65 * erosion algorithm, and incrementing each pixel that survives any given erosion. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
66 * Once every pixel is eroded, the maximum value is recorded, and a set of masks |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
67 * from size 0 to this size are generaged. The masks are circular binary masks, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
68 * where each pixel within a radius N (where N is the size of the mask) is a 1, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
69 * and all other pixels are a 0. Although a gaussian mask would be more |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
70 * mathematically accurate, a binary mask works better in practice because we |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
71 * generally do not use the central pixels in the mask (because they are in the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
72 * logo region), and thus a gaussian mask will cause too little blur and thus a |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
73 * very unstable image. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
74 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
75 * The mask is applied in a special way. Namely, only pixels in the mask that |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
76 * line up to pixels outside the logo are used. The dynamic mask size means that |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
77 * the mask is just big enough so that the edges touch pixels outside the logo, so |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
78 * the blurring is kept to a minimum and at least the first boundary condition is |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
79 * met (that the image function itself is continuous), even if the second boundary |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
80 * condition (that the derivative of the image function is continuous) is not met. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
81 * A masking algorithm that does preserve the second boundary coundition |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
82 * (perhaps something based on a highly-modified bi-cubic algorithm) should offer |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
83 * even better results on paper, but the noise in a typical TV signal should make |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
84 * anything based on derivatives hopelessly noisy. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
85 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
86 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
87 #include <stdio.h> |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
88 #include <stdlib.h> |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
89 #include <string.h> |
16182 | 90 #include <ctype.h> |
15693
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
91 #include <inttypes.h> |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
92 |
17012 | 93 #include "config.h" |
94 #include "mp_msg.h" | |
95 #include "libvo/fastmemcpy.h" | |
15693
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
96 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
97 #include "img_format.h" |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
98 #include "mp_image.h" |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
99 #include "vf.h" |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
100 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
101 //===========================================================================// |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
102 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
103 /** \brief Returns the larger of the two arguments. **/ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
104 #define max(x,y) ((x)>(y)?(x):(y)) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
105 /** \brief Returns the smaller of the two arguments. **/ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
106 #define min(x,y) ((x)>(y)?(y):(x)) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
107 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
108 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
109 * \brief Test if a pixel is part of the logo. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
110 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
111 #define test_filter(image, x, y) ((unsigned char) (image->pixel[((y) * image->width) + (x)])) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
112 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
113 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
114 * \brief Chooses a slightly larger mask size to improve performance. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
115 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
116 * This function maps the absolute minimum mask size needed to the mask size we'll |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
117 * actually use. f(x) = x (the smallest that will work) will produce the sharpest |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
118 * results, but will be quite jittery. f(x) = 1.25x (what I'm using) is a good |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
119 * tradeoff in my opinion. This will calculate only at init-time, so you can put a |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
120 * long expression here without effecting performance. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
121 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
122 #define apply_mask_fudge_factor(x) (((x) >> 2) + x) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
123 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
124 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
125 * \brief Simple implementation of the PGM image format. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
126 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
127 * This struct holds a bare-bones image loaded from a PGM or PPM file. Once |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
128 * loaded and pre-processed, each pixel in this struct will contain how far from |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
129 * the edge of the logo each pixel is, using the manhattan distance (|dx| + |dy|). |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
130 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
131 * pixels in char * pixel can be addressed using (y * width) + height. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
132 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
133 typedef struct |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
134 { |
17366 | 135 unsigned int width; |
136 unsigned int height; | |
15693
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
137 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
138 unsigned char * pixel; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
139 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
140 } pgm_structure; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
141 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
142 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
143 * \brief Stores persistant variables. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
144 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
145 * Variables stored here are kept from frame to frame, and seperate instances of |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
146 * the filter will get their own seperate copies. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
147 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
148 typedef struct |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
149 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
150 unsigned int fmt; /* Not exactly sure of the use for this. It came with the example filter I used as a basis for this, and it looks like a lot of stuff will break if I remove it. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
151 int max_mask_size; /* The largest possible mask size that will be needed with the given filter and corresponding half_size_filter. The half_size_filter can have a larger requirment in some rare (but not degenerate) cases. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
152 int * * * mask; /* Stores our collection of masks. The first * is for an array of masks, the second for the y axis, and the third for the x axis. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
153 pgm_structure * filter; /* Stores the full-size filter image. This is used to tell what pixels are in the logo or not in the luma plane. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
154 pgm_structure * half_size_filter; /* Stores a 50% width and 50% height filter image. This is used to tell what pixels are in the logo or not in the chroma planes. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
155 /* These 8 variables store the bounding rectangles that the logo resides in. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
156 int bounding_rectangle_posx1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
157 int bounding_rectangle_posy1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
158 int bounding_rectangle_posx2; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
159 int bounding_rectangle_posy2; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
160 int bounding_rectangle_half_size_posx1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
161 int bounding_rectangle_half_size_posy1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
162 int bounding_rectangle_half_size_posx2; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
163 int bounding_rectangle_half_size_posy2; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
164 } vf_priv_s; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
165 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
166 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
167 * \brief Mallocs memory and checks to make sure it succeeded. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
168 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
169 * \param size How many bytes to allocate. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
170 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
171 * \return A pointer to the freshly allocated memory block, or NULL on failutre. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
172 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
173 * Mallocs memory, and checks to make sure it was successfully allocated. Because |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
174 * of how MPlayer works, it cannot safely halt execution, but at least the user |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
175 * will get an error message before the segfault happens. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
176 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
177 void * safe_malloc(int size) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
178 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
179 void * answer = malloc(size); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
180 if (answer == NULL) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
181 mp_msg(MSGT_VFILTER, MSGL_ERR, "Unable to allocate memory in vf_remove_logo.c\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
182 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
183 return answer; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
184 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
185 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
186 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
187 * \brief Calculates the smallest rectangle that will encompass the logo region. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
188 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
189 * \param filter This image contains the logo around which the rectangle will |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
190 * will be fitted. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
191 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
192 * The bounding rectangle is calculated by testing successive lines (from the four |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
193 * sides of the rectangle) until no more can be removed without removing logo |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
194 * pixels. The results are returned by reference to posx1, posy1, posx2, and |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
195 * posy2. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
196 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
197 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
198 void calculate_bounding_rectangle(int * posx1, int * posy1, int * posx2, int * posy2, pgm_structure * filter) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
199 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
200 int x; /* Temporary variables to run */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
201 int y; /* through each row or column. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
202 int start_x; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
203 int start_y; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
204 int end_x = filter->width - 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
205 int end_y = filter->height - 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
206 int did_we_find_a_logo_pixel = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
207 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
208 /* Let's find the top bound first. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
209 for (start_x = 0; start_x < filter->width && !did_we_find_a_logo_pixel; start_x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
210 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
211 for (y = 0; y < filter->height; y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
212 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
213 did_we_find_a_logo_pixel |= test_filter(filter, start_x, y); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
214 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
215 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
216 start_x--; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
217 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
218 /* Now the bottom bound. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
219 did_we_find_a_logo_pixel = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
220 for (end_x = filter->width - 1; end_x > start_x && !did_we_find_a_logo_pixel; end_x--) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
221 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
222 for (y = 0; y < filter->height; y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
223 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
224 did_we_find_a_logo_pixel |= test_filter(filter, end_x, y); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
225 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
226 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
227 end_x++; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
228 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
229 /* Left bound. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
230 did_we_find_a_logo_pixel = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
231 for (start_y = 0; start_y < filter->height && !did_we_find_a_logo_pixel; start_y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
232 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
233 for (x = 0; x < filter->width; x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
234 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
235 did_we_find_a_logo_pixel |= test_filter(filter, x, start_y); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
236 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
237 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
238 start_y--; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
239 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
240 /* Right bound. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
241 did_we_find_a_logo_pixel = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
242 for (end_y = filter->height - 1; end_y > start_y && !did_we_find_a_logo_pixel; end_y--) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
243 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
244 for (x = 0; x < filter->width; x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
245 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
246 did_we_find_a_logo_pixel |= test_filter(filter, x, end_y); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
247 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
248 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
249 end_y++; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
250 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
251 *posx1 = start_x; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
252 *posy1 = start_y; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
253 *posx2 = end_x; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
254 *posy2 = end_y; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
255 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
256 return; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
257 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
258 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
259 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
260 * \brief Free mask memory. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
261 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
262 * \param vf Data structure which stores our persistant data, and is to be freed. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
263 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
264 * We call this function when our filter is done. It will free the memory |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
265 * allocated to the masks and leave the variables in a safe state. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
266 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
267 void destroy_masks(vf_instance_t * vf) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
268 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
269 int a, b; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
270 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
271 /* Load values from the vf->priv struct for faster dereferencing. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
272 int * * * mask = ((vf_priv_s *)vf->priv)->mask; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
273 int max_mask_size = ((vf_priv_s *)vf->priv)->max_mask_size; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
274 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
275 if (mask == NULL) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
276 return; /* Nothing allocated, so return before we segfault. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
277 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
278 /* Free all allocated memory. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
279 for (a = 0; a <= max_mask_size; a++) /* Loop through each mask. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
280 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
281 for (b = -a; b <= a; b++) /* Loop through each scanline in a mask. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
282 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
283 free(mask[a][b + a]); /* Free a scanline. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
284 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
285 free(mask[a]); /* Free a mask. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
286 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
287 free(mask); /* Free the array of pointers pointing to the masks. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
288 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
289 /* Set the pointer to NULL, so that any duplicate calls to this function will not cause a crash. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
290 ((vf_priv_s *)vf->priv)->mask = NULL; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
291 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
292 return; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
293 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
294 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
295 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
296 * \brief Set up our array of masks. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
297 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
298 * \param vf Where our filter stores persistance data, like these masks. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
299 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
300 * This creates an array of progressively larger masks and calculates their |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
301 * values. The values will not change during program execution once this function |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
302 * is done. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
303 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
304 void initialize_masks(vf_instance_t * vf) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
305 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
306 int a, b, c; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
307 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
308 /* Load values from the vf->priv struct for faster dereferencing. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
309 int * * * mask = ((vf_priv_s *)vf->priv)->mask; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
310 int max_mask_size = ((vf_priv_s *)vf->priv)->max_mask_size; /* This tells us how many masks we'll need to generate. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
311 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
312 /* Create a circular mask for each size up to max_mask_size. When the filter is applied, the mask size is |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
313 determined on a pixel by pixel basis, with pixels nearer the edge of the logo getting smaller mask sizes. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
314 mask = (int * * *) safe_malloc(sizeof(int * *) * (max_mask_size + 1)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
315 for (a = 0; a <= max_mask_size; a++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
316 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
317 mask[a] = (int * *) safe_malloc(sizeof(int *) * ((a * 2) + 1)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
318 for (b = -a; b <= a; b++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
319 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
320 mask[a][b + a] = (int *) safe_malloc(sizeof(int) * ((a * 2) + 1)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
321 for (c = -a; c <= a; c++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
322 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
323 if ((b * b) + (c * c) <= (a * a)) /* Circular 0/1 mask. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
324 mask[a][b + a][c + a] = 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
325 else |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
326 mask[a][b + a][c + a] = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
327 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
328 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
329 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
330 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
331 /* Store values back to vf->priv so they aren't lost after the function returns. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
332 ((vf_priv_s *)vf->priv)->mask = mask; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
333 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
334 return; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
335 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
336 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
337 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
338 * \brief Pre-processes an image to give distance information. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
339 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
340 * \param vf Data structure that holds persistant information. All it is used for |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
341 in this function is to store the calculated max_mask_size variable. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
342 * \param mask This image will be converted from a greyscale image into a |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
343 * distance image. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
344 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
345 * This function takes a greyscale image (pgm_structure * mask) and converts it |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
346 * in place into a distance image. A distance image is zero for pixels ourside of |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
347 * the logo and is the manhattan distance (|dx| + |dy|) for pixels inside of the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
348 * logo. This will overestimate the distance, but that is safe, and is far easier |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
349 * to implement than a proper pythagorean distance since I'm using a modified |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
350 * erosion algorithm to compute the distances. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
351 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
352 void convert_mask_to_strength_mask(vf_instance_t * vf, pgm_structure * mask) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
353 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
354 int x, y; /* Used by our for loops to go through every single pixel in the picture one at a time. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
355 int has_anything_changed = 1; /* Used by the main while() loop to know if anything changed on the last erosion. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
356 int current_pass = 0; /* How many times we've gone through the loop. Used in the in-place erosion algorithm |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
357 and to get us max_mask_size later on. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
358 int max_mask_size; /* This will record how large a mask the pixel that is the furthest from the edge of the logo |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
359 (and thus the neediest) is. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
360 char * current_pixel = mask->pixel; /* This stores the actual pixel data. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
361 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
362 /* First pass, set all non-zero values to 1. After this loop finishes, the data should be considered numeric |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
363 data for the filter, not color data. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
364 for (x = 0; x < mask->height * mask->width; x++, current_pixel++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
365 if(*current_pixel) *current_pixel = 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
366 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
367 /* Second pass and future passes. For each pass, if a pixel is itself the same value as the current pass, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
368 and its four neighbors are too, then it is incremented. If no pixels are incremented by the end of the pass, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
369 then we go again. Edge pixels are counted as always excluded (this should be true anyway for any sane mask, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
370 but if it isn't this will ensure that we eventually exit). */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
371 while (has_anything_changed) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
372 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
373 current_pass++; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
374 current_pixel = mask->pixel; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
375 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
376 has_anything_changed = 0; /* If this doesn't get set by the end of this pass, then we're done. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
377 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
378 for (y = 1; y < mask->height - 1; y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
379 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
380 for (x = 1; x < mask->width - 1; x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
381 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
382 /* Apply the in-place erosion transform. It is based on the following two premises: 1 - Any pixel that fails 1 erosion |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
383 will fail all future erosions. 2 - Only pixels having survived all erosions up to the present will be >= to |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
384 current_pass. It doesn't matter if it survived the current pass, failed it, or hasn't been tested yet. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
385 if (*current_pixel >= current_pass && /* By using >= instead of ==, we allow the algorithm to work in place. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
386 *(current_pixel + 1) >= current_pass && |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
387 *(current_pixel - 1) >= current_pass && |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
388 *(current_pixel + mask->width) >= current_pass && |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
389 *(current_pixel - mask->width) >= current_pass) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
390 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
391 (*current_pixel)++; /* Increment the value since it still has not been eroded, as evidenced by the if statement |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
392 that just evaluated to true. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
393 has_anything_changed = 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
394 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
395 current_pixel++; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
396 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
397 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
398 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
399 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
400 /* Apply the fudge factor, which will increase the size of the mask a little to reduce jitter at the cost of more blur. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
401 for (y = 1; y < mask->height - 1; y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
402 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
403 for (x = 1; x < mask->width - 1; x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
404 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
405 mask->pixel[(y * mask->width) + x] = apply_mask_fudge_factor(mask->pixel[(y * mask->width) + x]); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
406 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
407 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
408 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
409 max_mask_size = current_pass + 1; /* As a side-effect, we now know the maximum mask size, which we'll use to generate our masks. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
410 max_mask_size = apply_mask_fudge_factor(max_mask_size); /* Apply the fudge factor to this number too, since we must |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
411 ensure that enough masks are generated. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
412 ((vf_priv_s *)vf->priv)->max_mask_size = max_mask_size; /* Commit the newly calculated max_mask_size to the vf->priv struct. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
413 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
414 return; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
415 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
416 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
417 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
418 * \brief Our blurring function. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
419 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
420 * \param vf Stores persistant data. In this function we are interested in the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
421 * array of masks. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
422 * \param value_out The properly blurred and delogoed pixel is outputted here. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
423 * \param logo_mask Tells us which pixels are in the logo and which aren't. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
424 * \param image The image that is having its logo removed. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
425 * \param x x-coordinate of the pixel to blur. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
426 * \param y y-coordinate of the pixel to blur. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
427 * \param plane 0 = luma, 1 = blue chroma, 2 = red chroma (YUV). |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
428 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
429 * This function is the core of the filter. It takes a pixel that is inside the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
430 * logo and blurs it. It does so by finding the average of all the pixels within |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
431 * the mask and outside of the logo. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
432 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
433 void get_blur(const vf_instance_t * const vf, unsigned int * const value_out, const pgm_structure * const logo_mask, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
434 const mp_image_t * const image, const int x, const int y, const int plane) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
435 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
436 int mask_size; /* Mask size tells how large a circle to use. The radius is about (slightly larger than) mask size. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
437 /* Get values from vf->priv for faster dereferencing. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
438 int * * * mask = ((vf_priv_s *)vf->priv)->mask; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
439 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
440 int start_posx, start_posy, end_posx, end_posy; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
441 int i, j; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
442 unsigned int accumulator = 0, divisor = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
443 const unsigned char * mask_read_position; /* What pixel we are reading out of the circular blur mask. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
444 const unsigned char * logo_mask_read_position; /* What pixel we are reading out of the filter image. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
445 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
446 /* Prepare our bounding rectangle and clip it if need be. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
447 mask_size = test_filter(logo_mask, x, y); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
448 start_posx = max(0, x - mask_size); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
449 start_posy = max(0, y - mask_size); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
450 end_posx = min(image->width - 1, x + mask_size); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
451 end_posy = min(image->height - 1, y + mask_size); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
452 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
453 mask_read_position = image->planes[plane] + (image->stride[plane] * start_posy) + start_posx; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
454 logo_mask_read_position = logo_mask->pixel + (start_posy * logo_mask->width) + start_posx; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
455 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
456 for (j = start_posy; j <= end_posy; j++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
457 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
458 for (i = start_posx; i <= end_posx; i++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
459 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
460 if (!(*logo_mask_read_position) && mask[mask_size][i - start_posx][j - start_posy]) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
461 { /* Check to see if this pixel is in the logo or not. Only use the pixel if it is not. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
462 accumulator += *mask_read_position; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
463 divisor++; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
464 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
465 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
466 mask_read_position++; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
467 logo_mask_read_position++; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
468 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
469 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
470 mask_read_position += (image->stride[plane] - ((end_posx + 1) - start_posx)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
471 logo_mask_read_position += (logo_mask->width - ((end_posx + 1) - start_posx)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
472 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
473 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
474 if (divisor == 0) /* This means that not a single pixel is outside of the logo, so we have no data. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
475 { /* We should put some eye catching value here, to indicate the flaw to the user. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
476 *value_out = 255; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
477 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
478 else /* Else we need to normalise the data using the divisor. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
479 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
480 *value_out = (accumulator + (divisor / 2)) / divisor; /* Divide, taking into account average rounding error. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
481 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
482 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
483 return; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
484 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
485 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
486 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
487 * \brief Free a pgm_structure. Undoes load_pgm(...). |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
488 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
489 void destroy_pgm(pgm_structure * to_be_destroyed) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
490 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
491 if (to_be_destroyed == NULL) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
492 return; /* Don't do anything if a NULL pointer was passed it. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
493 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
494 /* Internally allocated memory. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
495 if (to_be_destroyed->pixel != NULL) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
496 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
497 free(to_be_destroyed->pixel); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
498 to_be_destroyed->pixel = NULL; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
499 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
500 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
501 /* Free the actual struct instance. This is done here and not by the calling function. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
502 free(to_be_destroyed); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
503 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
504 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
505 /** \brief Helper function for load_pgm(...) to skip whitespace. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
506 void load_pgm_skip(FILE *f) { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
507 int c, comment = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
508 do { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
509 c = fgetc(f); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
510 if (c == '#') |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
511 comment = 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
512 if (c == '\n') |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
513 comment = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
514 } while (c != EOF && (isspace(c) || comment)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
515 ungetc(c, f); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
516 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
517 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
518 #define REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE(message) {mp_msg(MSGT_VFILTER, MSGL_ERR, message); return NULL;} |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
519 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
520 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
521 * \brief Loads a raw pgm or ppm file into a newly created pgm_structure object. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
522 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
523 * \param file_name The name of the file to be loaded. So long as the file is a |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
524 * valid pgm or ppm file, it will load correctly, even if the |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
525 * extension is missing or invalid. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
526 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
527 * \return A pointer to the newly created pgm_structure object. Don't forget to |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
528 * call destroy_pgm(...) when you're done with this. If an error occurs, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
529 * NULL is returned. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
530 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
531 * Can load either raw pgm (P5) or raw ppm (P6) image files as a binary image. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
532 * While a pgm file will be loaded normally (greyscale), the only thing that is |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
533 * guaranteed with ppm is that all zero (R = 0, G = 0, B = 0) pixels will remain |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
534 * zero, and non-zero pixels will remain non-zero. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
535 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
536 pgm_structure * load_pgm(const char * file_name) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
537 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
538 unsigned char flags; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
539 int x, y; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
540 int maximum_greyscale_value; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
541 FILE * input; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
542 int pnm_number; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
543 pgm_structure * new_pgm = (pgm_structure *) safe_malloc (sizeof(pgm_structure)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
544 char * write_position; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
545 char * end_position; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
546 int image_size; /* width * height */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
547 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
548 if((input = fopen(file_name, "rb")) == NULL) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Unable to open file. File not found or insufficient permissions.\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
549 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
550 /* Parse the PGM header. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
551 if (fgetc(input) != 'P') REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: File is not a valid PGM or PPM file.\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
552 pnm_number = fgetc(input) - '0'; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
553 if (pnm_number != 5 && pnm_number != 6) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PNM file. Only raw PGM (Portable Gray Map) and raw PPM (Portable Pixel Map) subtypes are allowed.\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
554 load_pgm_skip(input); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
555 if (fscanf(input, "%i", &(new_pgm->width)) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
556 load_pgm_skip(input); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
557 if (fscanf(input, "%i", &(new_pgm->height)) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
558 load_pgm_skip(input); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
559 if (fscanf(input, "%i", &maximum_greyscale_value) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
560 if (maximum_greyscale_value >= 256) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove_logo: Only 1 byte per pixel (pgm) or 1 byte per color value (ppm) are supported.\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
561 load_pgm_skip(input); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
562 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
563 new_pgm->pixel = (unsigned char *) safe_malloc (sizeof(unsigned char) * new_pgm->width * new_pgm->height); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
564 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
565 /* Load the pixels. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
566 /* Note: I am aware that fgetc(input) isn't the fastest way of doing things, but it is quite compact and the code only runs once when the filter is initialized.*/ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
567 image_size = new_pgm->width * new_pgm->height; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
568 end_position = new_pgm->pixel + image_size; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
569 for (write_position = new_pgm->pixel; write_position < end_position; write_position++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
570 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
571 *write_position = fgetc(input); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
572 if (pnm_number == 6) /* This tests to see if the file is a PPM file. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
573 { /* If it is, then consider the pixel set if any of the three color channels are set. Since we just care about == 0 or != 0, a bitwise or will do the trick. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
574 *write_position |= fgetc(input); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
575 *write_position |= fgetc(input); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
576 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
577 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
578 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
579 return new_pgm; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
580 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
581 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
582 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
583 * \brief Generates a scaled down image with half width, height, and intensity. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
584 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
585 * \param vf Our struct for persistant data. In this case, it is used to update |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
586 * mask_max_size with the larger of the old or new value. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
587 * \param input_image The image from which the new half-sized one will be based. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
588 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
589 * \return The newly allocated and shrunken image. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
590 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
591 * This function not only scales down an image, but halves the value in each pixel |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
592 * too. The purpose of this is to produce a chroma filter image out of a luma |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
593 * filter image. The pixel values store the distance to the edge of the logo and |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
594 * halving the dimensions halves the distance. This function rounds up, because |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
595 * a downwards rounding error could cause the filter to fail, but an upwards |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
596 * rounding error will only cause a minor amount of excess blur in the chroma |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
597 * planes. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
598 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
599 pgm_structure * generate_half_size_image(vf_instance_t * vf, pgm_structure * input_image) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
600 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
601 int x, y; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
602 pgm_structure * new_pgm = (pgm_structure *) safe_malloc (sizeof(pgm_structure)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
603 int has_anything_changed = 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
604 int current_pass; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
605 int max_mask_size; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
606 char * current_pixel; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
607 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
608 new_pgm->width = input_image->width / 2; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
609 new_pgm->height = input_image->height / 2; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
610 new_pgm->pixel = (unsigned char *) safe_malloc (sizeof(unsigned char) * new_pgm->width * new_pgm->height); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
611 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
612 /* Copy over the image data, using the average of 4 pixels for to calculate each downsampled pixel. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
613 for (y = 0; y < new_pgm->height; y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
614 for (x = 0; x < new_pgm->width; x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
615 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
616 /* Set the pixel if there exists a non-zero value in the source pixels, else clear it. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
617 new_pgm->pixel[(y * new_pgm->width) + x] = input_image->pixel[((y << 1) * input_image->width) + (x << 1)] || |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
618 input_image->pixel[((y << 1) * input_image->width) + (x << 1) + 1] || |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
619 input_image->pixel[(((y << 1) + 1) * input_image->width) + (x << 1)] || |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
620 input_image->pixel[(((y << 1) + 1) * input_image->width) + (x << 1) + 1]; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
621 new_pgm->pixel[(y * new_pgm->width) + x] = min(1, new_pgm->pixel[(y * new_pgm->width) + x]); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
622 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
623 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
624 /* Now we need to recalculate the numbers for the smaller size. Just using the old_value / 2 can cause subtle |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
625 and fairly rare, but very nasty, bugs. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
626 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
627 current_pixel = new_pgm->pixel; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
628 /* First pass, set all non-zero values to 1. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
629 for (x = 0; x < new_pgm->height * new_pgm->width; x++, current_pixel++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
630 if(*current_pixel) *current_pixel = 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
631 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
632 /* Second pass and future passes. For each pass, if a pixel is itself the same value as the current pass, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
633 and its four neighbors are too, then it is incremented. If no pixels are incremented by the end of the pass, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
634 then we go again. Edge pixels are counted as always excluded (this should be true anyway for any sane mask, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
635 but if it isn't this will ensure that we eventually exit). */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
636 current_pass = 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
637 while (has_anything_changed) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
638 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
639 current_pass++; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
640 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
641 has_anything_changed = 0; /* If this doesn't get set by the end of this pass, then we're done. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
642 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
643 for (y = 1; y < new_pgm->height - 1; y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
644 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
645 for (x = 1; x < new_pgm->width - 1; x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
646 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
647 if (new_pgm->pixel[(y * new_pgm->width) + x] >= current_pass && /* By using >= instead of ==, we allow the algorithm to work in place. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
648 new_pgm->pixel[(y * new_pgm->width) + (x + 1)] >= current_pass && |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
649 new_pgm->pixel[(y * new_pgm->width) + (x - 1)] >= current_pass && |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
650 new_pgm->pixel[((y + 1) * new_pgm->width) + x] >= current_pass && |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
651 new_pgm->pixel[((y - 1) * new_pgm->width) + x] >= current_pass) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
652 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
653 new_pgm->pixel[(y * new_pgm->width) + x]++; /* Increment the value since it still has not been eroded, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
654 as evidenced by the if statement that just evaluated to true. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
655 has_anything_changed = 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
656 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
657 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
658 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
659 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
660 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
661 for (y = 1; y < new_pgm->height - 1; y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
662 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
663 for (x = 1; x < new_pgm->width - 1; x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
664 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
665 new_pgm->pixel[(y * new_pgm->width) + x] = apply_mask_fudge_factor(new_pgm->pixel[(y * new_pgm->width) + x]); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
666 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
667 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
668 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
669 max_mask_size = current_pass + 1; /* As a side-effect, we now know the maximum mask size, which we'll use to generate our masks. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
670 max_mask_size = apply_mask_fudge_factor(max_mask_size); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
671 /* Commit the newly calculated max_mask_size to the vf->priv struct. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
672 ((vf_priv_s *)vf->priv)->max_mask_size = max(max_mask_size, ((vf_priv_s *)vf->priv)->max_mask_size); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
673 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
674 return new_pgm; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
675 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
676 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
677 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
678 * \brief Checks if YV12 is supported by the next filter. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
679 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
680 static unsigned int find_best(struct vf_instance_s* vf){ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
681 int is_format_okay = vf->next->query_format(vf->next, IMGFMT_YV12); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
682 if ((is_format_okay & VFCAP_CSP_SUPPORTED_BY_HW) || (is_format_okay & VFCAP_CSP_SUPPORTED)) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
683 return IMGFMT_YV12; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
684 else |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
685 return 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
686 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
687 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
688 //===========================================================================// |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
689 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
690 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
691 * \brief Configure the filter and call the next filter's config function. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
692 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
693 static int config(struct vf_instance_s* vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
694 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
695 if(!(((vf_priv_s *)vf->priv)->fmt=find_best(vf))) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
696 return 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
697 else |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
698 return vf_next_config(vf,width,height,d_width,d_height,flags,((vf_priv_s *)vf->priv)->fmt); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
699 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
700 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
701 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
702 * \brief Removes the logo from a plane (either luma or chroma). |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
703 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
704 * \param vf Not needed by this function, but needed by the blur function. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
705 * \param source The image to have it's logo removed. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
706 * \param destination Where the output image will be stored. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
707 * \param source_stride How far apart (in memory) two consecutive lines are. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
708 * \param destination Same as source_stride, but for the destination image. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
709 * \param width Width of the image. This is the same for source and destination. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
710 * \param height Height of the image. This is the same for source and destination. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
711 * \param is_image_direct If the image is direct, then source and destination are |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
712 * the same and we can save a lot of time by not copying pixels that |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
713 * haven't changed. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
714 * \param filter The image that stores the distance to the edge of the logo for |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
715 * each pixel. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
716 * \param logo_start_x Smallest x-coordinate that contains at least 1 logo pixel. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
717 * \param logo_start_y Smallest y-coordinate that contains at least 1 logo pixel. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
718 * \param logo_end_x Largest x-coordinate that contains at least 1 logo pixel. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
719 * \param logo_end_y Largest y-coordinate that contains at least 1 logo pixel. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
720 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
721 * This function processes an entire plane. Pixels outside of the logo are copied |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
722 * to the output without change, and pixels inside the logo have the de-blurring |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
723 * function applied. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
724 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
725 static void convert_yv12(const vf_instance_t * const vf, const char * const source, const int source_stride, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
726 const mp_image_t * const source_image, const int width, const int height, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
727 char * const destination, const int destination_stride, int is_image_direct, pgm_structure * filter, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
728 const int plane, const int logo_start_x, const int logo_start_y, const int logo_end_x, const int logo_end_y) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
729 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
730 int y; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
731 int x; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
732 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
733 /* These pointers point to where we are getting our pixel data (inside mpi) and where we are storing it (inside dmpi). */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
734 const unsigned char * source_line; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
735 unsigned char * destination_line; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
736 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
737 if (!is_image_direct) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
738 memcpy_pic(destination, source, width, height, destination_stride, source_stride); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
739 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
740 for (y = logo_start_y; y <= logo_end_y; y++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
741 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
742 source_line = (const unsigned char *) source + (source_stride * y); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
743 destination_line = (unsigned char *) destination + (destination_stride * y); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
744 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
745 for (x = logo_start_x; x <= logo_end_x; x++) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
746 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
747 unsigned int output; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
748 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
749 if (filter->pixel[(y * filter->width) + x]) /* Only process if we are in the logo. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
750 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
751 get_blur(vf, &output, filter, source_image, x, y, plane); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
752 destination_line[x] = output; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
753 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
754 else /* Else just copy the data. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
755 if (!is_image_direct) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
756 destination_line[x] = source_line[x]; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
757 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
758 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
759 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
760 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
761 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
762 * \brief Process a frame. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
763 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
764 * \param mpi The image sent to use by the previous filter. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
765 * \param dmpi Where we will store the processed output image. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
766 * \param vf This is how the filter gets access to it's persistant data. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
767 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
768 * \return The return code of the next filter, or 0 on failure/error. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
769 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
770 * This function processes an entire frame. The frame is sent by the previous |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
771 * filter, has the logo removed by the filter, and is then sent to the next |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
772 * filter. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
773 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
774 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
775 mp_image_t *dmpi; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
776 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
777 dmpi=vf_get_image(vf->next,((vf_priv_s *)vf->priv)->fmt, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
778 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
779 mpi->w, mpi->h); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
780 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
781 /* Check to make sure that the filter image and the video stream are the same size. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
782 if ((((vf_priv_s *)vf->priv)->filter->width != mpi->w) || (((vf_priv_s *)vf->priv)->filter->height != mpi->h)) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
783 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
784 mp_msg(MSGT_VFILTER,MSGL_ERR, "Filter image and video stream are not of the same size. (Filter: %d x %d, Stream: %d x %d)\n", |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
785 ((vf_priv_s *)vf->priv)->filter->width, ((vf_priv_s *)vf->priv)->filter->height, mpi->w, mpi->h); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
786 return 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
787 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
788 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
789 switch(dmpi->imgfmt){ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
790 case IMGFMT_YV12: |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
791 convert_yv12(vf, mpi->planes[0], mpi->stride[0], mpi, mpi->w, mpi->h, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
792 dmpi->planes[0], dmpi->stride[0], |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
793 mpi->flags & MP_IMGFLAG_DIRECT, ((vf_priv_s *)vf->priv)->filter, 0, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
794 ((vf_priv_s *)vf->priv)->bounding_rectangle_posx1, ((vf_priv_s *)vf->priv)->bounding_rectangle_posy1, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
795 ((vf_priv_s *)vf->priv)->bounding_rectangle_posx2, ((vf_priv_s *)vf->priv)->bounding_rectangle_posy2); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
796 convert_yv12(vf, mpi->planes[1], mpi->stride[1], mpi, mpi->w / 2, mpi->h / 2, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
797 dmpi->planes[1], dmpi->stride[1], |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
798 mpi->flags & MP_IMGFLAG_DIRECT, ((vf_priv_s *)vf->priv)->half_size_filter, 1, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
799 ((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posx1, ((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posy1, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
800 ((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posx2, ((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posy2); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
801 convert_yv12(vf, mpi->planes[2], mpi->stride[2], mpi, mpi->w / 2, mpi->h / 2, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
802 dmpi->planes[2], dmpi->stride[2], |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
803 mpi->flags & MP_IMGFLAG_DIRECT, ((vf_priv_s *)vf->priv)->half_size_filter, 2, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
804 ((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posx1, ((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posy1, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
805 ((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posx2, ((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posy2); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
806 break; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
807 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
808 default: |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
809 mp_msg(MSGT_VFILTER,MSGL_ERR,"Unhandled format: 0x%X\n",dmpi->imgfmt); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
810 return 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
811 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
812 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
813 return vf_next_put_image(vf,dmpi); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
814 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
815 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
816 //===========================================================================// |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
817 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
818 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
819 * \brief Checks to see if the next filter accepts YV12 images. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
820 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
821 static int query_format(struct vf_instance_s * vf, unsigned int fmt) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
822 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
823 if (fmt == IMGFMT_YV12) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
824 return vf->next->query_format(vf->next, IMGFMT_YV12); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
825 else |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
826 return 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
827 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
828 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
829 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
830 * \brief Initializes our filter. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
831 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
832 * \param args The arguments passed in from the command line go here. This |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
833 * filter expects only a single argument telling it where the PGM |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
834 * or PPM file that describes the logo region is. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
835 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
836 * This sets up our instance variables and parses the arguments to the filter. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
837 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
838 static int open(vf_instance_t * vf, char * args) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
839 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
840 vf->priv = safe_malloc(sizeof(vf_priv_s)); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
841 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
842 /* Load our filter image. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
843 if (args) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
844 ((vf_priv_s *)vf->priv)->filter = load_pgm(args); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
845 else |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
846 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
847 mp_msg(MSGT_VFILTER, MSGL_ERR, "[vf]remove_logo usage: remove_logo=/path/to/filter_image_file.pgm\n"); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
848 free(vf->priv); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
849 return 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
850 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
851 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
852 if (((vf_priv_s *)vf->priv)->filter == NULL) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
853 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
854 /* Error message was displayed by load_pgm(). */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
855 free(vf->priv); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
856 return 0; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
857 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
858 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
859 /* Create the scaled down filter image for the chroma planes. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
860 convert_mask_to_strength_mask(vf, ((vf_priv_s *)vf->priv)->filter); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
861 ((vf_priv_s *)vf->priv)->half_size_filter = generate_half_size_image(vf, ((vf_priv_s *)vf->priv)->filter); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
862 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
863 /* Now that we know how many masks we need (the info is in vf), we can generate the masks. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
864 initialize_masks(vf); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
865 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
866 /* Calculate our bounding rectangles, which determine in what region the logo resides for faster processing. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
867 calculate_bounding_rectangle(&((vf_priv_s *)vf->priv)->bounding_rectangle_posx1, &((vf_priv_s *)vf->priv)->bounding_rectangle_posy1, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
868 &((vf_priv_s *)vf->priv)->bounding_rectangle_posx2, &((vf_priv_s *)vf->priv)->bounding_rectangle_posy2, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
869 ((vf_priv_s *)vf->priv)->filter); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
870 calculate_bounding_rectangle(&((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posx1, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
871 &((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posy1, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
872 &((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posx2, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
873 &((vf_priv_s *)vf->priv)->bounding_rectangle_half_size_posy2, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
874 ((vf_priv_s *)vf->priv)->half_size_filter); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
875 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
876 vf->config=config; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
877 vf->put_image=put_image; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
878 vf->query_format=query_format; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
879 return 1; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
880 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
881 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
882 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
883 * \brief Frees memory that our filter allocated. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
884 * |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
885 * This is called at exit-time. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
886 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
887 void uninit(vf_instance_t * vf) |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
888 { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
889 /* Destroy our masks and images. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
890 destroy_pgm(((vf_priv_s *)vf->priv)->filter); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
891 destroy_pgm(((vf_priv_s *)vf->priv)->half_size_filter); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
892 destroy_masks(vf); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
893 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
894 /* Destroy our private structure that had been used to store those masks and images. */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
895 free(vf->priv); |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
896 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
897 return; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
898 } |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
899 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
900 /** |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
901 * \brief Meta data about our filter. |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
902 */ |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
903 vf_info_t vf_info_remove_logo = { |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
904 "Removes a tv logo based on a mask image.", |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
905 "remove-logo", |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
906 "Robert Edele", |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
907 "", |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
908 open, |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
909 NULL |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
910 }; |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
911 |
98cc17f305de
remove_logo filter by yartrebo, committed with fixes for c++ variable declarations
rfelker
parents:
diff
changeset
|
912 //===========================================================================// |