com.facebook.imagepipeline.request.Postprocessor Java Examples

The following examples show how to use com.facebook.imagepipeline.request.Postprocessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PipelineUtil.java    From fresco with MIT License 6 votes vote down vote up
/**
 * Utility method which adds optional configuration to ImageRequest
 *
 * @param imageRequestBuilder The Builder for ImageRequest
 * @param config The Config
 */
public static void addOptionalFeatures(ImageRequestBuilder imageRequestBuilder, Config config) {
  if (config.usePostprocessor) {
    final Postprocessor postprocessor;
    switch (config.postprocessorType) {
      case "use_slow_postprocessor":
        postprocessor = DelayPostprocessor.getMediumPostprocessor();
        break;
      case "use_fast_postprocessor":
        postprocessor = DelayPostprocessor.getFastPostprocessor();
        break;
      default:
        postprocessor = DelayPostprocessor.getMediumPostprocessor();
    }
    imageRequestBuilder.setPostprocessor(postprocessor);
  }
  if (config.rotateUsingMetaData) {
    imageRequestBuilder.setRotationOptions(RotationOptions.autoRotateAtRenderTime());
  } else {
    imageRequestBuilder.setRotationOptions(
        RotationOptions.forceRotation(config.forcedRotationAngle));
  }
}
 
Example #2
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void produceResults(
    final Consumer<CloseableReference<CloseableImage>> consumer,
    ProducerContext context) {
  final ProducerListener listener = context.getListener();
  final Postprocessor postprocessor = context.getImageRequest().getPostprocessor();
  Consumer<CloseableReference<CloseableImage>> postprocessorConsumer;
  if (postprocessor instanceof RepeatedPostprocessor) {
    postprocessorConsumer =
        new RepeatedPostprocessorConsumer(
            consumer,
            listener,
            context.getId(),
            (RepeatedPostprocessor) postprocessor,
            context);
  } else {
    postprocessorConsumer =
        new SingleUsePostprocessorConsumer(consumer, listener, context.getId(), postprocessor);
  }
  mNextProducer.produceResults(postprocessorConsumer, context);
}
 
Example #3
Source File: DefaultCacheKeyFactory.java    From fresco with MIT License 6 votes vote down vote up
@Override
public CacheKey getPostprocessedBitmapCacheKey(
    ImageRequest request, @Nullable Object callerContext) {
  final Postprocessor postprocessor = request.getPostprocessor();
  final CacheKey postprocessorCacheKey;
  final String postprocessorName;
  if (postprocessor != null) {
    postprocessorCacheKey = postprocessor.getPostprocessorCacheKey();
    postprocessorName = postprocessor.getClass().getName();
  } else {
    postprocessorCacheKey = null;
    postprocessorName = null;
  }
  return new BitmapMemoryCacheKey(
      getCacheKeySourceUri(request.getSourceUri()).toString(),
      request.getResizeOptions(),
      request.getRotationOptions(),
      request.getImageDecodeOptions(),
      postprocessorCacheKey,
      postprocessorName,
      callerContext);
}
 
Example #4
Source File: PostprocessorProducer.java    From fresco with MIT License 6 votes vote down vote up
@Override
public void produceResults(
    final Consumer<CloseableReference<CloseableImage>> consumer, ProducerContext context) {
  final ProducerListener2 listener = context.getProducerListener();
  final Postprocessor postprocessor = context.getImageRequest().getPostprocessor();
  final PostprocessorConsumer basePostprocessorConsumer =
      new PostprocessorConsumer(consumer, listener, postprocessor, context);
  final Consumer<CloseableReference<CloseableImage>> postprocessorConsumer;
  if (postprocessor instanceof RepeatedPostprocessor) {
    postprocessorConsumer =
        new RepeatedPostprocessorConsumer(
            basePostprocessorConsumer, (RepeatedPostprocessor) postprocessor, context);
  } else {
    postprocessorConsumer = new SingleUsePostprocessorConsumer(basePostprocessorConsumer);
  }
  mInputProducer.produceResults(postprocessorConsumer, context);
}
 
