Ejemplo n.º 1
0
 private void tearDownPipeline() {
   ImageFilter.resetStatics();
   FiltersManager.getPreviewManager().freeRSFilterScripts();
   FiltersManager.getManager().freeRSFilterScripts();
   FiltersManager.getHighresManager().freeRSFilterScripts();
   FiltersManager.reset();
   CachingPipeline.destroyRenderScriptContext();
 }
Ejemplo n.º 2
0
 private Bitmap createNotificationBitmap(Bitmap preview, Uri sourceUri, ImagePreset preset) {
   int notificationBitmapSize =
       Resources.getSystem().getDimensionPixelSize(android.R.dimen.notification_large_icon_width);
   if (preview != null) {
     return Bitmap.createScaledBitmap(
         preview, notificationBitmapSize, notificationBitmapSize, true);
   }
   Bitmap bitmap =
       ImageLoader.loadConstrainedBitmap(
           sourceUri, getContext(), notificationBitmapSize, null, true);
   CachingPipeline pipeline = new CachingPipeline(FiltersManager.getManager(), "Thumb");
   return pipeline.renderFinalImage(bitmap, preset);
 }
 public synchronized Bitmap renderFinalImage(Bitmap bitmap, ImagePreset preset) {
   synchronized (CachingPipeline.class) {
     if (getRenderScriptContext() == null) {
       return bitmap;
     }
     setupEnvironment(preset, false);
     mEnvironment.setQuality(FilterEnvironment.QUALITY_FINAL);
     mEnvironment.setScaleFactor(1.0f);
     mFiltersManager.freeFilterResources(preset);
     bitmap = preset.applyGeometry(bitmap, mEnvironment);
     bitmap = preset.apply(bitmap, mEnvironment);
     return bitmap;
   }
 }
 public synchronized void renderImage(ImagePreset preset, Allocation in, Allocation out) {
   synchronized (CachingPipeline.class) {
     if (getRenderScriptContext() == null) {
       return;
     }
     setupEnvironment(preset, false);
     mFiltersManager.freeFilterResources(preset);
     preset.applyFilters(-1, -1, in, out, mEnvironment);
     boolean copyOut = false;
     if (preset.nbFilters() > 0) {
       copyOut = true;
     }
     preset.applyBorder(in, out, copyOut, mEnvironment);
   }
 }
 public void renderFilters(RenderingRequest request) {
   synchronized (CachingPipeline.class) {
     if (getRenderScriptContext() == null) {
       return;
     }
     ImagePreset preset = request.getImagePreset();
     setupEnvironment(preset, false);
     Bitmap bitmap = MasterImage.getImage().getOriginalBitmapHighres();
     if (bitmap == null) {
       return;
     }
     bitmap = mEnvironment.getBitmapCopy(bitmap, BitmapCache.FILTERS);
     bitmap = preset.apply(bitmap, mEnvironment);
     if (!mEnvironment.needsStop()) {
       request.setBitmap(bitmap);
     } else {
       mEnvironment.cache(bitmap);
     }
     mFiltersManager.freeFilterResources(preset);
   }
 }
