@@ -75,27 +75,28 @@ void MDEC::yuvToRgb(decodedBlock& output, int blockX, int blockY) {
75
75
void MDEC::decodeMacroblocks () {
76
76
for (auto src = input.begin (); src != input.end ();) {
77
77
auto block = decodeMacroblock (src);
78
+ if (!block) continue ;
78
79
79
- output.insert (output.end (), block.begin (), block.end ());
80
+ output.insert (output.end (), (* block) .begin (), (* block) .end ());
80
81
}
81
82
}
82
83
83
- decodedBlock MDEC::decodeMacroblock (std::vector<uint16_t >::iterator& src) {
84
- decodeBlock (crblk, src, colorQuantTable);
85
- decodeBlock (cbblk, src, colorQuantTable);
84
+ std::optional< decodedBlock> MDEC::decodeMacroblock (std::vector<uint16_t >::iterator& src) {
85
+ if (! decodeBlock (crblk, src, colorQuantTable)) return std::nullopt ;
86
+ if (! decodeBlock (cbblk, src, colorQuantTable)) return std::nullopt ;
86
87
87
- decodeBlock (yblk[0 ], src, luminanceQuantTable);
88
- decodeBlock (yblk[1 ], src, luminanceQuantTable);
89
- decodeBlock (yblk[2 ], src, luminanceQuantTable);
90
- decodeBlock (yblk[3 ], src, luminanceQuantTable);
88
+ if (! decodeBlock (yblk[0 ], src, luminanceQuantTable)) return std::nullopt ;
89
+ if (! decodeBlock (yblk[1 ], src, luminanceQuantTable)) return std::nullopt ;
90
+ if (! decodeBlock (yblk[2 ], src, luminanceQuantTable)) return std::nullopt ;
91
+ if (! decodeBlock (yblk[3 ], src, luminanceQuantTable)) return std::nullopt ;
91
92
92
93
decodedBlock out;
93
94
yuvToRgb (out, 0 , 0 );
94
95
yuvToRgb (out, 0 , 8 );
95
96
yuvToRgb (out, 8 , 0 );
96
97
yuvToRgb (out, 8 , 8 );
97
98
98
- return out;
99
+ return std::optional<decodedBlock>( out) ;
99
100
// Handle format conversion
100
101
}
101
102
@@ -119,7 +120,7 @@ union RLE {
119
120
RLE (uint16_t val) : _ (val){};
120
121
};
121
122
122
- void MDEC::decodeBlock (std::array<int16_t , 64 >& blk, std::vector<uint16_t >::iterator& src, const std::array<uint8_t , 64 >& table) {
123
+ bool MDEC::decodeBlock (std::array<int16_t , 64 >& blk, std::vector<uint16_t >::iterator& src, const std::array<uint8_t , 64 >& table) {
123
124
blk.fill (0 );
124
125
125
126
// Block structure:
@@ -132,7 +133,7 @@ void MDEC::decodeBlock(std::array<int16_t, 64>& blk, std::vector<uint16_t>::iter
132
133
src++; // Skip padding
133
134
}
134
135
135
- if (src == input.end ()) return ;
136
+ if (src == input.end ()) return false ;
136
137
DCT dct = *src++;
137
138
int32_t current = extend_sign<10 >(dct.dc );
138
139
@@ -151,7 +152,7 @@ void MDEC::decodeBlock(std::array<int16_t, 64>& blk, std::vector<uint16_t>::iter
151
152
blk.at (n) = value;
152
153
}
153
154
154
- if (src == input.end ()) break ;
155
+ if (src == input.end ()) return false ;
155
156
RLE rle = *src++;
156
157
current = extend_sign<10 >(rle.ac );
157
158
n += rle.zeroes + 1 ;
@@ -160,6 +161,7 @@ void MDEC::decodeBlock(std::array<int16_t, 64>& blk, std::vector<uint16_t>::iter
160
161
}
161
162
162
163
idct (blk);
164
+ return true ;
163
165
}
164
166
165
167
void MDEC::idct (std::array<int16_t , 64 >& src) {
0 commit comments