~ubuntu-branches/ubuntu/feisty/avidemux/feisty

« back to all changes in this revision

Viewing changes to avidemux/ADM_video/ADM_vidHue.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Marillat
  • Date: 2005-05-25 13:02:29 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20050525130229-jw94cav0yhmg7vjw
Tags: 1:2.0.40-0.0
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          Hue/Saturation filter ported from mplayer 
 
3
 (c) Michael Niedermayer
 
4
 ***************************************************************************/
 
5
 
 
6
/***************************************************************************
 
7
 *                                                                         *
 
8
 *   This program is free software; you can redistribute it and/or modify  *
 
9
 *   it under the terms of the GNU General Public License as published by  *
 
10
 *   the Free Software Foundation; either version 2 of the License, or     *
 
11
 *   (at your option) any later version.                                   *
 
12
 *                                                                         *
 
13
 ***************************************************************************/
 
14
 
 
15
#include <stdio.h>
 
16
#include <math.h>
 
17
 
 
18
#include <stdlib.h>
 
19
#include <string.h>
 
20
#include <ADM_assert.h>
 
21
 
 
22
#include "config.h"
 
23
#include "fourcc.h"
 
24
#include "avio.hxx"
 
25
#include "config.h"
 
26
#include "avi_vars.h"
 
27
#ifdef HAVE_ENCODER
 
28
 
 
29
 
 
30
#include "ADM_toolkit/toolkit.hxx"
 
31
#include "ADM_editor/ADM_edit.hxx"
 
32
#include "ADM_video/ADM_genvideo.hxx"
 
33
#include "ADM_video/ADM_vidFlipV.h"
 
34
#include "ADM_filter/video_filters.h"
 
35
#include "ADM_dialog/DIA_enter.h"
 
36
#include "ADM_video/ADM_cache.h"
 
37
 
 
38
#include "admmangle.h"
 
39
#include "ADM_vidHue.h"
 
40
static FILTER_PARAM HueParam={2,{"hue","saturation"}};
 
41
 
 
42
extern uint8_t DIA_getHue(Hue_Param *param, AVDMGenericVideoStream *in);
 
43
 
 
44
class  ADMVideoHue:public AVDMGenericVideoStream
 
45
{
 
46
 
 
47
  protected:
 
48
    AVDMGenericVideoStream  *_in;           
 
49
    virtual char            *printConf(void);
 
50
            void            update(void);
 
51
            Hue_Param       *_param;    
 
52
            VideoCache      *vidCache; 
 
53
            float           _hue;
 
54
            float           _saturation;
 
55
  public:
 
56
                
 
57
                        ADMVideoHue(  AVDMGenericVideoStream *in,CONFcouple *setup);
 
58
    virtual             ~ADMVideoHue();
 
59
    virtual uint8_t     configure(AVDMGenericVideoStream *in);
 
60
    virtual uint8_t     getFrameNumberNoAlloc(uint32_t frame, uint32_t *len,
 
61
                                          ADMImage *data,uint32_t *flags);
 
62
 
 
63
             uint8_t     getCoupledConf( CONFcouple **couples);
 
64
}     ;
 
65
 
 
66
SCRIPT_CREATE(hue_script,ADMVideoHue,HueParam);
 
67
BUILD_CREATE(hue_create,ADMVideoHue);
 
68
 
 
69
void HueProcess_C(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride,
 
70
                    int w, int h, float hue, float sat)
 
71
{
 
72
        int i;
 
73
        const int s= (int)rint(sin(hue) * (1<<16) * sat);
 
74
        const int c= (int)rint(cos(hue) * (1<<16) * sat);
 
75
 
 
76
        while (h--) {
 
77
                for (i = 0; i<w; i++)
 
78
                {
 
79
                        const int u= usrc[i] - 128;
 
80
                        const int v= vsrc[i] - 128;
 
81
                        int new_u= (c*u - s*v + (1<<15) + (128<<16))>>16;
 
82
                        int new_v= (s*u + c*v + (1<<15) + (128<<16))>>16;
 
83
                        if(new_u & 768) new_u= (-new_u)>>31;
 
84
                        if(new_v & 768) new_v= (-new_v)>>31;
 
85
                        udst[i]= new_u;
 
86
                        vdst[i]= new_v;
 
87
                }
 
88
                usrc += srcstride;
 
89
                vsrc += srcstride;
 
90
                udst += dststride;
 
91
                vdst += dststride;
 
92
        }
 
93
}
 
94
 
 
95
 
 
96
uint8_t ADMVideoHue::configure(AVDMGenericVideoStream *in)
 
97
{
 
98
uint8_t r=0;
 
99
  _in=in;   
 
100
  r=  DIA_getHue(_param, in);
 
101
  if(r) update();
 
102
  return r;  
 
103
}
 
104
char *ADMVideoHue::printConf( void )
 
105
{
 
106
  static char buf[50];
 
107
        
 
108
  sprintf((char *)buf," Hue :%2.2f %2.2f",_param->hue,_param->saturation);
 
109
  return buf;
 
110
}
 
111
 
 
112
ADMVideoHue::ADMVideoHue(  AVDMGenericVideoStream *in,CONFcouple *couples)
 
113
{
 
114
  
 
115
  _in=in;         
 
116
  memcpy(&_info,_in->getInfo(),sizeof(_info));    
 
117
  _info.encoding=1; 
 
118
  _param=new  Hue_Param;
 
119
  if(couples)
 
120
  {                 
 
121
    GET(hue);    
 
122
    GET(saturation); 
 
123
  }
 
124
  else
 
125
  {
 
126
    _param->hue =0.0;                
 
127
    _param->saturation=1.0;
 
128
  }      
 
129
  vidCache=new VideoCache(1,_in);
 
130
  update();
 
131
}
 
132
void ADMVideoHue::update(void)
 
133
{
 
134
    _hue=_param->hue*M_PI/180.;
 
135
    _saturation=(100+_param->saturation)/100;
 
136
}
 
137
ADMVideoHue::~ADMVideoHue()
 
138
{
 
139
  delete _param;
 
140
  delete vidCache;
 
141
  
 
142
}
 
143
uint8_t ADMVideoHue::getCoupledConf( CONFcouple **couples)
 
144
{
 
145
  ADM_assert(_param);
 
146
  *couples=new CONFcouple(2);
 
147
 
 
148
 
 
149
                CSET(hue);
 
150
                CSET(saturation);
 
151
                return 1;
 
152
}
 
153
 
 
154
 
 
155
uint8_t ADMVideoHue::getFrameNumberNoAlloc(uint32_t frame,
 
156
                                             uint32_t *len,
 
157
                                             ADMImage *data,
 
158
                                             uint32_t *flags)
 
159
{
 
160
  ADMImage *mysrc=NULL;
 
161
  
 
162
 
 
163
  if(frame>=_info.nb_frames) return 0;
 
164
  
 
165
  mysrc=vidCache->getImage(frame);
 
166
  if(!mysrc) return 0;
 
167
  memcpy(YPLANE(data),YPLANE(mysrc),_info.width*_info.height);
 
168
  HueProcess_C(VPLANE(data), UPLANE(data),
 
169
        VPLANE(mysrc), UPLANE(mysrc),
 
170
        _info.width>>1,_info.width>>1,
 
171
        _info.width>>1,_info.height>>1, 
 
172
        _hue, _saturation);
 
173
 
 
174
  vidCache->unlockAll();
 
175
  
 
176
  
 
177
  return 1;
 
178
}
 
179
 
 
180
  
 
181
#endif