Browse Source

Merge pull request #28 from tsoding/cleanup

Cleanup
Alexey Kutepov 5 years ago
parent
commit
591b9976c0
3 changed files with 29 additions and 74 deletions
  1. 1 1
      Makefile
  2. 21 19
      src/vodus_bttv.cpp
  3. 7 54
      src/vodus_main.cpp

+ 1 - 1
Makefile

@@ -12,4 +12,4 @@ vodus: src/vodus.cpp src/vodus_image32.cpp src/vodus_main.cpp
 render: output.mpeg
 
 output.mpeg: vodus
-	./vodus 'Chat! Vy r u ded?' assets/phpHop.gif assets/ayaya.png assets/ComicNeue_Bold.otf output.mpeg
+	./vodus assets/phpHop.gif assets/ayaya.png assets/ComicNeue_Bold.otf output.mpeg

+ 21 - 19
src/vodus_bttv.cpp

@@ -7,6 +7,7 @@ struct Gif_Animat
 
     void update(float dt)
     {
+        // TODO(#29): If dt is too big Gif_Animat::index could probably go out of sync
         delay_time -= dt * 100;
         if (delay_time <= 0.0f) {
             index = (index + 1) % file->ImageCount;
@@ -48,15 +49,16 @@ struct Gif_Animat
     }
 };
 
-enum class Bttv_Emote_Type
+struct Emote
 {
-    Png = 0,
-    Gif
-};
+    enum Type
+    {
+        Png = 0,
+        Gif
+    };
+
+    Type type;
 
-struct Bttv_Emote
-{
-    Bttv_Emote_Type type;
     union
     {
         Image32 png;
@@ -66,35 +68,35 @@ struct Bttv_Emote
     int width() const
     {
         switch (type) {
-        case Bttv_Emote_Type::Png: return png.width;
-        case Bttv_Emote_Type::Gif: return gif.width();
+        case Png: return png.width;
+        case Gif: return gif.width();
         }
-        assert(!"Incorrect Bttv_Emote_Type value");
+        assert(!"Incorrect Emote_Type value");
         return 0;
     }
 
     int height() const
     {
         switch (type) {
-        case Bttv_Emote_Type::Png: return png.height;
-        case Bttv_Emote_Type::Gif: return gif.height();
+        case Png: return png.height;
+        case Gif: return gif.height();
         }
-        assert(!"Incorrect Bttv_Emote_Type value");
+        assert(!"Incorrect Emote_Type value");
         return 0;
     }
 
     void slap_onto_image32(Image32 surface, int x, int y, int w, int h)
     {
         switch (type) {
-        case Bttv_Emote_Type::Png: {
+        case Png: {
             slap_image32_onto_image32(surface, png, x, y, w, h);
         } return;
 
-        case Bttv_Emote_Type::Gif: {
+        case Gif: {
             gif.slap_onto_image32(surface, x, y, w, h);
         } return;
         }
-        assert(!"Incorrect Bttv_Emote_Type value");
+        assert(!"Incorrect Emote_Type value");
     }
 };
 
@@ -107,17 +109,17 @@ struct Maybe
 
 struct Bttv
 {
-    Maybe<Bttv_Emote> emote_by_name(String_View name,
+    Maybe<Emote> emote_by_name(String_View name,
                                     const char *channel = nullptr)
     {
         // TODO(#19): Emotes in Bttv::emote_by_name are hardcoded
         //    Some sort of a cache system is required here.
         if (name == "AYAYA"_sv) {
-            Bttv_Emote emote = {Bttv_Emote_Type::Png};
+            Emote emote = {Emote::Png};
             emote.png = ayaya_image;
             return {true, emote};
         } else if (name == "phpHop"_sv) {
-            Bttv_Emote emote = {Bttv_Emote_Type::Gif};
+            Emote emote = {Emote::Gif};
             emote.gif = php_hop;
             return {true, emote};
         }

+ 7 - 54
src/vodus_main.cpp

@@ -40,7 +40,7 @@ const float VODUS_DELTA_TIME_SEC = 1.0f / VODUS_FPS;
 const size_t VODUS_WIDTH = 1028;
 const size_t VODUS_HEIGHT = 768;
 const float VODUS_VIDEO_DURATION = 5.0f;
-const size_t VODUS_FONT_SIZE = 128;
+const size_t VODUS_FONT_SIZE = 64;
 
 void encode_avframe(AVCodecContext *context, AVFrame *frame, AVPacket *pkt, FILE *outfile)
 {
@@ -212,62 +212,17 @@ void sample_chat_log_animation(FT_Face face, Encode_Frame encode_frame, Bttv *bt
     }
 }
 
-void test_animation(GifFileType *gif_file,
-                    Image32 png_sample_image,
-                    FT_Face face,
-                    const char *text,
-                    Encode_Frame encode_frame)
-{
-    assert(gif_file->ImageCount > 0);
-    Gif_Animat gif_animat = {gif_file};
-
-    Image32 surface = {
-        .width = VODUS_WIDTH,
-        .height = VODUS_HEIGHT,
-        .pixels = new Pixel32[VODUS_WIDTH * VODUS_HEIGHT]
-    };
-    defer(delete[] surface.pixels);
-
-    float text_x = 0.0f;
-    float text_y = VODUS_HEIGHT;
-    float t = 0.0f;
-    for (int frame_index = 0; text_y > 0.0f; ++frame_index) {
-        fill_image32_with_color(surface, {50, 0, 0, 255});
-
-        gif_animat.slap_onto_image32(surface, (int) text_x, (int) text_y);
-        slap_image32_onto_image32(
-            surface,
-            png_sample_image,
-            (int) text_x + gif_animat.width(), (int) text_y);
-
-        {
-            int x = (int) text_x;
-            int y = (int) text_y;
-            slap_text_onto_image32(surface, face, text, {0, 255, 0, 255},
-                                   &x, &y);
-        }
-
-        gif_animat.update(VODUS_DELTA_TIME_SEC);
-
-        encode_frame(surface, frame_index);
-
-        text_y -= (VODUS_HEIGHT / VODUS_VIDEO_DURATION) * VODUS_DELTA_TIME_SEC;
-        t += VODUS_DELTA_TIME_SEC;
-    }
-}
-
 int main(int argc, char *argv[])
 {
-    if (argc < 6) {
-        fprintf(stderr, "Usage: ./vodus <text> <gif_image> <png_image> <font> <output>\n");
+    if (argc < 5) {
+        fprintf(stderr, "Usage: ./vodus <gif_image> <png_image> <font> <output>\n");
         exit(1);
     }
 
-    const char *text = argv[1];
-    const char *gif_filepath = argv[2];
-    const char *png_filepath = argv[3];
-    const char *face_file_path = argv[4];
-    const char *output_filepath = argv[5];
+    const char *gif_filepath = argv[1];
+    const char *png_filepath = argv[2];
+    const char *face_file_path = argv[3];
+    const char *output_filepath = argv[4];
 
     FT_Library library;
     auto error = FT_Init_FreeType(&library);
@@ -372,8 +327,6 @@ int main(int argc, char *argv[])
               });
 
     sample_chat_log_animation(face, encode_frame, &bttv);
-    // test_animation(gif_file, png_sample_image, face, text,
-    //                encode_frame);
 
     encode_avframe(context, NULL, packet, output_stream);