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

« back to all changes in this revision

Viewing changes to avidemux/ADM_colorspace/ADM_colorspace.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
    copyright            : (C) 2007 by mean
 
3
    email                : fixounet@free.fr
 
4
    
 
5
 
 
6
 ***************************************************************************/
 
7
 
 
8
/***************************************************************************
 
9
 *                                                                         *
 
10
 *   This program is free software; you can redistribute it and/or modify  *
 
11
 *   it under the terms of the GNU General Public License as published by  *
 
12
 *   the Free Software Foundation; either version 2 of the License, or     *
 
13
 *   (at your option) any later version.                                   *
 
14
 *                                                                         *
 
15
 ***************************************************************************/
 
16
#include "config.h"
 
17
#include <stdio.h>
 
18
#include <stdlib.h>
 
19
 
 
20
#include <string.h>
 
21
 
 
22
#include "ADM_utilities/default.h"
 
23
#include <ADM_assert.h>
 
24
 
 
25
#include "colorspace.h"
 
26
 
 
27
#include "ADM_osSupport/ADM_cpuCap.h"
 
28
#if (defined( ARCH_X86)  || defined(ARCH_X86_64))
 
29
extern "C" {
 
30
#include "ADM_lavcodec/avcodec.h"
 
31
}
 
32
#endif
 
33
 
 
34
#include "../ADM_lavutil/avutil.h"
 
35
#include "../ADM_libswscale/swscale.h"
 
36
#include "ADM_rgb.h" 
 
37
#include "ADM_colorspace.h"
 
38
 
 
39
#if (defined( ARCH_X86)  || defined(ARCH_X86_64))               
 
40
                #define ADD(x,y) if( CpuCaps::has##x()) flags|=SWS_CPU_CAPS_##y;
 
41
#define FLAGS()         ADD(MMX,MMX);                           ADD(3DNOW,3DNOW);               ADD(MMXEXT,MMX2);
 
42
#else
 
43
#ifdef USE_ALTIVEC
 
44
#define FLAGS() flags|=SWS_CPU_CAPS_ALTIVEC;
 
45
#else
 
46
#define FLAGS()
 
47
#endif
 
48
#endif
 
49
 
 
50
#define CONTEXT (SwsContext *)context
 
51
 
 
52
/**
 
53
    \fn ADMColor2LAVColor
 
54
    \brief Convert ADM colorspace type swscale/lavcodec colorspace name
 
55
 
 
56
*/
 
57
static PixelFormat ADMColor2LAVColor(ADM_colorspace fromColor)
 
58
{
 
59
  switch(fromColor)
 
60
  {
 
61
    case ADM_COLOR_YV12: return PIX_FMT_YUV420P;
 
62
    case ADM_COLOR_YUV422P: return PIX_FMT_YUV422P;
 
63
    default : ADM_assert(0); 
 
64
  }
 
65
  return PIX_FMT_YUV420P;
 
66
}
 
67
/**
 
68
      \fn getStrideAndPointers
 
69
      \brief Fill in strides etc.. needed by libswscale
 
70
*/
 
71
uint8_t ADMColorspace::getStrideAndPointers(uint8_t  *from,ADM_colorspace fromColor,uint8_t **srcData,int *srcStride)
 
72
{
 
73
  switch(fromColor)
 
74
  {
 
75
    case  ADM_COLOR_YV12:
 
76
            srcData[0]=from;
 
77
            srcData[1]=from+width*height;
 
78
            srcData[2]=from+((5*width*height)>>2);
 
79
            srcStride[0]=width;
 
80
            srcStride[1]=width>>1;
 
81
            srcStride[2]=width>>1;
 
82
            break;
 
83
    case  ADM_COLOR_YUV422P:
 
84
            srcData[0]=from;
 
85
            srcData[1]=from+width*height;
 
86
            srcData[2]=from+((3*width*height)>>1);
 
87
            srcStride[0]=width;
 
88
            srcStride[1]=width>>1;
 
89
            srcStride[2]=width>>1;
 
90
            break;
 
91
 
 
92
    default:
 
93
        ADM_assert(0);
 
94
  }
 
95
  return 1;
 
96
}
 
97
/**
 
98
    \fn  convert
 
99
    \brief Do the color conversion
 
100
  @param from Source image
 
101
  @param to Target image
 
102
*/
 
103
 
 
104
uint8_t ADMColorspace::convert(uint8_t  *from, uint8_t *to)
 
105
{
 
106
  uint8_t *srcData[3];
 
107
  uint8_t *dstData[3];
 
108
  int srcStride[3];
 
109
  int dstStride[3];
 
110
  
 
111
  getStrideAndPointers(from,fromColor,srcData,srcStride);
 
112
  getStrideAndPointers(to,toColor,dstData,dstStride);
 
113
  sws_scale(CONTEXT,srcData,srcStride,0,height,dstData,dstStride);
 
114
  return 1;
 
115
  
 
116
}
 
117
 
 
118
/**
 
119
    \fn  ADMColorspace
 
120
    \brief Constructor
 
121
  @param w width
 
122
  @param h height
 
123
  @param from colorspace to convert from
 
124
  @param to colorspace to concert to
 
125
*/
 
126
 
 
127
ADMColorspace::ADMColorspace(uint32_t w, uint32_t h, ADM_colorspace from,ADM_colorspace to)
 
128
{
 
129
  int flags=SWS_BICUBLIN;
 
130
  FLAGS();
 
131
  
 
132
    width=w;
 
133
    height=h;
 
134
    fromColor=from;
 
135
    toColor=to;
 
136
    PixelFormat lavFrom=ADMColor2LAVColor(fromColor);
 
137
    PixelFormat lavTo=ADMColor2LAVColor(toColor);
 
138
    
 
139
    context=(void *)sws_getContext(
 
140
                      width,height,
 
141
                      lavFrom ,
 
142
                      width,height,
 
143
                      lavTo,
 
144
                      flags, NULL, NULL,NULL);
 
145
 
 
146
}
 
147
/**
 
148
    \fn  ~ADMColorspace
 
149
    \brief Destructor
 
150
*/
 
151
ADMColorspace::~ADMColorspace()
 
152
{
 
153
  if(context)
 
154
  {
 
155
     sws_freeContext(CONTEXT);
 
156
     context=NULL;
 
157
  }
 
158
}
 
159
 
 
160
//EOF