Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

RenderingEngine.cpp

Go to the documentation of this file.
00001 #include "RenderingEngine.hpp"
00002 
00006 RenderingEngine::RenderingEngine(int x, int y,
00007                                  long yBO, long uBO, long vBO,
00008                                  long yS, long uvS, bool two, Layout l)
00009 {
00010 
00011     //  cout << "Initializing new RenderingEngine!!!" << nl;
00012 
00013 
00014     width = x;
00015     height = y;
00016     layout = l;
00017 
00018     ySize = yS;
00019     uvSize = uvS;
00020     bufOffsetY = yBO;
00021     bufOffsetU = uBO;
00022     bufOffsetV = vBO;
00023 
00024 
00025     if (two) {
00026         if (layout == UP_AND_DOWN)
00027             height *= 2;
00028         else
00029             width *= 2;
00030 
00031         ySize *= 2;
00032         uvSize *= 2;
00033         bufOffsetY *= 2;
00034         bufOffsetU *= 2;
00035         bufOffsetV *= 2;
00036     }
00037     // init video mode
00038     char buf[32];
00039 
00040 
00041     if (SDL_Init(SDL_INIT_VIDEO) < 0 || !SDL_VideoDriverName(buf, 1)) {
00042 #if DEBUG >= 1
00043         cerr << "Could not init SDL video: " << SDL_GetError() << nl;
00044 #endif
00045         exit(-1);               // use exception here l8er
00046     }
00047 
00048     video_info = SDL_GetVideoInfo();
00049 
00050     switch (video_info->vfmt->BitsPerPixel) {
00051     case 16:
00052     case 32:
00053         video_bpp = video_info->vfmt->BitsPerPixel;
00054         break;
00055     default:
00056         video_bpp = 16;
00057         break;
00058     }
00059 
00060 
00061     m_screen = SDL_SetVideoMode(width,
00062                                 height, 32, SDL_SWSURFACE | SDL_ASYNCBLIT);
00063 
00064 
00065 
00066     if (m_screen == NULL) {
00067         cerr << "Couldn't initialize window with dimension " << width <<
00068             "x" << height << "!\n";
00069         exit(1);                // use exception here l8er
00070     }
00071 
00072 
00073 
00074     SDL_WM_SetCaption("mk2l rulez ;-)", "");
00075 
00076     m_dstrect.x = 0;
00077     m_dstrect.y = 0;
00078     m_dstrect.w = m_screen->w;
00079     m_dstrect.h = m_screen->h;
00080 
00081 
00082     m_image =
00083         SDL_CreateYUVOverlay(width, height, SDL_YV12_OVERLAY, m_screen);
00084 
00085 
00086 
00087     //  cout << "Init OK!" << nl;
00088 
00089 }
00090 
00091 
00094 void
00095  RenderingEngine::show(char *buffer, int delay)
00096 {
00097 
00098     if (SDL_MUSTLOCK(m_screen)) {
00099         if (SDL_LockSurface(m_screen) < 0) {
00100             return;
00101         }
00102     }
00103 
00104     memcpy(m_image->pixels[0], buffer + bufOffsetY, ySize);
00105     memcpy(m_image->pixels[1], buffer + bufOffsetV, uvSize);
00106     memcpy(m_image->pixels[2], buffer + bufOffsetU, uvSize);
00107 
00108     SDL_DisplayYUVOverlay(m_image, &m_dstrect);
00109     SDL_UnlockYUVOverlay(m_image);
00110 
00111     SDL_Delay(delay);
00112 
00113     if (SDL_MUSTLOCK(m_screen)) {
00114         SDL_UnlockSurface(m_screen);
00115     }
00116     //  SDL_UpdateRect(m_screen, x, y, 1, 1);
00117 
00118 }
00119 
00120 
00123 void RenderingEngine::show(char *buffer1, char *buffer2, int delay)
00124 {
00125 
00126     if (SDL_MUSTLOCK(m_screen)) {
00127         if (SDL_LockSurface(m_screen) < 0) {
00128             return;
00129         }
00130     }
00131 
00132     if (layout == UP_AND_DOWN) {
00133         // interleave buffers and send the stuff to the grafix card
00134         memcpy(m_image->pixels[0], buffer2, ySize / 2);
00135         memcpy(m_image->pixels[0] + ySize / 2, buffer1, ySize / 2);
00136 
00137         memcpy(m_image->pixels[1], buffer2 + bufOffsetV / 2, uvSize / 2);
00138         memcpy(m_image->pixels[1] + uvSize / 2, buffer1 + bufOffsetV / 2,
00139                uvSize / 2);
00140 
00141         memcpy(m_image->pixels[2], buffer2 + bufOffsetU / 2, uvSize / 2);
00142         memcpy(m_image->pixels[2] + uvSize / 2, buffer1 + bufOffsetU / 2,
00143                uvSize / 2);
00144     }
00145 
00146     else {
00147         long i = 0;
00148         long j = 0;
00149         while (i < ySize / 2) {
00150             memcpy(m_image->pixels[0] + j, buffer2 + i, width / 2);
00151             memcpy(m_image->pixels[0] + width / 2 + j, buffer1 + i,
00152                    width / 2);
00153             i += width / 2;
00154             j += width;
00155         }
00156 
00157         i = 0;
00158         j = 0;
00159         while (i < uvSize / 2) {
00160             memcpy(m_image->pixels[1] + j, buffer2 + bufOffsetV / 2 + i,
00161                    width / 4);
00162             memcpy(m_image->pixels[1] + width / 4 + j,
00163                    buffer1 + bufOffsetV / 2 + i, width / 4);
00164 
00165             memcpy(m_image->pixels[2] + j, buffer2 + bufOffsetU / 2 + i,
00166                    width / 4);
00167             memcpy(m_image->pixels[2] + width / 4 + j,
00168                    buffer1 + bufOffsetU / 2 + i, width / 4);
00169 
00170             i += width / 4;
00171             j += width / 2;
00172         }
00173     }
00174 
00175     SDL_DisplayYUVOverlay(m_image, &m_dstrect);
00176     SDL_UnlockYUVOverlay(m_image);
00177 
00178     SDL_Delay(delay);
00179 
00180     if (SDL_MUSTLOCK(m_screen)) {
00181         SDL_UnlockSurface(m_screen);
00182     }
00183 }

Generated on Wed Mar 19 11:57:43 2003 for qctva4lv by doxygen1.2.17