Changeset 4909


Ignore:
Timestamp:
Sep 1, 2014 4:03:31 AM (10 years ago)
Author:
riza
Message:

Re #1762: When capturing, image stride is not always equal to the image width. I.e on Ipad air, at 352*288 the image stride is 384. Additional discard process is
needed to correct the image rendered.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjmedia/src/pjmedia-videodev/ios_dev.m

    r4902 r4909  
    403403    frame.size = stream->frame_size; 
    404404    frame.timestamp.u64 = stream->frame_ts.u64; 
    405  
     405     
    406406    if (stream->is_planar && stream->capture_buf) { 
    407407        if (stream->param.fmt.id == PJMEDIA_FORMAT_I420) { 
     
    409409            pj_uint8_t *p, *p_end, *Y, *U, *V; 
    410410            pj_size_t p_len; 
     411            /* Image stride is not always equal to the image width. I.e on Ipad 
     412             * air, at 352*288 the image stride is 384. 
     413             */ 
     414            pj_size_t stride = CVPixelBufferGetBytesPerRowOfPlane(img, 0); 
     415            pj_bool_t need_clip = (stride != stream->size.w); 
    411416             
    412417            p = (pj_uint8_t*)CVPixelBufferGetBaseAddressOfPlane(img, 0); 
     
    415420            U = Y + p_len; 
    416421            V = U + p_len/4; 
    417             pj_memcpy(Y, p, p_len); 
    418              
     422 
     423            if (!need_clip) { 
     424                pj_memcpy(Y, p, p_len); 
     425            } else { 
     426                int i = 0; 
     427                for (;i<stream->size.h;++i) { 
     428                    pj_memcpy(Y+(i*stream->size.w), p+(i*stride), 
     429                              stream->size.w); 
     430                } 
     431            } 
     432 
    419433            p = (pj_uint8_t*)CVPixelBufferGetBaseAddressOfPlane(img, 1); 
    420             p_len >>= 1; 
    421             p_end = p + p_len; 
    422             while (p < p_end) { 
    423                 *U++ = *p++; 
    424                 *V++ = *p++; 
     434            if (!need_clip) { 
     435                p_len >>= 1; 
     436                p_end = p + p_len; 
     437                 
     438                while (p < p_end) { 
     439                    *U++ = *p++; 
     440                    *V++ = *p++; 
     441                } 
     442            } else { 
     443                int i = 0; 
     444                for (;i<(stream->size.h)/2;++i) { 
     445                    int y=0; 
     446                    for (;y<(stream->size.w)/2;++y) { 
     447                        *U++ = *p++; 
     448                        *V++ = *p++; 
     449                    } 
     450                    p += (stride - stream->size.w); 
     451                } 
    425452            } 
    426453 
Note: See TracChangeset for help on using the changeset viewer.