Panda3D

inkblotVideoCursor.cxx

00001 // Filename: inkblotVideoCursor.cxx
00002 // Created by: jyelon (02Jul07)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "inkblotVideoCursor.h"
00016 #include "config_movies.h"
00017 
00018 TypeHandle InkblotVideoCursor::_type_handle;
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //
00022 // The Color-Map
00023 //
00024 ////////////////////////////////////////////////////////////////////
00025 struct color {
00026   int r,g,b;
00027 };
00028 
00029 static color colormap[17] = {
00030   { 255,0,0 },
00031   { 255,255,0 },
00032   { 0,255,0 },
00033   { 0,255,255 },
00034   { 0,0,255 },
00035   { 0,0,0 },
00036   { 255,0,0 },
00037   { 255,255,0 },
00038   { 0,255,0 },
00039   { 0,255,255 },
00040   { 0,0,255 },
00041   { 0,0,0 },
00042   { 255,0,0 },
00043   { 255,255,0 },
00044   { 0,255,0 },
00045   { 0,255,255 },
00046   { 0,0,255 },
00047 };  
00048 
00049 ////////////////////////////////////////////////////////////////////
00050 //     Function: InkblotVideoCursor::Constructor
00051 //       Access: Public
00052 //  Description: xxx
00053 ////////////////////////////////////////////////////////////////////
00054 InkblotVideoCursor::
00055 InkblotVideoCursor(InkblotVideo *src) :
00056   MovieVideoCursor(src)
00057 {
00058   _size_x = src->_specified_x;
00059   _size_y = src->_specified_y;
00060   _fps = src->_specified_fps;
00061   int padx = _size_x + 2;
00062   int pady = _size_y + 2;
00063   _cells = new unsigned char[padx * pady];
00064   _cells2 = new unsigned char[padx * pady];
00065   memset(_cells, 255, padx * pady);
00066   memset(_cells2, 255, padx * pady);
00067   _can_seek = true;
00068   _can_seek_fast = false;
00069   _frames_read = 0;
00070 }
00071 
00072 ////////////////////////////////////////////////////////////////////
00073 //     Function: InkblotVideoCursor::Destructor
00074 //       Access: Public, Virtual
00075 //  Description: 
00076 ////////////////////////////////////////////////////////////////////
00077 InkblotVideoCursor::
00078 ~InkblotVideoCursor() {
00079   delete[] _cells;
00080   delete[] _cells2;
00081 }
00082 
00083 ////////////////////////////////////////////////////////////////////
00084 //     Function: InkblotVideoCursor::fetch_into_buffer
00085 //       Access: Published, Virtual
00086 //  Description: See MovieVideoCursor::fetch_into_buffer.
00087 ////////////////////////////////////////////////////////////////////
00088 void InkblotVideoCursor::
00089 fetch_into_buffer(double time, unsigned char *data, bool bgra) {
00090 
00091   int padx = size_x() + 2;
00092   int pady = size_y() + 2;
00093   
00094   if (time < _next_start) {
00095     // Rewind to beginning.
00096     memset(_cells, 255, padx * pady);
00097     memset(_cells2, 255, padx * pady);
00098     _last_start = -1.0;
00099     _next_start = 0.0;
00100     _frames_read = 0;
00101   }
00102   
00103   nassertv(time >= _next_start);
00104   
00105   while (_next_start <= time) {
00106     _last_start = (_frames_read * 1.0) / _fps;
00107     _frames_read += 1;
00108     _next_start = (_frames_read * 1.0) / _fps;
00109     for (int y=1; y<pady-1; y++) {
00110       for (int x=1; x<padx-1; x++) {
00111         int tot =
00112           _cells[(x+1)+(y+1)*padx] +
00113           _cells[(x+1)+(y+0)*padx] +
00114           _cells[(x+1)+(y-1)*padx] +
00115           _cells[(x+0)+(y+1)*padx] +
00116           _cells[(x+0)+(y+0)*padx] +
00117           _cells[(x+0)+(y-1)*padx] +
00118           _cells[(x-1)+(y+1)*padx] +
00119           _cells[(x-1)+(y+0)*padx] +
00120           _cells[(x-1)+(y-1)*padx];
00121         _cells2[x + y*padx] = (tot/9)+3;
00122       }
00123     }
00124     unsigned char *t = _cells;
00125     _cells = _cells2;
00126     _cells2 = t;
00127   }
00128 
00129   for (int y=1; y<pady - 1; y++) {
00130     for (int x=1; x<padx - 1; x++) {
00131       int val = _cells[x + y*padx];
00132       color &c1 = colormap[(val>>4)+0];
00133       color &c2 = colormap[(val>>4)+1];
00134       int lerp = val & 15;
00135       data[0] = (c1.b * (16-lerp) + c2.b * lerp) / 16;
00136       data[1] = (c1.g * (16-lerp) + c2.g * lerp) / 16;
00137       data[2] = (c1.r * (16-lerp) + c2.r * lerp) / 16;
00138       if (bgra) {
00139         data[3] = 255;
00140         data += 4;
00141       } else {
00142         data += 3;
00143       }
00144     }
00145   }
00146 }
00147 
 All Classes Functions Variables Enumerations