Add luma only master
authorPeng Li <seudut@gmail.com>
Thu, 31 May 2018 16:07:15 +0000 (00:07 +0800)
committerPeng Li <seudut@gmail.com>
Fri, 8 Jun 2018 16:21:35 +0000 (00:21 +0800)
Makefile
yuvPlayer.cpp

index 23e4c43..67c8fe0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,8 @@ LDFLAGS = -fpic \
 #LDLIBS = -lavdevice -lavformat -lavfilter -lavcodec -lswresample -lswscale -lpostproc -lavutil -lSDL2
 LDLIBS = -lSDL2
 
-TARGETS =      yuvPlayer
+TARGETS =      yuvPlayer \
+                       yuv
 
 OBJS = $(addsuffix .o,$(TARGETS))
 
index fe7f45e..fb8c1a9 100644 (file)
@@ -27,6 +27,7 @@ public:
     YuvPlayer(int width, int height, const string& title = "YUV Player");
     void play(string fname, int fps = -1);
     void toggleGrid();
+    void toggleYumaOnly();
     ~YuvPlayer();
 
 private:
@@ -42,6 +43,7 @@ private:
     string title;
     ifstream::pos_type last_pos;
     bool isShowingGrid = false;
+    bool isLumOnly = false;
     uint8_t *raw;
 };
 
@@ -79,6 +81,20 @@ YuvPlayer::~YuvPlayer()
     SDL_Quit();
 }
 
+// https://wiki.videolan.org/YUV/, YCrCb
+// I420, YUV420p,  YYYY YYYY UU VV
+static void lumaOnly(uint8_t *raw, int w, int h)
+{
+    memset(raw + w * h, 128, w * h / 2); // UV 128
+    //memset(raw + w * h, 0, w * h / 2); // UV 128
+    //memset(raw + w * h, 0, w * h / 2); // UV 0, G only
+    //memset(raw + w * h, 255, w * h / 2); // UV 0, R only
+    //memset(raw + w * h, 128, w * h / 4); // U 128
+    //for (int i = 0; i < w * h; i++){
+    //    raw[i] = raw[i] / 2; // Y to 1/2
+    //}
+}
+
 void YuvPlayer::play(string file, int fps)
 {
     size_t frame_size = width * height * 3 / 2;
@@ -130,6 +146,8 @@ void YuvPlayer::play(string file, int fps)
                     case SDLK_g:
                         toggleGrid();
                         break;
+                    case SDLK_y:
+                        toggleYumaOnly();
                     default:
                         break;
                 }
@@ -139,6 +157,11 @@ void YuvPlayer::play(string file, int fps)
     }
     free(raw);
 }
+void YuvPlayer::toggleYumaOnly()
+{
+    isLumOnly = !isLumOnly;
+    updateRenderer(this->raw);
+}
 
 void YuvPlayer::toggleGrid()
 {
@@ -164,6 +187,9 @@ bool YuvPlayer::readFrame(ifstream& in, uint8_t *raw, size_t size)
 
 void YuvPlayer::updateRenderer(uint8_t *raw)
 {    
+    if (isLumOnly){
+        lumaOnly(raw, width, height);
+    }
     SDL_UpdateTexture(texture, nullptr, raw, width * SDL_BYTESPERPIXEL(SDL_PIXELFORMAT_IYUV));
     SDL_RenderClear(renderer);
     SDL_RenderCopy(renderer, texture, nullptr, nullptr);
@@ -184,8 +210,14 @@ void YuvPlayer::updateRenderer(uint8_t *raw)
 
 int main(int argc, char* argv[])
 {
-    string fname = "out.yuv";
+//    string fname(argv[1] ? argv[1] : "out.yuv");
+//    size_t width  = atoi(argv[2] ? argv[2] : "1280");
+//    size_t height = atoi(argv[3] ? argv[3] : "720");
+//
+//    int fps = atoi(argv[4] ? argv[4] : "20");
+//    cout << fname << "\n" << width << "\n" << height << "\n" << fps << "\n" << endl;
+//
     YuvPlayer player(1280, 720);
-    player.play(fname, 25);
+    player.play("out.yuv", 25);
     //player.play(fname);
 }