annotate libmpcodecs/vf_mirror.c @ 34177:fadc00cc31d3

Optimize TranslateFilename(). Replace for loop with index by while loop with pointer. Unite the if conditions.
author ib
date Wed, 26 Oct 2011 15:52:06 +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
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
19 #include <stdio.h>
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
20 #include <stdlib.h>
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
21 #include <string.h>
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
22 #include <inttypes.h>
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
23
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9593
diff changeset
24 #include "config.h"
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 9593
diff changeset
25 #include "mp_msg.h"
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
26
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
27 #include "img_format.h"
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
28 #include "mp_image.h"
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
29 #include "vf.h"
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
30
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
31
8748
30f7df2d1bed fixed 16bpp packed YUV formats
arpi
parents: 7368
diff changeset
32 static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,unsigned int fmt){
5772
cfb787b821a0 10l, >1bpp modes fixed..., x<->y swapped
arpi
parents: 5763
diff changeset
33 int y;
cfb787b821a0 10l, >1bpp modes fixed..., x<->y swapped
arpi
parents: 5763
diff changeset
34 for(y=0;y<h;y++){
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
35 int x;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
36 switch(bpp){
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
37 case 1:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
38 for(x=0;x<w;x++) dst[x]=src[w-x-1];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
39 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
40 case 2:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
41 switch(fmt){
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
42 case IMGFMT_UYVY: {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
43 // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
44 int w2=w>>1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
45 for(x=0;x<w2;x++){
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
46 // TODO: optimize this...
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
47 dst[x*4+0]=src[0+(w2-x-1)*4];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
48 dst[x*4+1]=src[3+(w2-x-1)*4];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
49 dst[x*4+2]=src[2+(w2-x-1)*4];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
50 dst[x*4+3]=src[1+(w2-x-1)*4];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
51 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
52 break; }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
53 case IMGFMT_YUY2:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
54 case IMGFMT_YVYU: {
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
55 // packed YUV is tricky. U,V are 32bpp while Y is 16bpp:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
56 int w2=w>>1;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
57 for(x=0;x<w2;x++){
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
58 // TODO: optimize this...
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
59 dst[x*4+0]=src[2+(w2-x-1)*4];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
60 dst[x*4+1]=src[1+(w2-x-1)*4];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
61 dst[x*4+2]=src[0+(w2-x-1)*4];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
62 dst[x*4+3]=src[3+(w2-x-1)*4];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
63 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
64 break; }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
65 default:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
66 for(x=0;x<w;x++) *((short*)(dst+x*2))=*((short*)(src+(w-x-1)*2));
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
67 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
68 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
69 case 3:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
70 for(x=0;x<w;x++){
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
71 dst[x*3+0]=src[0+(w-x-1)*3];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
72 dst[x*3+1]=src[1+(w-x-1)*3];
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
73 dst[x*3+2]=src[2+(w-x-1)*3];
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 break;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
76 case 4:
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
77 for(x=0;x<w;x++) *((int*)(dst+x*4))=*((int*)(src+(w-x-1)*4));
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
78 }
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
79 src+=srcstride;
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
80 dst+=dststride;
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
81 }
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
82 }
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
83
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
84 //===========================================================================//
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
85
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
86 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
87 mp_image_t *dmpi;
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
88
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
89 // hope we'll get DR buffer:
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
90 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
91 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
92 mpi->w, mpi->h);
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
93
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
94 if(mpi->flags&MP_IMGFLAG_PLANAR){
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
95 mirror(dmpi->planes[0],mpi->planes[0],
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
96 dmpi->stride[0],mpi->stride[0],
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
97 dmpi->w,dmpi->h,1,mpi->imgfmt);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
98 mirror(dmpi->planes[1],mpi->planes[1],
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
99 dmpi->stride[1],mpi->stride[1],
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
100 dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
101 mirror(dmpi->planes[2],mpi->planes[2],
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
102 dmpi->stride[2],mpi->stride[2],
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
103 dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt);
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
104 } else {
32702
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
105 mirror(dmpi->planes[0],mpi->planes[0],
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
106 dmpi->stride[0],mpi->stride[0],
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
107 dmpi->w,dmpi->h,dmpi->bpp>>3,mpi->imgfmt);
7af3e6f901fd Convert some tabs to whitespace to allow using MPlayer filter sourcecode in FFmpeg.
cehoyos
parents: 30642
diff changeset
108 dmpi->planes[1]=mpi->planes[1]; // passthrough rgb8 palette
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
109 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 25221
diff changeset
110
17906
20aca9baf5d8 passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents: 17012
diff changeset
111 return vf_next_put_image(vf,dmpi, pts);
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
112 }
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
113
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
114 //===========================================================================//
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
115
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30421
diff changeset
116 static int vf_open(vf_instance_t *vf, char *args){
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
117 //vf->config=config;
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
118 vf->put_image=put_image;
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
119 return 1;
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
120 }
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
121
25221
00fff9a3b735 Make all vf_info_t structs const
reimar
parents: 23373
diff changeset
122 const vf_info_t vf_info_mirror = {
5772
cfb787b821a0 10l, >1bpp modes fixed..., x<->y swapped
arpi
parents: 5763
diff changeset
123 "horizontal mirror",
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
124 "mirror",
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
125 "Eyck",
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
126 "",
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30421
diff changeset
127 vf_open,
9593
e9a2af584986 Add the new -vf option wich is the same as vop in reverse order.
albeu
parents: 9279
diff changeset
128 NULL
5763
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
129 };
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
130
e9fb293c53d2 Complement existing filters - rotate and flip.
eyck
parents:
diff changeset
131 //===========================================================================//