Add facility to read frames in RGB & RGBA format
[imageviewer.git] / sequenceReader.h
blobac0002d9f60b359e428b99f18e74bf98dd6b0a40
1 /* ***** BEGIN LICENSE BLOCK *****
3 * $Id$
5 * The MIT License
7 * Copyright (c) 2008 BBC Research
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
27 * ***** END LICENSE BLOCK ***** */
29 #ifndef __SEQUENCEREADER_H
30 #define __SEQUENCEREADER_H
32 #include "rawFrame.h"
33 #include "rawFrameIO.h"
35 #include <vector>
37 #include <QStringList>
38 #include <QObject>
40 #include <QtGui>
42 class SequenceReader : public QObject
44 Q_OBJECT
45 public:
46 SequenceReader();
48 //Values of this type are stored in the settings, so if you need to extend this enum please only add to the end,
49 //or settings and program values may get out of step.
50 typedef enum _RawType {type_v216,
51 type_v210,
52 type_yv12,
53 type_i420,
54 type_uyvy,
55 type_pgm,
56 type_ppm,
57 type_uy16,
58 type_yy16,
59 type_yyy8,
60 type_16P4,
61 type_16P2,
62 type_16P0,
63 type_8P2,
64 type_sgi,
65 type_leader_frm,
66 type_unknown,
67 type_auto,
68 type_rgb,
69 type_rgba} RawType;
71 enum ImageSizes {SizeQSIF=0, SizeQCIF, SizeSIF, SizeCIF, Size4SIF, Size4CIF, SizeSD480, SizeSD576, SizeHD720, SizeHD1080, Size2K, Size4K, SizeSHV, SizeCustom, SizeUnknown, NumSizes=SizeUnknown};
73 int getSequenceLength(void);
74 int getFirstFrameNum(void);
75 int getLastFrameNum(void);
76 int getCurrentFrameNum(void);
78 int getFrameWidth(void) {return frameWidth;}
79 int getFrameHeight(void) {return frameHeight;}
80 int getFrameDepth(void) {return frameDepth;}
81 bool getFrameHasHeader(void);
83 int getCustomWidth();
84 int getCustomHeight();
85 RawFrame& readFrame(int frameNum);
87 signals:
88 void newFrame(const RawFrame*);
89 void frameFileName(const QString &);
90 void frameFormat(const QString &);
91 void frameSize(QSize &);
92 void sequencePosition(const QString&, int, int, int, int);
93 void frameHasHeader(bool);
94 void frameBitDepth(int);
96 public slots:
97 int setDirectoryOfFiles(const QString &dir);
98 int setFileNames(const QStringList &);
99 void setSizeType(ImageSizes s);
100 void setCustomSize(int width, int height);
101 void setRawFormat(RawType);
102 void nextInSequence();
103 void prevInSequence();
105 private slots:
107 private:
109 int jumpInSequence(int);
111 typedef struct { //information about each file in the sequence
112 RawFrame::Chroma chroma;
113 RawType rawType;
114 int bitDepth;
115 bool hasHeader;
116 int bytesPerFrame;
117 int framesInFile;
118 int firstFrameNum;
119 int lastFrameNum;
120 } sequenceFileInfo;
122 int rawImageWidth[NumSizes];
123 int rawImageHeight[NumSizes];
125 void buildFileInfo(void); //look through the file list and gather information on each video file
126 int bytesPerFrame(RawType); //turn a file extension into a number of bytes per frame for the current picture size
127 bool hasHeader(RawType); //does the file have a header which allows file information to be read?
128 int bitDepth(RawType); //can the pixel bit depth be determined for a file from the file extension?
129 RawFrame::Chroma chromaType(RawType); //chroma type we read into, determined by file extension
130 RawType rawType(QString &extension); //enumerated version of file extension
132 int fileIndexForFrameNum(int frameNum); //look through the file info list for the file containing a particular frame number
134 RawType frameType; //the user interface may force the raw yuv file type regardless of the extension
135 int frameDepth; //the bit depth for the frame if is is known / deduced, or 0 otherwise
136 int frameWidth; //the actual frame dimensions, either read from the header or taken from rawWidth/rawHeight
137 int frameHeight;
139 int rawWidth; //dimensions for raw files, where the frame size is unknown
140 int rawHeight;
142 int firstFrame; //first frame number in the sequence
143 int lastFrame; //last frame number in the sequence
144 int currentFrameNum; //current
145 int currentFileIndex; //current file in the list of files to display (each may contain more than one frame)
146 FILE *filePtr; //the currently open file
147 QStringList fileList; //list of filenames
148 std::vector<sequenceFileInfo> infoList; //list of info about each file of frames
149 RawFrame *destFrame; //the destination frame for reading into
152 #endif