Ticket #5259: yuyv_yuv420p_interlaced.patch

File yuyv_yuv420p_interlaced.patch, 2.7 KB (added by jrgreen@…, 16 years ago)

patch implementing interlaced chroma subsampling with linear interpolation

  • libs/libmythtv/NuppelVideoRecorder.cpp

     
    15591559
    15601560                uint8_t *src = buffers[frame];
    15611561
    1562                 // Round height to multiple of two.
    1563                 unsigned height = (h / 2) * 2;
     1562                // Interlaced chroma subsampling: samples reside between
     1563                // scan lines and are linearly interpolated using the
     1564                // nearest lines from the same field.
    15641565
    1565                 // Treat lines in batches of two, first use color information, then don't
     1566                // Round height to multiple of four.
     1567                unsigned height = (h / 4) * 4;
     1568
    15661569                unsigned line_size = w * 2;
    15671570
    1568                 for (unsigned line = 0; line < height; line += 2)
     1571                // Treat lines in batches of four
     1572                for (unsigned line = 0; line < height; line += 4)
    15691573                {
    15701574                    uint8_t *src_endline = src + line_size;
     1575                    uint8_t *src2 = src + line_size * 2;
    15711576
    1572                     // convert first line, use color information
     1577                    // luma from line 1 and chroma from lines 1 and 3
    15731578                    while (src < src_endline)
    15741579                    {
    15751580                        *y_plane++ = *src++;
    1576                         *cb_plane++ = *src++;
     1581                        src2++;
     1582                        *cb_plane++ = (*src++ * 3 + *src2++) / 4;
    15771583                        *y_plane++ = *src++;
    1578                         *cr_plane++ = *src++;
     1584                        src2++;
     1585                        *cr_plane++ = (*src++ * 3 + *src2++) / 4;
    15791586                    }
    15801587
    15811588                    src_endline = src + line_size;
    15821589
    1583                     // convert second line, don't use color information
     1590                    // luma from line 2 and chroma from lines 2 and 4
    15841591                    while (src < src_endline)
    15851592                    {
    15861593                        *y_plane++ = *src++;
     1594                        src2++;
     1595                        *cb_plane++ = (*src++ + *src2++ * 3) / 4;
     1596                        *y_plane++ = *src++;
     1597                        src2++;
     1598                        *cr_plane++ = (*src++ + *src2++ * 3) / 4;
     1599                    }
     1600
     1601                    src_endline = src + line_size * 2;
     1602
     1603                    // luma from line 3 and from line 4
     1604                    while (src < src_endline)
     1605                    {
     1606                        *y_plane++ = *src++;
    15871607                        src++;
    15881608                        *y_plane++ = *src++;
    15891609                        src++;