Ejemplo n.º 6
0
  private void setupPipeline() {
    Resources res = getResources();
    FiltersManager.setResources(res);
    CachingPipeline.createRenderscriptContext(this);

    FiltersManager filtersManager = FiltersManager.getManager();
    filtersManager.addLooks(this);
    filtersManager.addBorders(this);
    filtersManager.addTools(this);
    filtersManager.addEffects();

    FiltersManager highresFiltersManager = FiltersManager.getHighresManager();
    highresFiltersManager.addLooks(this);
    highresFiltersManager.addBorders(this);
    highresFiltersManager.addTools(this);
    highresFiltersManager.addEffects();
  }
  public synchronized void render(RenderingRequest request) {
    // TODO: cleanup/remove GEOMETRY / FILTERS paths
    synchronized (CachingPipeline.class) {
      if (getRenderScriptContext() == null) {
        return;
      }
      if ((request.getType() != RenderingRequest.PARTIAL_RENDERING
              && request.getType() != RenderingRequest.ICON_RENDERING
              && request.getBitmap() == null)
          || request.getImagePreset() == null) {
        return;
      }

      if (DEBUG) {
        Log.v(LOGTAG, "render image of type " + getType(request));
      }

      Bitmap bitmap = request.getBitmap();
      ImagePreset preset = request.getImagePreset();
      setupEnvironment(preset, true);
      mFiltersManager.freeFilterResources(preset);

      if (request.getType() == RenderingRequest.PARTIAL_RENDERING) {
        MasterImage master = MasterImage.getImage();
        bitmap =
            ImageLoader.getScaleOneImageForPreset(
                master.getActivity(),
                mEnvironment.getBimapCache(),
                master.getUri(),
                request.getBounds(),
                request.getDestination());
        if (bitmap == null) {
          Log.w(LOGTAG, "could not get bitmap for: " + getType(request));
          return;
        }
      }

      if (request.getType() == RenderingRequest.FULL_RENDERING
          || request.getType() == RenderingRequest.GEOMETRY_RENDERING
          || request.getType() == RenderingRequest.FILTERS_RENDERING) {
        updateOriginalAllocation(preset);
      }

      if (DEBUG && bitmap != null) {
        Log.v(
            LOGTAG,
            "after update, req bitmap ("
                + bitmap.getWidth()
                + "x"
                + bitmap.getHeight()
                + " ? resizeOriginal ("
                + mResizedOriginalBitmap.getWidth()
                + "x"
                + mResizedOriginalBitmap.getHeight());
      }

      if (request.getType() == RenderingRequest.FULL_RENDERING
          || request.getType() == RenderingRequest.GEOMETRY_RENDERING) {
        mOriginalAllocation.copyTo(bitmap);
      } else if (request.getType() == RenderingRequest.FILTERS_RENDERING) {
        mFiltersOnlyOriginalAllocation.copyTo(bitmap);
      }

      if (request.getType() == RenderingRequest.FULL_RENDERING
          || request.getType() == RenderingRequest.FILTERS_RENDERING
          || request.getType() == RenderingRequest.ICON_RENDERING
          || request.getType() == RenderingRequest.PARTIAL_RENDERING
          || request.getType() == RenderingRequest.STYLE_ICON_RENDERING) {

        if (request.getType() == RenderingRequest.ICON_RENDERING) {
          mEnvironment.setQuality(FilterEnvironment.QUALITY_ICON);
        } else {
          mEnvironment.setQuality(FilterEnvironment.QUALITY_PREVIEW);
        }

        if (request.getType() == RenderingRequest.ICON_RENDERING) {
          Rect iconBounds = request.getIconBounds();
          Bitmap source = MasterImage.getImage().getThumbnailBitmap();
          if (iconBounds.width() > source.getWidth() * 2) {
            source = MasterImage.getImage().getLargeThumbnailBitmap();
          }
          if (iconBounds != null) {
            bitmap =
                mEnvironment.getBitmap(iconBounds.width(), iconBounds.height(), BitmapCache.ICON);
            Canvas canvas = new Canvas(bitmap);
            Matrix m = new Matrix();
            float minSize = Math.min(source.getWidth(), source.getHeight());
            float maxSize = Math.max(iconBounds.width(), iconBounds.height());
            float scale = maxSize / minSize;
            m.setScale(scale, scale);
            float dx = (iconBounds.width() - (source.getWidth() * scale)) / 2.0f;
            float dy = (iconBounds.height() - (source.getHeight() * scale)) / 2.0f;
            m.postTranslate(dx, dy);
            canvas.drawBitmap(source, m, new Paint(Paint.FILTER_BITMAP_FLAG));
          } else {
            bitmap = mEnvironment.getBitmapCopy(source, BitmapCache.ICON);
          }
        }
        Bitmap bmp = preset.apply(bitmap, mEnvironment);
        if (!mEnvironment.needsStop()) {
          request.setBitmap(bmp);
        }
        mFiltersManager.freeFilterResources(preset);
      }
    }
  }