Panda3D
 All Classes Functions Variables Enumerations
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   _num_components = 3;
00061   _fps = src->_specified_fps;
00062   int padx = _size_x + 2;
00063   int pady = _size_y + 2;
00064   _cells = new unsigned char[padx * pady];
00065   _cells2 = new unsigned char[padx * pady];
00066   memset(_cells, 255, padx * pady);
00067   memset(_cells2, 255, padx * pady);
00068   _can_seek = true;
00069   _can_seek_fast = false;
00070   _current_frame = 0;
00071   _last_frame = -1;
00072 }
00073 
00074 ////////////////////////////////////////////////////////////////////
00075 //     Function: InkblotVideoCursor::Destructor
00076 //       Access: Public, Virtual
00077 //  Description: 
00078 ////////////////////////////////////////////////////////////////////
00079 InkblotVideoCursor::
00080 ~InkblotVideoCursor() {
00081   delete[] _cells;
00082   delete[] _cells2;
00083 }
00084 
00085 ////////////////////////////////////////////////////////////////////
00086 //     Function: InkblotVideoCursor::set_time
00087 //       Access: Published, Virtual
00088 //  Description: See MovieVideoCursor::set_time().
00089 ////////////////////////////////////////////////////////////////////
00090 bool InkblotVideoCursor::
00091 set_time(double time, int loop_count) {
00092   int frame = (int)(time / _fps);
00093   if (frame == _current_frame) {
00094     return false;
00095   }
00096 
00097   _current_frame = frame;
00098   return true;
00099 }
00100 
00101 ////////////////////////////////////////////////////////////////////
00102 //     Function: InkblotVideoCursor::fetch_buffer
00103 //       Access: Published, Virtual
00104 //  Description: See MovieVideoCursor::fetch_buffer.
00105 ////////////////////////////////////////////////////////////////////
00106 PT(MovieVideoCursor::Buffer) InkblotVideoCursor::
00107 fetch_buffer() {
00108   PT(Buffer) buffer = get_standard_buffer();
00109 
00110   int padx = size_x() + 2;
00111   int pady = size_y() + 2;
00112   
00113   if (_current_frame < _last_frame) {
00114     // Rewind to beginning.
00115     memset(_cells, 255, padx * pady);
00116     memset(_cells2, 255, padx * pady);
00117     _last_frame = 0;
00118   }
00119   
00120   while (_last_frame <= _current_frame) {
00121     ++_last_frame;
00122     for (int y=1; y<pady-1; y++) {
00123       for (int x=1; x<padx-1; x++) {
00124         int tot =
00125           _cells[(x+1)+(y+1)*padx] +
00126           _cells[(x+1)+(y+0)*padx] +
00127           _cells[(x+1)+(y-1)*padx] +
00128           _cells[(x+0)+(y+1)*padx] +
00129           _cells[(x+0)+(y+0)*padx] +
00130           _cells[(x+0)+(y-1)*padx] +
00131           _cells[(x-1)+(y+1)*padx] +
00132           _cells[(x-1)+(y+0)*padx] +
00133           _cells[(x-1)+(y-1)*padx];
00134         _cells2[x + y*padx] = (tot/9)+3;
00135       }
00136     }
00137     unsigned char *t = _cells;
00138     _cells = _cells2;
00139     _cells2 = t;
00140   }
00141 
00142   unsigned char *data = buffer->_block;
00143   for (int y=1; y<pady - 1; y++) {
00144     for (int x=1; x<padx - 1; x++) {
00145       int val = _cells[x + y*padx];
00146       color &c1 = colormap[(val>>4)+0];
00147       color &c2 = colormap[(val>>4)+1];
00148       int lerp = val & 15;
00149       data[0] = (c1.b * (16-lerp) + c2.b * lerp) / 16;
00150       data[1] = (c1.g * (16-lerp) + c2.g * lerp) / 16;
00151       data[2] = (c1.r * (16-lerp) + c2.r * lerp) / 16;
00152       data += 3;
00153     }
00154   }
00155 
00156   return buffer;
00157 }
00158 
 All Classes Functions Variables Enumerations