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

« back to all changes in this revision

Viewing changes to avidemux/ADM_gui2/GUI_sdlDraw.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
 
// C++ Implementation: GUI_sdlDraw
3
 
//
4
 
// Description: 
5
 
//
6
 
//  YUY2 does not work on win32, U&V seems to be zeroed
7
 
//
8
 
//  The pitch stride has to be changed as there could be some padding depending on the OS
9
 
//
10
 
//
11
 
// Author: mean <fixounet@free.fr>, (C) 2004
12
 
//
13
 
// Copyright: See COPYING file that comes with this distribution
14
 
//
15
 
//
16
 
#include "config.h"
17
 
#if defined(USE_SDL)
18
 
 
19
 
#include <stdio.h>         
20
 
#include <stdlib.h>
21
 
#include <math.h>
22
 
#include <string.h>
23
 
 
24
 
#include "ADM_library/default.h"
25
 
#ifndef CYG_MANGLING
26
 
#include <X11/Xlib.h>
27
 
#include <X11/Xutil.h>
28
 
 
29
 
 
30
 
#include <gtk/gtk.h>
31
 
#include <gdk/gdk.h>
32
 
#include <gdk/gdkx.h>
33
 
#include "ADM_toolkit/toolkit_gtk.h"
34
 
#else
35
 
#define GtkWidget void
36
 
#endif
37
 
 
38
 
#include <time.h>
39
 
#include <sys/time.h>
40
 
#include <ADM_assert.h>
41
 
#include "ADM_colorspace/ADM_rgb.h"
42
 
#include "ADM_gui2/GUI_render.h"
43
 
 
44
 
#include "ADM_gui2/GUI_accelRender.h"
45
 
#include "ADM_gui2/GUI_sdlDraw.h"
46
 
 
47
 
 
48
 
extern "C" {
49
 
#include "SDL/SDL.h"
50
 
#include "SDL/SDL_syswm.h"
51
 
 
52
 
 
53
 
}
54
 
static uint8_t sdl_running=0;
55
 
static SDL_Overlay *sdl_overlay=NULL;
56
 
static SDL_Surface *sdl_display=NULL;
57
 
static SDL_Rect disp;
58
 
 
59
 
static ColBase *color=NULL;
60
 
 
61
 
sdlAccelRender::sdlAccelRender( void)
62
 
{
63
 
        useYV12=1;
64
 
        decoded=NULL;
65
 
}
66
 
uint8_t sdlAccelRender::end( void)
67
 
{
68
 
        if(sdl_overlay)
69
 
        {
70
 
                SDL_FreeYUVOverlay(sdl_overlay);
71
 
        }
72
 
        if(sdl_display)
73
 
        {
74
 
        SDL_UnlockSurface(sdl_display);
75
 
                SDL_FreeSurface(sdl_display);
76
 
        }
77
 
        if(sdl_running)
78
 
        {
79
 
                SDL_QuitSubSystem(SDL_INIT_VIDEO);
80
 
        }
81
 
        if(decoded)
82
 
        {
83
 
        delete [] decoded;
84
 
        decoded=NULL;   
85
 
        }
86
 
        sdl_running=0;
87
 
        sdl_overlay=NULL;
88
 
        sdl_display=NULL;
89
 
        printf("SDL killed\n");
90
 
        
91
 
        
92
 
}
93
 
uint8_t sdlAccelRender::init( GtkWidget * window, uint32_t w, uint32_t h)
94
 
