• Leon Scroggins III's avatar
    Add an option on SkImageDecoder to skip writing 0s. · 34835907
    Leon Scroggins III authored
    Only implemented for PNG.
    
    Add a getter and setter, and sets the default to false in the
    constructor. Also copies the setting in copyFieldsToOther.
    
    Fix an indpendent bug where fDitherImage was not being copied in
    copyFieldsToOther.
    
    In SkScaledBitmapSampler::begin, consolidate the settings passed in
    by passing a const reference to the decoder. The decoder can be
    referenced for its settings of dither, unpremultiplied, and now
    skipping writing zeroes. Update callers to use the new API. In png
    decoder, rather than passing around a pointer to an initial
    read of getDitherImage, and potentially changing it, look at the
    field on the decoder itself, and modify it directly. This is a
    change in behavior - now if that same decoder is used to decode
    a different image, the dither setting has changed. I think this is
    okay because A) the typical use case is to use a new decoder for
    each decode, B) we do not make any promises that a decode does not
    change the decoder and C) it makes the code in SkScaledBitmapSampler
    much cleaner.
    
    In SkScaledBitmapScampler, add new row procs for skipping zeroes. Now
    that choosing the row proc has five dimensions (src config, dst config,
    dither, skip writing zeroes, unpremultiplied), use a new method: each
    src/dst combination has a function for choosing the right proc depending
    on the decoder.
    
    SkScaledBitmapScampler::RowProc is now public for convenience.
    
    Remove Sample_Gray_D8888_Unpremul, which is effectively no different
    from Sample_Gray_D8888.
    
    In cases where unpremultiplied was trivial, such as 565 and when
    sampling from gray, decoding may now succeed.
    
    Add a benchmark (currently disabled) for comparing the speed of skipping
    writing zeroes versus not skipping. For this particular image, which is
    mostly transparent pixels, normal decoding took about 3.6 milliseconds,
    while skipping zeroes in the decode took only about 2.5 milliseconds
    (this is on a Nexus 4). Presumably it would be slower on an image
    with a small amount of transparency, but there will be no slowdown
    for an image which reports that it has no transparency.
    
    In SkImageRef_ashmem, always skip writing zeroes, since ashmem
    memory is guaranteed to be initialized to 0.
    
    Add a flag to skip writing zeroes in skimage.
    
    Add a regression test for choosing the rowproc to ensure I did not
    change any behavior accidentally.
    
    BUG:10016979
    Change-Id: I5986ae750b85a9c9d8e3cafeebe904910247de3b
    34835907
SkImageDecoder.h 22.7 KB