]> git.seodisparate.com - EN605.617.81.FA21_StephenSeo_DitheringProject/commitdiff
Minor fixes
authorStephen Seo <seo.disparate@gmail.com>
Thu, 2 Dec 2021 13:01:26 +0000 (22:01 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 2 Dec 2021 13:01:26 +0000 (22:01 +0900)
src/image.cc
src/video.cc
src/video.h

index 247bff2adbeceaf2eb67f8824df0c41f657fefe8..ca9b2dcf2c9c504cc504d26f6ed79487a6911bd1 100644 (file)
@@ -1423,16 +1423,13 @@ 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)) {
-      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;
 }
index a06722e3f8fbf50c1f39e86395b3b4132d30773b..a8984aa646005bce96793d6fe4b7f65519fa7afd 100644 (file)
@@ -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
index 3662598792f2bdc414a06837ffba63f0d1610eed..3e6c2e707c5055531ac405818af6118e1da01961 100644 (file)
@@ -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