Panda3D
inkblotVideoCursor.cxx
1 // Filename: inkblotVideoCursor.cxx
2 // Created by: jyelon (02Jul07)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "inkblotVideoCursor.h"
16 #include "config_movies.h"
17 
18 TypeHandle InkblotVideoCursor::_type_handle;
19 
20 ////////////////////////////////////////////////////////////////////
21 //
22 // The Color-Map
23 //
24 ////////////////////////////////////////////////////////////////////
25 struct color {
26  int r,g,b;
27 };
28 
29 static color colormap[17] = {
30  { 255,0,0 },
31  { 255,255,0 },
32  { 0,255,0 },
33  { 0,255,255 },
34  { 0,0,255 },
35  { 0,0,0 },
36  { 255,0,0 },
37  { 255,255,0 },
38  { 0,255,0 },
39  { 0,255,255 },
40  { 0,0,255 },
41  { 0,0,0 },
42  { 255,0,0 },
43  { 255,255,0 },
44  { 0,255,0 },
45  { 0,255,255 },
46  { 0,0,255 },
47 };
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: InkblotVideoCursor::Constructor
51 // Access: Public
52 // Description: xxx
53 ////////////////////////////////////////////////////////////////////
56  MovieVideoCursor(src)
57 {
58  _size_x = src->_specified_x;
59  _size_y = src->_specified_y;
60  _num_components = 3;
61  _fps = src->_specified_fps;
62  int padx = _size_x + 2;
63  int pady = _size_y + 2;
64  _cells = new unsigned char[padx * pady];
65  _cells2 = new unsigned char[padx * pady];
66  memset(_cells, 255, padx * pady);
67  memset(_cells2, 255, padx * pady);
68  _can_seek = true;
69  _can_seek_fast = false;
70  _current_frame = 0;
71  _last_frame = -1;
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: InkblotVideoCursor::Destructor
76 // Access: Public, Virtual
77 // Description:
78 ////////////////////////////////////////////////////////////////////
79 InkblotVideoCursor::
80 ~InkblotVideoCursor() {
81  delete[] _cells;
82  delete[] _cells2;
83 }
84 
85 ////////////////////////////////////////////////////////////////////
86 // Function: InkblotVideoCursor::set_time
87 // Access: Published, Virtual
88 // Description: See MovieVideoCursor::set_time().
89 ////////////////////////////////////////////////////////////////////
91 set_time(double time, int loop_count) {
92  int frame = (int)(time / _fps);
93  if (frame == _current_frame) {
94  return false;
95  }
96 
97  _current_frame = frame;
98  return true;
99 }
100 
101 ////////////////////////////////////////////////////////////////////
102 // Function: InkblotVideoCursor::fetch_buffer
103 // Access: Published, Virtual
104 // Description: See MovieVideoCursor::fetch_buffer.
105 ////////////////////////////////////////////////////////////////////
106 PT(MovieVideoCursor::Buffer) InkblotVideoCursor::
107 fetch_buffer() {
108  PT(Buffer) buffer = get_standard_buffer();
109 
110  int padx = size_x() + 2;
111  int pady = size_y() + 2;
112 
113  if (_current_frame < _last_frame) {
114  // Rewind to beginning.
115  memset(_cells, 255, padx * pady);
116  memset(_cells2, 255, padx * pady);
117  _last_frame = 0;
118  }
119 
120  while (_last_frame <= _current_frame) {
121  ++_last_frame;
122  for (int y=1; y<pady-1; y++) {
123  for (int x=1; x<padx-1; x++) {
124  int tot =
125  _cells[(x+1)+(y+1)*padx] +
126  _cells[(x+1)+(y+0)*padx] +
127  _cells[(x+1)+(y-1)*padx] +
128  _cells[(x+0)+(y+1)*padx] +
129  _cells[(x+0)+(y+0)*padx] +
130  _cells[(x+0)+(y-1)*padx] +
131  _cells[(x-1)+(y+1)*padx] +
132  _cells[(x-1)+(y+0)*padx] +
133  _cells[(x-1)+(y-1)*padx];
134  _cells2[x + y*padx] = (tot/9)+3;
135  }
136  }
137  unsigned char *t = _cells;
138  _cells = _cells2;
139  _cells2 = t;
140  }
141 
142  unsigned char *data = buffer->_block;
143  for (int y=1; y<pady - 1; y++) {
144  for (int x=1; x<padx - 1; x++) {
145  int val = _cells[x + y*padx];
146  color &c1 = colormap[(val>>4)+0];
147  color &c2 = colormap[(val>>4)+1];
148  int lerp = val & 15;
149  data[0] = (c1.b * (16-lerp) + c2.b * lerp) / 16;
150  data[1] = (c1.g * (16-lerp) + c2.g * lerp) / 16;
151  data[2] = (c1.r * (16-lerp) + c2.r * lerp) / 16;
152  data += 3;
153  }
154  }
155 
156  return buffer;
157 }
158 
InkblotVideoCursor(InkblotVideo *src)
xxx
virtual bool set_time(double time, int loop_count)
See MovieVideoCursor::set_time().
A MovieVideo is actually any source that provides a sequence of video frames.
A cellular automaton that generates an amusing pattern of swirling colors.
Definition: inkblotVideo.h:27
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85