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