summaryrefslogtreecommitdiffstats
path: root/mpeglib/lib/util/render/sdl/imageDeskSDL.cpp
blob: b1ff9a7c5e8323a4d3ccae46cc2b4eb15c2769d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
  SDL surface output
  Copyright (C) 2000  Martin Vogt

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU Library General Public License as published by
  the Free Software Foundation.

  For more information look at the file COPYRIGHT in this package

 */


#include "imageDeskSDL.h"

#ifdef SDL_WRAPPER


ImageDeskSDL::ImageDeskSDL() {

  this->surface=NULL;
  this->rect=NULL;
  imageMode=_IMAGE_NONE;
  lSupport=true;
  image=NULL;
}


ImageDeskSDL::~ImageDeskSDL() {
  closeImage();
  cout << "SDL destry needed"<<endl;
}



int ImageDeskSDL::support() {
  return lSupport;
}


void ImageDeskSDL::init(XWindow* xWindow, YUVPicture* pic) {
  cout << "ImageDeskSDL::init"<<endl;
  this->surface=(SDL_Surface*)xWindow;
  this->rect=(SDL_Rect*)pic;
}

int ImageDeskSDL::openImage(int imageMode) {
  int w=rect->w;
  int h=rect->h;
  this->imageMode=imageMode;
  /* Create a YV12 image (Y + V + U) */
  cout << "CreateYUVOverlay -s"<<imageMode<<" w:"<<w<<" h:"<<h<<endl;
  image = SDL_CreateYUVOverlay(w,h,
			       SDL_YV12_OVERLAY, 
			       surface);
  if (image == NULL) {
    cout << "error creating image"<<endl;
    exit(0);
  }
  cout << "CreateYUVOverlay -e"<<endl;
  return true;
}


int ImageDeskSDL::closeImage() {
  if (image != NULL) {
    cout << "FreeYUVOverlay -s"<<endl;
    SDL_FreeYUVOverlay(image);
    // otherwise test of NULL will fail
    image = NULL;
    cout << "FreeYUVOverlay -e"<<endl;
  }
  return true;
}



void ImageDeskSDL::ditherImage(YUVPicture* pic) {

  int w=pic->getWidth();
  int h=pic->getHeight();
  int size=w*h+(w*h)/2;
  SDL_LockYUVOverlay(image);
  memcpy(*((char**)image->pixels),pic->getLuminancePtr(),size);
  SDL_UnlockYUVOverlay(image);
 
}


void ImageDeskSDL::putImage(int w, int h) {
  SDL_Rect dest;
  dest.x=0;
  dest.y=0;
  dest.w=rect->w;
  dest.h=rect->h;
  if (imageMode & _IMAGE_RESIZE) {
    dest.w = w;
    dest.h = h;
  }

  if (imageMode & _IMAGE_DOUBLE) {
    dest.w*=2;
    dest.h*=2;
  }
  SDL_DisplayYUVOverlay(image,&dest);

}

#endif