Example #5
Source File: PostprocessorProducer.java    From fresco with MIT License 6 votes vote down vote up
public PostprocessorConsumer(
    Consumer<CloseableReference<CloseableImage>> consumer,
    ProducerListener2 listener,
    Postprocessor postprocessor,
    ProducerContext producerContext) {
  super(consumer);
  mListener = listener;
  mPostprocessor = postprocessor;
  mProducerContext = producerContext;
  producerContext.addCallbacks(
      new BaseProducerContextCallbacks() {
        @Override
        public void onCancellationRequested() {
          maybeNotifyOnCancellation();
        }
      });
}
 
Example #6
Source File: PostProcessorRegistry.java    From react-native-image-filter-kit with MIT License 6 votes vote down vote up
@Nullable
Postprocessor createComposition(
  @Nullable String name,
  int width,
  int height,
  @Nullable JSONObject config,
  @Nonnull CloseableReference<CloseableImage> imageRef,
  @Nonnull CacheKey imageKey,
  @Nonnull Context context
) {
  @Nullable CreateComposition filter = mCompositions.get(name);

  Assertions.assertCondition(
    filter != null,
    "ImageFilterKit: Can't find '" + name + "' filter in registry."
  );

  return filter != null
    ? filter.create(width, height, config, imageRef, imageKey, context)
    : null;
}
 
Example #7
Source File: PostProcessorRegistry.java    From react-native-image-filter-kit with MIT License 6 votes vote down vote up
@Nullable
Postprocessor createSingular(
  @Nullable String name,
  int width,
  int height,
  @Nullable JSONObject config,
  @Nonnull Context context
) {
  @Nullable CreateSingular filter = mSingulars.get(name);

  Assertions.assertCondition(
    filter != null,
    "ImageFilterKit: Can't find '" + name + "' filter in registry."
  );

  return filter != null ? filter.create(width, height, config, context) : null;
}
 
Example #8
Source File: MultiPostProcessor.java    From react-native-image-filter-kit with MIT License 6 votes vote down vote up
@Override
public CloseableReference<Bitmap> process(
  Bitmap src,
  PlatformBitmapFactory bitmapFactory
) {
  CloseableReference<Bitmap> prevBitmap = null, nextBitmap = null;

  try {
    for (Postprocessor p : mPostProcessors) {
      nextBitmap = p.process(prevBitmap != null ? prevBitmap.get() : src, bitmapFactory);
      CloseableReference.closeSafely(prevBitmap);
      prevBitmap = nextBitmap.clone();
    }

    return nextBitmap == null ? super.process(src, bitmapFactory) : nextBitmap.clone();
  } finally {
    CloseableReference.closeSafely(nextBitmap);
  }
}
 
Example #9
Source File: PostprocessorProducer.java    From fresco with MIT License 5 votes vote down vote up
private @Nullable Map<String, String> getExtraMap(
    ProducerListener2 listener, ProducerContext producerContext, Postprocessor postprocessor) {
  if (!listener.requiresExtraMap(producerContext, NAME)) {
    return null;
  }
  return ImmutableMap.of(POSTPROCESSOR, postprocessor.getName());
}
 
Example #10
Source File: ImagePipelinePostProcessorFragment.java    From fresco with MIT License 5 votes vote down vote up
private void setPostprocessor(Postprocessor postprocessor) {
  final ImageRequest imageRequest =
      ImageRequestBuilder.newBuilderWithSource(mUri).setPostprocessor(postprocessor).build();

  final DraweeController draweeController =
      Fresco.newDraweeControllerBuilder()
          .setOldController(mDraweeMain.getController())
          .setImageRequest(imageRequest)
          .build();

  mDraweeMain.setController(draweeController);
}
 
Example #11
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private SingleUsePostprocessorConsumer(
    Consumer<CloseableReference<CloseableImage>> consumer,
    ProducerListener listener,
    String requestId,
    Postprocessor postprocessor) {
  super(consumer, listener, requestId, postprocessor);
}
 
