1 /***************************************************************************
2                           ADM_genvideo.cpp  -  description
3                              -------------------
4     begin                : Sun Apr 14 2002
5     copyright            : (C) 2002 by mean
6     email                : fixounet@free.fr
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 
19 
20 #include "ADM_default.h"
21 //#include "ADM_editor/ADM_edit.hxx"
22 #include "ADM_videoFilter.h"
23 
getPixel(int32_t x,int32_t y,uint8_t * data)24 uint8_t AVDMGenericVideoStream::getPixel(int32_t x,int32_t y,uint8_t *data)
25 {
26 		if(x>(int32_t)_info.width)
27   			{
28             	x=2*_info.width-x;
29        	}
30        if(y>(int32_t)_info.height)
31   			{
32             	y=2*_info.height-y;
33        	}
34         if(   x<0)
35           x=-x;
36         if(   y<0)
37           y=-y;
38 
39           return *(data+x+(y*_info.width));
40 }
41 
getPARWidth(void)42 uint32_t   AVDMGenericVideoStream::getPARWidth(void)
43 {
44   if(_in)
45   {
46     return _in-> getPARWidth();
47   }
48   return 1;
49 }
50 /* If there is a father, retrieve PAR from him else assume it is 1:1 */
getPARHeight(void)51 uint32_t   AVDMGenericVideoStream::getPARHeight(void)
52 {
53   if(_in)
54   {
55     return _in-> getPARHeight();
56   }
57   return 1;
58 }
59 
60 
getPixelU(int32_t x,int32_t y,uint8_t * data)61 uint8_t AVDMGenericVideoStream::getPixelU(int32_t x,int32_t y,uint8_t *data)
62 {
63 int32_t w=_info.width>>1;
64 int32_t h=_info.height>>1;
65 
66 			x=x>>1;
67 			y=y>>1;
68 
69 		if(x>w)
70   			{
71             	x=2*w-x;
72        	}
73        if(y>h)
74   			{
75             	y=2*h-y;
76        	}
77         if(   x<0)
78           x=-x;
79         if(   y<0)
80           y=-y;
81 
82           return *(data+x+(y*w));
83 
84 
85 }
setPixelU(uint8_t val,int32_t x,int32_t y,uint8_t * data)86 uint8_t AVDMGenericVideoStream::setPixelU(uint8_t val,int32_t x,int32_t y,uint8_t *data)
87 {
88 int32_t w=_info.width>>1;
89 int32_t h=_info.height>>1;
90 
91 			x=x>>1;
92 			y=y>>1;
93 
94 		if(x>w)
95   			{
96             	x=2*w-x;
97        	}
98        if(y>h)
99   			{
100             	y=2*h-y;
101        	}
102         if(   x<0)
103           x=-x;
104         if(   y<0)
105           y=-y;
106 
107            *(data+x+(y*w))=val;
108            return 1;
109 
110 
111 }
unPackChroma(uint8_t * ssrc,uint8_t * ddst)112 uint8_t AVDMGenericVideoStream::unPackChroma(uint8_t *ssrc,uint8_t *ddst)
113 {
114 uint8_t *src,*dst,*srcu,*srcv; //,*dstu,*dstv;
115 	src=ssrc;
116  	dst=ddst;
117    	// unpack   luma
118 				for(uint32_t l=_info.width*_info.height;l>0;l--)
119     				{
120                    	*dst++=*src++;
121                     	dst+=2;
122           			}
123          	// unpack   chroma
124 
125 	          srcu=ssrc+_info.width*_info.height;
126        		srcv=srcu+((_info.width*_info.height)>>2);
127          		dst=ddst+1;
128 
129              for(int32_t y=0;y<(int32_t)(_info.height >>1);y++)
130            	{
131 		         		for(int32_t x=0;x<(int32_t)(_info.width );x++)
132              			{
133 
134                  			*dst=*(dst+3*_info.width)=*srcu;
135                     		dst++;
136                  			*dst=*(dst+3*_info.width)=*srcv;
137                     		dst+=2;
138                     		if(x&1) srcu++;
139                     		if(x&1) srcv++;
140 
141                   	}
142                    dst+=_info.width*3;
143                }
144           return 1;
145 }
146 
147 // EOF
148