~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_video/ADM_vidHue.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

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