Example #12
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private Map<String, String> getExtraMap(
    ProducerListener listener,
    String requestId,
    Postprocessor postprocessor) {
  if (!listener.requiresExtraMap(requestId)) {
    return null;
  }
  return ImmutableMap.of(POSTPROCESSOR, postprocessor.getName());
}
 
Example #13
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private void postprocessBitmap(
    CloseableReference<CloseableImage> destinationCloseableImageRef,
    Postprocessor postprocessor) {
  Bitmap destinationBitmap =
      ((CloseableBitmap) destinationCloseableImageRef.get()).getUnderlyingBitmap();
  postprocessor.process(destinationBitmap);
}
 
Example #14
Source File: PostprocessorProducer.java    From FanXin-based-HuanXin with GNU General Public License v2.0 5 votes vote down vote up
private AbstractPostprocessorConsumer(
    Consumer<CloseableReference<CloseableImage>> consumer,
    ProducerListener listener,
    String requestId,
    Postprocessor postprocessor) {
  mConsumer = consumer;
  mListener = listener;
  mRequestId = requestId;
  mPostprocessor = postprocessor;
}
 
Example #15
Source File: FrescoHelper.java    From FrescoUtils with Apache License 2.0 5 votes vote down vote up
private static void init(FrescoImageView imageView, int cornerRadius, boolean isCircle, boolean isAnima,
                         Point size, Postprocessor postprocessor) {
    imageView.setAnim(isAnima);
    imageView.setCornerRadius(cornerRadius);
    imageView.setFadeTime(300);
    if (isCircle)
        imageView.asCircle();
    if (postprocessor != null)
        imageView.setPostProcessor(postprocessor);
    if (size != null) {
        imageView.setResize(size);
    }
}
 
Example #16
Source File: MultiPostprocessor.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public CloseableReference<Bitmap>	process(Bitmap sourceBitmap, PlatformBitmapFactory bitmapFactory) {
  CloseableReference<Bitmap> prevBitmap = null, nextBitmap = null;

  try {
    for (Postprocessor p : mPostprocessors) {
      nextBitmap = p.process(prevBitmap != null ? prevBitmap.get() : sourceBitmap, bitmapFactory);
      CloseableReference.closeSafely(prevBitmap);
      prevBitmap = nextBitmap.clone();
    }
    return nextBitmap.clone();
  } finally {
    CloseableReference.closeSafely(nextBitmap);
  }
}
 
Example #17
Source File: MultiPostprocessor.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public CacheKey getPostprocessorCacheKey () {
  LinkedList<CacheKey> keys = new LinkedList<>();
  for (Postprocessor p: mPostprocessors) {
    keys.push(p.getPostprocessorCacheKey());
  }
  return new MultiCacheKey(keys);
}
 
Example #18
Source File: MultiPostprocessor.java    From react-native-GPay with MIT License 5 votes vote down vote up
@Override
public String getName () {
  StringBuilder name = new StringBuilder();
  for (Postprocessor p: mPostprocessors) {
    if (name.length() > 0) {
      name.append(",");
    }
    name.append(p.getName());
  }
  name.insert(0, "MultiPostProcessor (");
  name.append(")");
  return name.toString();
}
 
Example #19
Source File: MultiPostprocessor.java    From react-native-GPay with MIT License 5 votes vote down vote up
public static Postprocessor from(List<Postprocessor> postprocessors) {
  switch (postprocessors.size()) {
    case 0:
      return null;
    case 1:
      return postprocessors.get(0);
    default:
      return new MultiPostprocessor(postprocessors);
  }
}
 
Example #20
Source File: MultiPostProcessor.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
@Override
public String getName() {
  StringBuilder name = new StringBuilder();
  for (Postprocessor p: mPostProcessors) {
    if (name.length() > 0) {
      name.append(",");
    }
    name.append(p.getName());
  }
  name.insert(0, "MultiPostProcessor (");
  name.append(")");
  return name.toString();
}
 
