7
7
namespace cv
8
8
{
9
9
10
- const unsigned int RIFF_CC = CV_FOURCC(' R' ,' I' ,' F' ,' F' );
11
- const unsigned int LIST_CC = CV_FOURCC(' L' ,' I' ,' S' ,' T' );
12
- const unsigned int HDRL_CC = CV_FOURCC(' h' ,' d' ,' r' ,' l' );
13
- const unsigned int AVIH_CC = CV_FOURCC(' a' ,' v' ,' i' ,' h' );
14
- const unsigned int STRL_CC = CV_FOURCC(' s' ,' t' ,' r' ,' l' );
15
- const unsigned int STRH_CC = CV_FOURCC(' s' ,' t' ,' r' ,' h' );
16
- const unsigned int STRF_CC = CV_FOURCC(' s' ,' t' ,' r' ,' f' );
17
- const unsigned int VIDS_CC = CV_FOURCC(' v' ,' i' ,' d' ,' s' );
18
- const unsigned int MJPG_CC = CV_FOURCC(' M' ,' J' ,' P' ,' G' );
19
- const unsigned int MOVI_CC = CV_FOURCC(' m' ,' o' ,' v' ,' i' );
20
- const unsigned int IDX1_CC = CV_FOURCC(' i' ,' d' ,' x' ,' 1' );
21
- const unsigned int AVI_CC = CV_FOURCC(' A' ,' V' ,' I' ,' ' );
22
- const unsigned int AVIX_CC = CV_FOURCC(' A' ,' V' ,' I' ,' X' );
23
- const unsigned int JUNK_CC = CV_FOURCC(' J' ,' U' ,' N' ,' K' );
24
- const unsigned int INFO_CC = CV_FOURCC(' I' ,' N' ,' F' ,' O' );
25
- const unsigned int ODML_CC = CV_FOURCC(' o' ,' d' ,' m' ,' l' );
26
- const unsigned int DMLH_CC = CV_FOURCC(' d' ,' m' ,' l' ,' h' );
27
-
28
- String fourccToString (unsigned int fourcc);
29
-
30
- #ifndef DWORD
31
- typedef unsigned int DWORD;
32
- #endif
33
- #ifndef WORD
34
- typedef unsigned short int WORD;
35
- #endif
36
- #ifndef LONG
37
- typedef int LONG;
38
- #endif
10
+ const uint32_t RIFF_CC = CV_FOURCC(' R' ,' I' ,' F' ,' F' );
11
+ const uint32_t LIST_CC = CV_FOURCC(' L' ,' I' ,' S' ,' T' );
12
+ const uint32_t HDRL_CC = CV_FOURCC(' h' ,' d' ,' r' ,' l' );
13
+ const uint32_t AVIH_CC = CV_FOURCC(' a' ,' v' ,' i' ,' h' );
14
+ const uint32_t STRL_CC = CV_FOURCC(' s' ,' t' ,' r' ,' l' );
15
+ const uint32_t STRH_CC = CV_FOURCC(' s' ,' t' ,' r' ,' h' );
16
+ const uint32_t STRF_CC = CV_FOURCC(' s' ,' t' ,' r' ,' f' );
17
+ const uint32_t VIDS_CC = CV_FOURCC(' v' ,' i' ,' d' ,' s' );
18
+ const uint32_t MJPG_CC = CV_FOURCC(' M' ,' J' ,' P' ,' G' );
19
+ const uint32_t MOVI_CC = CV_FOURCC(' m' ,' o' ,' v' ,' i' );
20
+ const uint32_t IDX1_CC = CV_FOURCC(' i' ,' d' ,' x' ,' 1' );
21
+ const uint32_t AVI_CC = CV_FOURCC(' A' ,' V' ,' I' ,' ' );
22
+ const uint32_t AVIX_CC = CV_FOURCC(' A' ,' V' ,' I' ,' X' );
23
+ const uint32_t JUNK_CC = CV_FOURCC(' J' ,' U' ,' N' ,' K' );
24
+ const uint32_t INFO_CC = CV_FOURCC(' I' ,' N' ,' F' ,' O' );
25
+ const uint32_t ODML_CC = CV_FOURCC(' o' ,' d' ,' m' ,' l' );
26
+ const uint32_t DMLH_CC = CV_FOURCC(' d' ,' m' ,' l' ,' h' );
27
+
28
+ String fourccToString (uint32_t fourcc);
29
+
39
30
40
31
#pragma pack(push, 1)
41
32
struct AviMainHeader
42
33
{
43
- DWORD dwMicroSecPerFrame; // The period between video frames
44
- DWORD dwMaxBytesPerSec; // Maximum data rate of the file
45
- DWORD dwReserved1; // 0
46
- DWORD dwFlags; // 0x10 AVIF_HASINDEX: The AVI file has an idx1 chunk containing an index at the end of the file.
47
- DWORD dwTotalFrames; // Field of the main header specifies the total number of frames of data in file.
48
- DWORD dwInitialFrames; // Is used for interleaved files
49
- DWORD dwStreams; // Specifies the number of streams in the file.
50
- DWORD dwSuggestedBufferSize; // Field specifies the suggested buffer size forreading the file
51
- DWORD dwWidth; // Fields specify the width of the AVIfile in pixels.
52
- DWORD dwHeight; // Fields specify the height of the AVIfile in pixels.
53
- DWORD dwReserved[4 ]; // 0, 0, 0, 0
34
+ uint32_t dwMicroSecPerFrame; // The period between video frames
35
+ uint32_t dwMaxBytesPerSec; // Maximum data rate of the file
36
+ uint32_t dwReserved1; // 0
37
+ uint32_t dwFlags; // 0x10 AVIF_HASINDEX: The AVI file has an idx1 chunk containing an index at the end of the file.
38
+ uint32_t dwTotalFrames; // Field of the main header specifies the total number of frames of data in file.
39
+ uint32_t dwInitialFrames; // Is used for interleaved files
40
+ uint32_t dwStreams; // Specifies the number of streams in the file.
41
+ uint32_t dwSuggestedBufferSize; // Field specifies the suggested buffer size forreading the file
42
+ uint32_t dwWidth; // Fields specify the width of the AVIfile in pixels.
43
+ uint32_t dwHeight; // Fields specify the height of the AVIfile in pixels.
44
+ uint32_t dwReserved[4 ]; // 0, 0, 0, 0
54
45
};
55
46
56
47
struct AviStreamHeader
57
48
{
58
- unsigned int fccType; // 'vids', 'auds', 'txts'...
59
- unsigned int fccHandler; // "cvid", "DIB "
60
- DWORD dwFlags; // 0
61
- DWORD dwPriority; // 0
62
- DWORD dwInitialFrames; // 0
63
- DWORD dwScale; // 1
64
- DWORD dwRate; // Fps (dwRate - frame rate for video streams)
65
- DWORD dwStart; // 0
66
- DWORD dwLength; // Frames number (playing time of AVI file as defined by scale and rate)
67
- DWORD dwSuggestedBufferSize; // For reading the stream
68
- DWORD dwQuality; // -1 (encoding quality. If set to -1, drivers use the default quality value)
69
- DWORD dwSampleSize; // 0 means that each frame is in its own chunk
49
+ uint32_t fccType; // 'vids', 'auds', 'txts'...
50
+ uint32_t fccHandler; // "cvid", "DIB "
51
+ uint32_t dwFlags; // 0
52
+ uint32_t dwPriority; // 0
53
+ uint32_t dwInitialFrames; // 0
54
+ uint32_t dwScale; // 1
55
+ uint32_t dwRate; // Fps (dwRate - frame rate for video streams)
56
+ uint32_t dwStart; // 0
57
+ uint32_t dwLength; // Frames number (playing time of AVI file as defined by scale and rate)
58
+ uint32_t dwSuggestedBufferSize; // For reading the stream
59
+ uint32_t dwQuality; // -1 (encoding quality. If set to -1, drivers use the default quality value)
60
+ uint32_t dwSampleSize; // 0 means that each frame is in its own chunk
70
61
struct {
71
62
short int left;
72
63
short int top;
@@ -77,39 +68,39 @@ struct AviStreamHeader
77
68
78
69
struct AviIndex
79
70
{
80
- DWORD ckid;
81
- DWORD dwFlags;
82
- DWORD dwChunkOffset;
83
- DWORD dwChunkLength;
71
+ uint32_t ckid;
72
+ uint32_t dwFlags;
73
+ uint32_t dwChunkOffset;
74
+ uint32_t dwChunkLength;
84
75
};
85
76
86
77
struct BitmapInfoHeader
87
78
{
88
- DWORD biSize; // Write header size of BITMAPINFO header structure
89
- LONG biWidth; // width in pixels
90
- LONG biHeight; // height in pixels
91
- WORD biPlanes; // Number of color planes in which the data is stored
92
- WORD biBitCount; // Number of bits per pixel
93
- DWORD biCompression; // Type of compression used (uncompressed: NO_COMPRESSION=0)
94
- DWORD biSizeImage; // Image Buffer. Quicktime needs 3 bytes also for 8-bit png
79
+ uint32_t biSize; // Write header size of BITMAPINFO header structure
80
+ int32_t biWidth; // width in pixels
81
+ int32_t biHeight; // height in pixels
82
+ uint16_t biPlanes; // Number of color planes in which the data is stored
83
+ uint16_t biBitCount; // Number of bits per pixel
84
+ uint32_t biCompression; // Type of compression used (uncompressed: NO_COMPRESSION=0)
85
+ uint32_t biSizeImage; // Image Buffer. Quicktime needs 3 bytes also for 8-bit png
95
86
// (biCompression==NO_COMPRESSION)?0:xDim*yDim*bytesPerPixel;
96
- LONG biXPelsPerMeter; // Horizontal resolution in pixels per meter
97
- LONG biYPelsPerMeter; // Vertical resolution in pixels per meter
98
- DWORD biClrUsed; // 256 (color table size; for 8-bit only)
99
- DWORD biClrImportant; // Specifies that the first x colors of the color table. Are important to the DIB.
87
+ int32_t biXPelsPerMeter; // Horizontal resolution in pixels per meter
88
+ int32_t biYPelsPerMeter; // Vertical resolution in pixels per meter
89
+ uint32_t biClrUsed; // 256 (color table size; for 8-bit only)
90
+ uint32_t biClrImportant; // Specifies that the first x colors of the color table. Are important to the DIB.
100
91
};
101
92
102
93
struct RiffChunk
103
94
{
104
- unsigned int m_four_cc;
105
- unsigned int m_size;
95
+ uint32_t m_four_cc;
96
+ uint32_t m_size;
106
97
};
107
98
108
99
struct RiffList
109
100
{
110
- unsigned int m_riff_or_list_cc;
111
- unsigned int m_size;
112
- unsigned int m_list_type_cc;
101
+ uint32_t m_riff_or_list_cc;
102
+ uint32_t m_size;
103
+ uint32_t m_list_type_cc;
113
104
};
114
105
115
106
class VideoInputStream
@@ -118,9 +109,9 @@ class VideoInputStream
118
109
VideoInputStream ();
119
110
VideoInputStream (const String& filename);
120
111
~VideoInputStream ();
121
- VideoInputStream& read (char *, unsigned long long int );
122
- VideoInputStream& seekg (unsigned long long int );
123
- unsigned long long int tellg ();
112
+ VideoInputStream& read (char *, uint64_t );
113
+ VideoInputStream& seekg (uint64_t );
114
+ uint64_t tellg ();
124
115
bool isOpened () const ;
125
116
bool open (const String& filename);
126
117
void close ();
@@ -178,7 +169,7 @@ static const int AVIIF_KEYFRAME = 0x10;
178
169
static const int MAX_BYTES_PER_SEC = 99999999 ;
179
170
static const int SUG_BUFFER_SIZE = 1048576 ;
180
171
181
- String fourccToString (unsigned int fourcc)
172
+ String fourccToString (uint32_t fourcc)
182
173
{
183
174
return format (" %c%c%c%c" , fourcc & 255 , (fourcc >> 8 ) & 255 , (fourcc >> 16 ) & 255 , (fourcc >> 24 ) & 255 );
184
175
}
@@ -221,7 +212,7 @@ void VideoInputStream::close()
221
212
}
222
213
}
223
214
224
- VideoInputStream& VideoInputStream::read (char * buf, unsigned long long int count)
215
+ VideoInputStream& VideoInputStream::read (char * buf, uint64_t count)
225
216
{
226
217
if (isOpened ())
227
218
{
@@ -231,14 +222,14 @@ VideoInputStream& VideoInputStream::read(char* buf, unsigned long long int count
231
222
return *this ;
232
223
}
233
224
234
- VideoInputStream& VideoInputStream::seekg (unsigned long long int pos)
225
+ VideoInputStream& VideoInputStream::seekg (uint64_t pos)
235
226
{
236
- m_is_valid = (fseek (m_f, (long )pos, SEEK_SET) == 0 );
227
+ m_is_valid = (fseek (m_f, (int32_t )pos, SEEK_SET) == 0 );
237
228
238
229
return *this ;
239
230
}
240
231
241
- unsigned long long int VideoInputStream::tellg ()
232
+ uint64_t VideoInputStream::tellg ()
242
233
{
243
234
return ftell (m_f);
244
235
}
@@ -283,9 +274,9 @@ void AVIReadContainer::close()
283
274
m_file_stream->close ();
284
275
}
285
276
286
- bool AVIReadContainer::parseIndex (unsigned int index_size, frame_list& in_frame_list)
277
+ bool AVIReadContainer::parseIndex (uint32_t index_size, frame_list& in_frame_list)
287
278
{
288
- unsigned long long int index_end = m_file_stream->tellg ();
279
+ uint64_t index_end = m_file_stream->tellg ();
289
280
index_end += index_size;
290
281
bool result = false ;
291
282
@@ -296,7 +287,7 @@ bool AVIReadContainer::parseIndex(unsigned int index_size, frame_list& in_frame_
296
287
297
288
if (idx1.ckid == m_stream_id)
298
289
{
299
- unsigned long long int absolute_pos = m_movi_start + idx1.dwChunkOffset ;
290
+ uint64_t absolute_pos = m_movi_start + idx1.dwChunkOffset ;
300
291
301
292
if (absolute_pos < m_movi_end)
302
293
{
@@ -322,7 +313,7 @@ bool AVIReadContainer::parseStrl(char stream_id, Codecs codec_)
322
313
323
314
if (m_file_stream && strh.m_four_cc == STRH_CC)
324
315
{
325
- unsigned long long int next_strl_list = m_file_stream->tellg ();
316
+ uint64_t next_strl_list = m_file_stream->tellg ();
326
317
next_strl_list += strh.m_size ;
327
318
328
319
AviStreamHeader strm_hdr;
@@ -332,8 +323,8 @@ bool AVIReadContainer::parseStrl(char stream_id, Codecs codec_)
332
323
{
333
324
if (strm_hdr.fccType == VIDS_CC && strm_hdr.fccHandler == MJPG_CC)
334
325
{
335
- char first_digit = (stream_id/10 ) + ' 0' ;
336
- char second_digit = (stream_id%10 ) + ' 0' ;
326
+ uint8_t first_digit = (stream_id/10 ) + ' 0' ;
327
+ uint8_t second_digit = (stream_id%10 ) + ' 0' ;
337
328
338
329
if (m_stream_id == 0 )
339
330
{
@@ -382,7 +373,7 @@ bool AVIReadContainer::parseHdrlList(Codecs codec_)
382
373
383
374
if (m_file_stream && avih.m_four_cc == AVIH_CC)
384
375
{
385
- unsigned long long int next_strl_list = m_file_stream->tellg ();
376
+ uint64_t next_strl_list = m_file_stream->tellg ();
386
377
next_strl_list += avih.m_size ;
387
378
388
379
AviMainHeader avi_hdr;
@@ -391,13 +382,13 @@ bool AVIReadContainer::parseHdrlList(Codecs codec_)
391
382
if (m_file_stream)
392
383
{
393
384
m_is_indx_present = ((avi_hdr.dwFlags & 0x10 ) != 0 );
394
- DWORD number_of_streams = avi_hdr.dwStreams ;
385
+ uint32_t number_of_streams = avi_hdr.dwStreams ;
395
386
CV_Assert (number_of_streams < 0xFF );
396
387
m_width = avi_hdr.dwWidth ;
397
388
m_height = avi_hdr.dwHeight ;
398
389
399
390
// the number of strl lists must be equal to number of streams specified in main avi header
400
- for (DWORD i = 0 ; i < number_of_streams; ++i)
391
+ for (uint32_t i = 0 ; i < number_of_streams; ++i)
401
392
{
402
393
m_file_stream->seekg (next_strl_list);
403
394
RiffList strl_list;
@@ -433,7 +424,7 @@ bool AVIReadContainer::parseAviWithFrameList(frame_list& in_frame_list, Codecs c
433
424
434
425
if ( m_file_stream && hdrl_list.m_riff_or_list_cc == LIST_CC && hdrl_list.m_list_type_cc == HDRL_CC )
435
426
{
436
- unsigned long long int next_list = m_file_stream->tellg ();
427
+ uint64_t next_list = m_file_stream->tellg ();
437
428
// RiffList::m_size includes fourCC field which we have already read
438
429
next_list += (hdrl_list.m_size - 4 );
439
430
// parseHdrlList sets m_is_indx_present flag which would be used later
@@ -472,7 +463,7 @@ bool AVIReadContainer::parseAviWithFrameList(frame_list& in_frame_list, Codecs c
472
463
if (m_is_indx_present)
473
464
{
474
465
// we are expecting to find index section after movi list
475
- unsigned int indx_pos = (unsigned int )m_movi_start + 4 ;
466
+ uint32_t indx_pos = (uint32_t )m_movi_start + 4 ;
476
467
indx_pos += (some_list.m_size - 4 );
477
468
m_file_stream->seekg (indx_pos);
478
469
@@ -520,6 +511,7 @@ std::vector<char> AVIReadContainer::readFrame(frame_iterator it)
520
511
521
512
RiffChunk chunk;
522
513
*(m_file_stream) >> chunk;
514
+ CV_Assert (chunk.m_size <= 0xFFFF );
523
515
524
516
std::vector<char > result;
525
517
@@ -543,7 +535,7 @@ bool AVIReadContainer::parseRiff(frame_list &m_mjpeg_frames_)
543
535
if ( *m_file_stream && riff_list.m_riff_or_list_cc == RIFF_CC &&
544
536
((riff_list.m_list_type_cc == AVI_CC) | (riff_list.m_list_type_cc == AVIX_CC)) )
545
537
{
546
- unsigned long long int next_riff = m_file_stream->tellg ();
538
+ uint64_t next_riff = m_file_stream->tellg ();
547
539
// RiffList::m_size includes fourCC field which we have already read
548
540
next_riff += (riff_list.m_size - 4 );
549
541
@@ -559,7 +551,7 @@ bool AVIReadContainer::parseRiff(frame_list &m_mjpeg_frames_)
559
551
return result;
560
552
}
561
553
562
- void AVIReadContainer::printError (RiffList &list, unsigned int expected_fourcc)
554
+ void AVIReadContainer::printError (RiffList &list, uint32_t expected_fourcc)
563
555
{
564
556
if (!m_file_stream)
565
557
{
@@ -575,7 +567,7 @@ void AVIReadContainer::printError(RiffList &list, unsigned int expected_fourcc)
575
567
}
576
568
}
577
569
578
- void AVIReadContainer::printError (RiffChunk &chunk, unsigned int expected_fourcc)
570
+ void AVIReadContainer::printError (RiffChunk &chunk, uint32_t expected_fourcc)
579
571
{
580
572
if (!m_file_stream)
581
573
{
@@ -742,6 +734,7 @@ void BitStream::patchInt(int val, size_t pos)
742
734
}
743
735
else
744
736
{
737
+ CV_Assert (pos < (1u <<31 ));
745
738
long fpos = ftell (m_f);
746
739
fseek (m_f, (long )pos, SEEK_SET);
747
740
uchar buf[] = { (uchar)val, (uchar)(val >> 8 ), (uchar)(val >> 16 ), (uchar)(val >> 24 ) };
0 commit comments