~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/util/render/sdl/imageDeskSDL.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  SDL surface output
 
3
  Copyright (C) 2000  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
#include "imageDeskSDL.h"
 
15
 
 
16
#ifdef SDL_WRAPPER
 
17
 
 
18
 
 
19
ImageDeskSDL::ImageDeskSDL() {
 
20
 
 
21
  this->surface=NULL;
 
22
  this->rect=NULL;
 
23
  imageMode=_IMAGE_NONE;
 
24
  lSupport=true;
 
25
  image=NULL;
 
26
}
 
27
 
 
28
 
 
29
ImageDeskSDL::~ImageDeskSDL() {
 
30
  closeImage();
 
31
  cout << "SDL destry needed"<<endl;
 
32
}
 
33
 
 
34
 
 
35
 
 
36
int ImageDeskSDL::support() {
 
37
  return lSupport;
 
38
}
 
39
 
 
40
 
 
41
void ImageDeskSDL::init(XWindow* xWindow, YUVPicture* pic) {
 
42
  cout << "ImageDeskSDL::init"<<endl;
 
43
  this->surface=(SDL_Surface*)xWindow;
 
44
  this->rect=(SDL_Rect*)pic;
 
45
}
 
46
 
 
47
int ImageDeskSDL::openImage(int imageMode) {
 
48
  int w=rect->w;
 
49
  int h=rect->h;
 
50
  this->imageMode=imageMode;
 
51
  /* Create a YV12 image (Y + V + U) */
 
52
  cout << "CreateYUVOverlay -s"<<imageMode<<" w:"<<w<<" h:"<<h<<endl;
 
53
  image = SDL_CreateYUVOverlay(w,h,
 
54
                               SDL_YV12_OVERLAY, 
 
55
                               surface);
 
56
  if (image == NULL) {
 
57
    cout << "error creating image"<<endl;
 
58
    exit(0);
 
59
  }
 
60
  cout << "CreateYUVOverlay -e"<<endl;
 
61
  return true;
 
62
}
 
63
 
 
64
 
 
65
int ImageDeskSDL::closeImage() {
 
66
  if (image != NULL) {
 
67
    cout << "FreeYUVOverlay -s"<<endl;
 
68
    SDL_FreeYUVOverlay(image);
 
69
    // otherwise test of NULL will fail
 
70
    image = NULL;
 
71
    cout << "FreeYUVOverlay -e"<<endl;
 
72
  }
 
73
  return true;
 
74
}
 
75
 
 
76
 
 
77
 
 
78
void ImageDeskSDL::ditherImage(YUVPicture* pic) {
 
79
 
 
80
  int w=pic->getWidth();
 
81
  int h=pic->getHeight();
 
82
  int size=w*h+(w*h)/2;
 
83
  SDL_LockYUVOverlay(image);
 
84
  memcpy(*((char**)image->pixels),pic->getLuminancePtr(),size);
 
85
  SDL_UnlockYUVOverlay(image);
 
86
 
 
87
}
 
88
 
 
89
 
 
90
void ImageDeskSDL::putImage(int w, int h) {
 
91
  SDL_Rect dest;
 
92
  dest.x=0;
 
93
  dest.y=0;
 
94
  dest.w=rect->w;
 
95
  dest.h=rect->h;
 
96
  if (imageMode & _IMAGE_RESIZE) {
 
97
    dest.w = w;
 
98
    dest.h = h;
 
99
  }
 
100
 
 
101
  if (imageMode & _IMAGE_DOUBLE) {
 
102
    dest.w*=2;
 
103
    dest.h*=2;
 
104
  }
 
105
  SDL_DisplayYUVOverlay(image,&dest);
 
106
 
 
107
}
 
108
 
 
109
#endif
 
110