Example #21
Source File: PostProcessorRegistry.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
Postprocessor create(
  int width,
  int height,
  @Nullable JSONObject config,
  @Nonnull CloseableReference<CloseableImage> imageRef,
  @Nonnull CacheKey imageKey,
  @Nonnull Context context
);
 
Example #22
Source File: WeakFilterableImage.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
WeakFilterableImage(
  final @Nonnull ArrayList<Postprocessor> postProcessors,
  final boolean cacheDisabled
) {
  mCacheDisabled = cacheDisabled;
  mPostProcessors = new ArrayList<>();

  for (Postprocessor p : postProcessors) {
    mPostProcessors.add(new WeakReference<>(p));
  }
}
 
Example #23
Source File: WeakFilterableImage.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
@Nullable ArrayList<Postprocessor> getPostProcessors() {
  ArrayList<Postprocessor> ps = new ArrayList<>();

  for (WeakReference<Postprocessor> weak : mPostProcessors) {
    Postprocessor p = weak.get();

    if (p == null) {
      return null;
    }

    ps.add(p);
  }

  return ps;
}
 
Example #24
Source File: FilterableImage.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
FilterableImage(
  final @Nonnull ReactImageView image,
  final @Nonnull ArrayList<Postprocessor> postProcessors,
  final boolean cacheDisabled
) {
  mImage = image;
  mPostProcessors = postProcessors;
  mCacheDisabled = cacheDisabled;
}
 
Example #25
Source File: FilterableImage.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
CacheKey generatedCacheKey() {
  final ArrayList<CacheKey> keys = new ArrayList<>(
    Collections.singletonList(ReactImageViewUtils.getCacheKey(mImage))
  );

  for (Postprocessor p : mPostProcessors) {
    keys.add(
      p instanceof CacheablePostProcessor
        ? ((CacheablePostProcessor) p).generateCacheKey()
        : p.getPostprocessorCacheKey()
    );
  }

  return new MultiCacheKey(keys);
}
 
Example #26
Source File: ImageFilter.java    From react-native-image-filter-kit with MIT License 5 votes vote down vote up
private Task<FilterableImage> createSingularImage(
  final @Nonnull JSONObject config,
  final @Nonnull Task<FilterableImage> prevImage
) throws JSONException {
  final String name = config.getString("name");

  return prevImage
    .onSuccess(task -> {
      final FilterableImage result = task.getResult();
      final ArrayList<Postprocessor> postProcessors = new ArrayList<>(result.getPostProcessors());

      postProcessors.add(
        PostProcessorRegistry.getInstance()
          .createSingular(
            name,
            mDefaultWidth,
            mDefaultHeight,
            config,
            getContext()
          )
      );

      final boolean cacheDisabled = CacheablePostProcessor.cacheDisabled(config);

      return new FilterableImage(result.getImage(), postProcessors, cacheDisabled);
    }, mFiltering.getToken());
}
 
Example #27
Source File: FilterableImage.java    From react-native-image-filter-kit with MIT License 4 votes vote down vote up
ArrayList<Postprocessor> getPostProcessors() {
  return mPostProcessors;
}
 
Example #28
Source File: MultiPostprocessor.java    From react-native-GPay with MIT License 4 votes vote down vote up
private MultiPostprocessor(List<Postprocessor> postprocessors) {
   mPostprocessors = new LinkedList<>(postprocessors);
}
 
Example #29
Source File: ImagePipelinePostProcessorFragment.java    From fresco with MIT License 4 votes vote down vote up
Entry(int descriptionId, Postprocessor postprocessor) {
  this.descriptionId = descriptionId;
  this.postprocessor = postprocessor;
}
 
Example #30
Source File: PostProcessorRegistry.java    From react-native-image-filter-kit with MIT License 4 votes vote down vote up
Postprocessor create(
  int width,
  int height,
  @Nullable JSONObject config,
  @Nonnull Context context
);