shithub: libvpx

Download patch

ref: fd9f9dc0547ae55bf729a92ac5fc4ba9a259f197
parent: 19e32ac7c7df70d5525d22bda784e5373fb9c705
author: Pascal Massimino <pascal.massimino@gmail.com>
date: Tue Nov 23 19:22:59 EST 2010

allow dimensions as low as 1 pixel

remove warning comment in vpxenc.c: in case of 1x1 picture,
detect_bytes will be equal to '3' and we'll fall back to
RAW_TYPE.
fix read_frame() by tracking the pre-read buffer length
in the struct detect

Change-Id: If1ed86ee5260dcdbc8f9d10da6cbb84a4cc2f151

--- a/vp8/vp8_cx_iface.c
+++ b/vp8/vp8_cx_iface.c
@@ -133,8 +133,8 @@
                                        const vpx_codec_enc_cfg_t *cfg,
                                        const struct vp8_extracfg *vp8_cfg)
 {
-    RANGE_CHECK(cfg, g_w,                   2, 16384);
-    RANGE_CHECK(cfg, g_h,                   2, 16384);
+    RANGE_CHECK(cfg, g_w,                   1, 16384);
+    RANGE_CHECK(cfg, g_h,                   1, 16384);
     RANGE_CHECK(cfg, g_timebase.den,        1, 1000000000);
     RANGE_CHECK(cfg, g_timebase.num,        1, cfg->g_timebase.den);
     RANGE_CHECK_HI(cfg, g_profile,          3);
--- a/vpxenc.c
+++ b/vpxenc.c
@@ -251,7 +251,8 @@
 
 struct detect_buffer {
     char buf[4];
-    int  valid;
+    size_t buf_read;
+    size_t position;
 };
 
 
@@ -305,14 +306,21 @@
 
             for (r = 0; r < h; r++)
             {
-                if (detect->valid)
+                size_t needed = w;
+                size_t buf_position = 0;
+                const size_t left = detect->buf_read - detect->position;
+                if (left > 0)
                 {
-                    memcpy(ptr, detect->buf, 4);
-                    shortread |= fread(ptr+4, 1, w-4, f) < w-4;
-                    detect->valid = 0;
+                    const size_t more = (left < needed) ? left : needed;
+                    memcpy(ptr, detect->buf + detect->position, more);
+                    buf_position = more;
+                    needed -= more;
+                    detect->position += more;
                 }
-                else
-                    shortread |= fread(ptr, 1, w, f) < w;
+                if (needed > 0)
+                {
+                    shortread |= (fread(ptr + buf_position, 1, needed, f) < needed);
+                }
 
                 ptr += img->stride[plane];
             }
@@ -1338,7 +1346,6 @@
     {
         int frames_in = 0, frames_out = 0;
         unsigned long nbytes = 0;
-        size_t detect_bytes;
         struct detect_buffer detect;
 
         /* Parse certain options from the input file, if possible */
@@ -1353,13 +1360,11 @@
 
         /* For RAW input sources, these bytes will applied on the first frame
          *  in read_frame().
-         * We can always read 4 bytes because the minimum supported frame size
-         *  is 2x2.
          */
-        detect_bytes = fread(detect.buf, 1, 4, infile);
-        detect.valid = 0;
+        detect.buf_read = fread(detect.buf, 1, 4, infile);
+        detect.position = 0;
 
-        if (detect_bytes == 4 && file_is_y4m(infile, &y4m, detect.buf))
+        if (detect.buf_read == 4 && file_is_y4m(infile, &y4m, detect.buf))
         {
             if (y4m_input_open(&y4m, infile, detect.buf, 4) >= 0)
             {
@@ -1384,7 +1389,7 @@
                 return EXIT_FAILURE;
             }
         }
-        else if (detect_bytes == 4 &&
+        else if (detect.buf_read == 4 &&
                  file_is_ivf(infile, &fourcc, &cfg.g_w, &cfg.g_h, detect.buf))
         {
             file_type = FILE_TYPE_IVF;
@@ -1404,7 +1409,6 @@
         else
         {
             file_type = FILE_TYPE_RAW;
-            detect.valid = 1;
         }
 
         if(!cfg.g_w || !cfg.g_h)