{
95
 
int bpp;
96
 
int flags;
97
 
 
98
 
        // Ask for the position of the drawing window at start
99
 
        //_______________________________________________________
100
 
        
101
 
        disp.w=w;
102
 
        disp.h=h;
103
 
        disp.x=0;
104
 
        disp.y=0;
105
 
 
106
 
        if(!useYV12)
107
 
        {
108
 
            color=new ColBase(720,480);
109
 
            decoded=new uint8_t[w*h*2];
110
 
    }
111
 
        /* Hack to get SDL to use GTK window, ugly but works */
112
 
#if !defined(CONFIG_DARWIN) && !defined(CYG_MANGLING)
113
 
        { char SDL_windowhack[32];
114
 
                sprintf(SDL_windowhack,"SDL_WINDOWID=%ld",
115
 
                        GDK_WINDOW_XWINDOW(window->window));
116
 
                putenv(SDL_windowhack);
117
 
        }
118
 
#endif
119
 
        if (  SDL_InitSubSystem(SDL_INIT_VIDEO) < 0 ) 
120
 
         {
121
 
                fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
122
 
                return 0;
123
 
          }
124
 
        sdl_running=1;
125
 
        flags = SDL_ANYFORMAT | SDL_HWPALETTE | SDL_HWSURFACE | SDL_NOFRAME;
126
 
        bpp= SDL_VideoModeOK( w, h,  16, flags );
127
 
        sdl_display= SDL_SetVideoMode( w, h,  bpp, flags );     
128
 
        if(!sdl_display)
129
 
        {
130
 
                end();
131
 
                printf("Cannot create get surface\n");
132
 
                return 0;
133
 
        
134
 
        }
135
 
        SDL_LockSurface(sdl_display);
136
 
        int cspace;
137
 
        
138
 
        if(useYV12) cspace=SDL_YV12_OVERLAY;
139
 
            else    cspace=SDL_YUY2_OVERLAY;
140
 
        //_______________________________________________________
141
 
        sdl_overlay=SDL_CreateYUVOverlay((w),(h),
142
 
        cspace,         
143
 
                sdl_display);
144
 
        if(!sdl_overlay)
145
 
        {
146
 
                end();
147
 
                printf("Cannot create SDL overlay\n");
148
 
                return 0;
149
 
        }
150
 
        
151
 
        int pitch=sdl_overlay->pitches[0];
152
 
        printf("SDL_init ok, type is : %d,planes :%d pitch:%d\n",sdl_overlay->hw_overlay,sdl_overlay->planes,pitch);
153
 
        if(!sdl_overlay->hw_overlay)
154
 
        {
155
 
                printf("** HW Acceleration disabled **\n");
156
 
        #ifdef CONFIG_DARWIN
157
 
                printf("** Darwin**\n");
158
 
        #endif
159
 
        }
160
 
        if(!useYV12) color->reset(w,h);
161
 
        return 1;
162
 
}
163
 
static void interleave(uint8_t *dst,uint8_t *src,int width, int stride, int lines)
164
 
{
165
 
    for(int y=0;y<lines;y++)
166
 
    {
167
 
        memcpy(dst,src,width);
168
 
        src+=width;
169
 
        dst+=stride;          
170
 
    }   
171
 
}
172
 
uint8_t sdlAccelRender::display(uint8_t *ptr, uint32_t w, uint32_t h)
173
 
{
174
 
int pitch;
175
 
int page=w*h;
176
 
        ADM_assert(sdl_overlay);
177
 
        SDL_LockYUVOverlay(sdl_overlay);        
178
 
        pitch=sdl_overlay->pitches[0];
179
 
//      printf("SDL: new pitch :%d\n",pitch);
180
 
        if(useYV12)
181
 
        {
182
 
        if(pitch==w)
183
 
            memcpy(sdl_overlay->pixels[0],ptr,w*h);
184
 
        else
185
 
            interleave(sdl_overlay->pixels[0],ptr,w,pitch,h);
186
 
            
187
 
        pitch=sdl_overlay->pitches[1];
188
 
        if(pitch==(w>>1))
189
 
            memcpy(sdl_overlay->pixels[1],ptr+page,(w*h)>>2);
190
 
        else
191
 
            interleave(sdl_overlay->pixels[1],ptr+page,w>>1,pitch,h>>1);
192
 
       
193
 
        pitch=sdl_overlay->pitches[2];
194
 
        if(pitch==(w>>1))
195
 
            memcpy(sdl_overlay->pixels[2],ptr+(page*5)/4,(w*h)>>2);
196
 
        else
197
 
            interleave(sdl_overlay->pixels[2],ptr+(page*5)/4,w>>1,pitch,h>>1);          
198
 
        }else
199
 
        {
200
 
        color->reset(w,h);
201
 
        if(pitch==2*w)
202
 
        {
203
 
            color->scale(ptr,sdl_overlay->pixels[0]);
204
 
        }
205
 
        else
206
 
        {
207
 
            color->scale(ptr,decoded);
208
 
            interleave(sdl_overlay->pixels[0],decoded,2*w,pitch,h);
209
 
        }
210
 
    }   
211
 
        
212
 
        disp.w=w;
213
 
        disp.h=h;
214
 
        disp.x=0;
215
 
        disp.y=0;
216
 
        
217
 
        SDL_UnlockYUVOverlay(sdl_overlay);
218
 
        SDL_DisplayYUVOverlay(sdl_overlay,&disp);
219
 
        
220
 
        //printf("*\n");
221
 
        return 1;
222
 
}
223
 
 
224
 
#endif