1 /******************************************************************************* 2 * animation.h 3 * 4 * --------------------------------------------------------------------------- 5 * Persistence of Vision Ray Tracer ('POV-Ray') version 3.7. 6 * Copyright 1991-2013 Persistence of Vision Raytracer Pty. Ltd. 7 * 8 * POV-Ray is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Affero General Public License as 10 * published by the Free Software Foundation, either version 3 of the 11 * License, or (at your option) any later version. 12 * 13 * POV-Ray is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU Affero General Public License for more details. 17 * 18 * You should have received a copy of the GNU Affero General Public License 19 * along with this program. If not, see <http://www.gnu.org/licenses/>. 20 * --------------------------------------------------------------------------- 21 * POV-Ray is based on the popular DKB raytracer version 2.12. 22 * DKBTrace was originally written by David K. Buck. 23 * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins. 24 * --------------------------------------------------------------------------- 25 * $File: //depot/public/povray/3.x/source/base/animation/animation.h $ 26 * $Revision: #1 $ 27 * $Change: 6069 $ 28 * $DateTime: 2013/11/06 11:59:40 $ 29 * $Author: chrisc $ 30 *******************************************************************************/ 31 32 #ifndef POVRAY_BASE_ANIMATION_H 33 #define POVRAY_BASE_ANIMATION_H 34 35 #include <vector> 36 37 #include "base/configbase.h" 38 #include "base/fileinputoutput.h" 39 #include "base/pov_err.h" 40 #include "base/types.h" 41 #include "base/image/image.h" 42 43 namespace pov_base 44 { 45 46 class Animation 47 { 48 public: 49 enum CodecType 50 { 51 LosslessCodec = 0, // file format default choice 52 LossyCodec = 1, // file format default choice 53 PNGCodec, 54 BMPCodec, 55 JPEGCodec, 56 MPEG1Codec, // i-frames only - note that JPEG library DCT can be reused [trf] 57 MPEG2Codec // i-frames only - note that JPEG library DCT can be reused [trf] 58 }; 59 60 enum FileType 61 { 62 AVI, 63 MOV, 64 MPEG 65 }; 66 67 enum ColorEncodingType 68 { 69 RGB, 70 YUV, 71 YUV422, 72 YUV420, 73 YUV411, 74 YUV410 75 }; 76 77 struct ReadOptions 78 { 79 float gamma; 80 bool gammacorrect; 81 ReadOptionsReadOptions82 ReadOptions() : gamma(1.0f), gammacorrect(false) { } 83 }; 84 85 struct WriteOptions 86 { 87 ColorEncodingType colorencoding; 88 unsigned char compress; // relative quality from 100 best to 0 worst 89 unsigned char bpcc; // bits per colour component 90 bool alphachannel; 91 float gamma; 92 float blurradius; // blur radius 0.0 to 1.0 (for better lossy compression without aa) - turned off by 0.0 93 float bluredgethreshold; // edge threshold 0.0 to 1.0 (grayscale difference of clipped pixels, only blur if difference larger than threshold) - turned off by 1.0 94 float framespersecond; // has to support very odd framerates i.e. for NTSC - defaults to standard 24 fps cinema/movie frame rate 95 WriteOptionsWriteOptions96 WriteOptions() : colorencoding(YUV), compress(75), alphachannel(false), gamma(1.0f), blurradius(0.0), bluredgethreshold(1.0), framespersecond(24.0) { } 97 }; 98 99 virtual ~Animation(); 100 101 static Animation *Open(FileType aftype, IStream *file, const ReadOptions& options = ReadOptions()); // reading only 102 static Animation *Open(FileType aftype, CodecType codec, OStream *file, unsigned int w, unsigned int h, const WriteOptions& options = WriteOptions()); // writing only 103 104 void AppendFrame(Image *image); // writing only - NOTE: This method reserves the right to *modify* the image passed to it!!! [trf] 105 106 Image *ReadNextFrame(); // reading only 107 108 float GetLengthInSeconds() const; 109 unsigned int GetLengthInFrames() const; 110 111 unsigned int GetCurrentFrame() const; // reading only 112 void SetCurrentFrame(unsigned int frame); // reading only 113 GetWidth()114 unsigned int GetWidth() const { return width; } GetHeight()115 unsigned int GetHeight() const { return height; } 116 117 const vector<string>& GetWarnings() const; 118 void ClearWarnings(); 119 protected: 120 FileType fileType; 121 IStream *inFile; 122 OStream *outFile; 123 unsigned int width; 124 unsigned int height; 125 ReadOptions readOptions; 126 WriteOptions writeOptions; 127 vector<string> warnings; 128 CodecType codec; 129 unsigned int currentFrame; 130 unsigned int totalFrames; 131 float frameDuration; 132 133 Animation(FileType aftype, IStream *file, const ReadOptions& options); 134 Animation(FileType aftype, CodecType codec, OStream *file, unsigned int w, unsigned int h, const WriteOptions& options); 135 136 Image *ReadFrame(IStream *file); 137 POV_LONG WriteFrame(OStream *file, const Image *image); 138 139 void ComputeBlurMask(const Image& image, Image& mask); 140 void GetBlurredPixel(const Image& image, unsigned int x, unsigned int y, float& red, float& green, float& blue); 141 private: 142 void *state; 143 float blurMatrix[16][16]; // only uses 15 x 15 maximum (16 x 16 for better alignment) 144 int blurMatrixRadius; 145 146 /// not available 147 Animation(); 148 /// not available 149 Animation(const Animation&); 150 /// not available 151 Animation& operator=(Animation&); 152 }; 153 154 } 155 156 #endif // POVRAY_BASE_ANIMATION_H 157