Skip to content

Commit

Permalink
Lazy Imagepipeline deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikey Rutherford authored and tyronen committed Jun 4, 2015
1 parent d5f855b commit 96d74f3
Showing 1 changed file with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@

package com.facebook.imagepipeline.decoder;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.facebook.common.internal.Preconditions;
import com.facebook.imagepipeline.image.ImmutableQualityInfo;
import com.facebook.imagepipeline.image.QualityInfo;

Expand All @@ -21,28 +22,43 @@
* <p/> If no specific scans to decode are provided, every scan is allowed to be decoded.
*/
public class SimpleProgressiveJpegConfig implements ProgressiveJpegConfig {
private final List<Integer> mScansToDecode;
private final int mGoodEnoughScanNumber;
public interface DynamicValueConfig {
List<Integer> getScansToDecode();
int getGoodEnoughScanNumber();
}

private static class DefaultDynamicValueConfig implements DynamicValueConfig {
public List<Integer> getScansToDecode() {
return Collections.EMPTY_LIST;
}

public int getGoodEnoughScanNumber() {
return 0;
}
}

private final DynamicValueConfig mDynamicValueConfig;

public SimpleProgressiveJpegConfig() {
this(new ArrayList<Integer>(), 0);
this (new DefaultDynamicValueConfig());
}

public SimpleProgressiveJpegConfig(
List<Integer> scansToDecode,
int goodEnoughScanNumber) {
mScansToDecode = scansToDecode;
mGoodEnoughScanNumber = goodEnoughScanNumber;


public SimpleProgressiveJpegConfig(DynamicValueConfig dynamicValueConfig) {
mDynamicValueConfig = Preconditions.checkNotNull(dynamicValueConfig);
}

@Override
public int getNextScanNumberToDecode(int scanNumber) {
if (mScansToDecode == null || mScansToDecode.isEmpty()) {
final List<Integer> scansToDecode = mDynamicValueConfig.getScansToDecode();
if (scansToDecode == null || scansToDecode.isEmpty()) {
return scanNumber + 1;
}
for (int i = 0; i < mScansToDecode.size(); i++) {
if (mScansToDecode.get(i) > scanNumber) {
return mScansToDecode.get(i);

for (int i = 0; i < scansToDecode.size(); i++) {
if (scansToDecode.get(i) > scanNumber) {
return scansToDecode.get(i);
}
}
return Integer.MAX_VALUE;
Expand All @@ -52,7 +68,7 @@ public int getNextScanNumberToDecode(int scanNumber) {
public QualityInfo getQualityInfo(int scanNumber) {
return ImmutableQualityInfo.of(
scanNumber,
/* isOfGoodEnoughQuality */ scanNumber >= mGoodEnoughScanNumber,
/* isOfGoodEnoughQuality */ scanNumber >= mDynamicValueConfig.getGoodEnoughScanNumber(),
/* isOfFullQuality */ false);
}
}

0 comments on commit 96d74f3

Please sign in to comment.