}
bool Image::DuplicateBlueNoiseOffsetExists() const {
- for (unsigned int i = 1; i < blue_noise_offsets_.size(); ++i) {
- if (blue_noise_offsets_.at(i - 1) == blue_noise_offsets_.at(i)) {
- return true;
+ for (unsigned int i = 0; i < blue_noise_offsets_.size(); ++i) {
+ for (unsigned int j = i + 1; j < blue_noise_offsets_.size(); ++j) {
+ if (blue_noise_offsets_.at(i) == blue_noise_offsets_.at(j)) {
+ return true;
+ }
}
}
- if (blue_noise_offsets_.size() > 1 &&
- blue_noise_offsets_.at(0) ==
- blue_noise_offsets_.at(blue_noise_offsets_.size() - 1)) {
- return true;
- }
return false;
}
// read frames
while (av_read_frame(avf_context, pkt) >= 0) {
if (pkt->stream_index == video_stream_idx) {
- if (!HandleDecodingPacket(codec_ctx, pkt, frame, blue_noise, grayscale)) {
+ if (!HandleDecodingPacket(codec_ctx, pkt, frame, blue_noise, grayscale,
+ overwrite)) {
return false;
}
}
}
// flush decoders
- if (!HandleDecodingPacket(codec_ctx, nullptr, frame, blue_noise, grayscale)) {
+ if (!HandleDecodingPacket(codec_ctx, nullptr, frame, blue_noise, grayscale,
+ overwrite)) {
return false;
}
bool Video::HandleDecodingPacket(AVCodecContext *codec_ctx, AVPacket *pkt,
AVFrame *frame, Image *blue_noise,
- bool grayscale) {
+ bool grayscale, bool overwrite) {
int return_value = avcodec_send_packet(codec_ctx, pkt);
if (return_value < 0) {
std::cout << "ERROR: Failed to decode packet (" << packet_count_ << ')'
out_name += std::to_string(frame_count_);
}
out_name += ".png";
- dithered_image->SaveAsPNG(out_name, false);
+ if (!dithered_image->SaveAsPNG(out_name, overwrite)) {
+ return false;
+ }
// TODO encode video with dithered_image
// cleanup
unsigned int packet_count_;
bool HandleDecodingPacket(AVCodecContext *codec_ctx, AVPacket *pkt,
- AVFrame *frame, Image *blue_noise, bool grayscale);
+ AVFrame *frame, Image *blue_noise, bool grayscale,
+ bool overwrite);
};
#endif