annotate libmpcodecs/vf_yuvcsp.c @ 36295:0bd0297b073a

Handle special argument -1 to switch_ratio as intended. Reset to the original aspect ratio that would have been used for the very first rescaling rather than to the display size ratio. This will now handle anamorphic videos correctly as well.
author ib
date Thu, 01 Aug 2013 21:18:14 +0000
parents 7af3e6f901fd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30421
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
1 /*
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
2 * This file is part of MPlayer.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
3 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
5 * it under the terms of the GNU General Public License as published by
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
7 * (at your option) any later version.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
8 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
12 * GNU General Public License for more details.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
13 *
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
14 * You should have received a copy of the GNU General Public License along
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
17 */
bbb6ebec87a0 Add missing license headers to all files in the libmpcodecs directory.
diego
parents: 29263
diff changeset
18
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
19 #include <stdio.h>
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
20 #include <stdlib.h>
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
21 #include <string.h>
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
22 #include <inttypes.h>
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
23
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 11536
diff changeset
24 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 11536
diff changeset
25 #include "mp_msg.h"
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
26
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
27 #include "img_format.h"
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
28 #include "mp_image.h"
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
29 #include "vf.h"
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
30
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
31 struct vf_priv_s {
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
32 int csp;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
33 };
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
34
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
35 //===========================================================================//
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
36
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
37 static int config(struct vf_instance *vf,
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
38 int width, int height, int d_width, int d_height,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
39 unsigned int flags, unsigned int outfmt){
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
40 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
41 }
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
42
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
43 static inline int clamp_y(int x){
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
44 return (x > 235) ? 235 : (x < 16) ? 16 : x;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
45 }
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
46
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
47 static inline int clamp_c(int x){
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
48 return (x > 240) ? 240 : (x < 16) ? 16 : x;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
49 }
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
50
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
51 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
52 int i,j;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
53 uint8_t *y_in, *cb_in, *cr_in;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
54 uint8_t *y_out, *cb_out, *cr_out;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
55
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
56 vf->dmpi=vf_get_image(vf->next,mpi->imgfmt,
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
57 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
58 mpi->width, mpi->height);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25221
diff changeset
59
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
60 y_in = mpi->planes[0];
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
61 cb_in = mpi->planes[1];
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
62 cr_in = mpi->planes[2];
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
63
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
64 y_out = vf->dmpi->planes[0];
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
65 cb_out = vf->dmpi->planes[1];
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
66 cr_out = vf->dmpi->planes[2];
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25221
diff changeset
67
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
68 for (i = 0; i < mpi->height; i++)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
69 for (j = 0; j < mpi->width; j++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
70 y_out[i*vf->dmpi->stride[0]+j] = clamp_y(y_in[i*mpi->stride[0]+j]);
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
71
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
72 for (i = 0; i < mpi->chroma_height; i++)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
73 for (j = 0; j < mpi->chroma_width; j++)
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
74 {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
75 cb_out[i*vf->dmpi->stride[1]+j] = clamp_c(cb_in[i*mpi->stride[1]+j]);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
76 cr_out[i*vf->dmpi->stride[2]+j] = clamp_c(cr_in[i*mpi->stride[2]+j]);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
77 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25221
diff changeset
78
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
79 return vf_next_put_image(vf,vf->dmpi, pts);
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
80 }
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
81
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
82 //===========================================================================//
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
83
24867
e5b4a794ac92 Comment out uninit function, its use is commented out. Fixes warning:
diego
parents: 17906
diff changeset
84 /*
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
85 static void uninit(struct vf_instance *vf){
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
86 free(vf->priv);
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
87 }
24867
e5b4a794ac92 Comment out uninit function, its use is commented out. Fixes warning:
diego
parents: 17906
diff changeset
88 */
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
89
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
90 static int query_format(struct vf_instance *vf, unsigned int fmt){
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
91 switch(fmt){
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
92 case IMGFMT_YV12:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
93 case IMGFMT_I420:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
94 case IMGFMT_IYUV:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
95 return 1;
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
96 }
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
97 return 0;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
98 }
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
99
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30421
diff changeset
100 static int vf_open(vf_instance_t *vf, char *args){
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
101 vf->config=config;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
102 vf->put_image=put_image;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
103 // vf->uninit=uninit;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
104 vf->query_format=query_format;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
105 // vf->priv=calloc(1, sizeof(struct vf_priv_s));
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
106 // if (args)
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
107 // vf->priv->csp = atoi(args);
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
108 return 1;
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
109 }
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
110
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 24867
diff changeset
111 const vf_info_t vf_info_yuvcsp = {
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
112 "yuv colorspace converter",
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
113 "yuvcsp",
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
114 "Alex Beregszaszi",
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
115 "",
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30421
diff changeset
116 vf_open,
11536
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
117 NULL
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
118 };
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
119
017a7e90fcf1 yuv colorspace converter
alex
parents:
diff changeset
120 //===========================================================================//