Minor fixes
This commit is contained in:
parent
cd9c363a48
commit
8191a51d9b
3 changed files with 15 additions and 13 deletions
|
@ -1423,15 +1423,12 @@ void Image::GenerateBlueNoiseOffsets() {
|
|||
}
|
||||
|
||||
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)) {
|
||||
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;
|
||||
|
|
12
src/video.cc
12
src/video.cc
|
@ -113,14 +113,16 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
|
|||
// 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;
|
||||
}
|
||||
|
||||
|
@ -134,7 +136,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
|
|||
|
||||
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_ << ')'
|
||||
|
@ -253,7 +255,9 @@ bool Video::HandleDecodingPacket(AVCodecContext *codec_ctx, AVPacket *pkt,
|
|||
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
|
||||
|
|
|
@ -57,7 +57,8 @@ class Video {
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue