예제 #1
0
static OfxStatus render(OfxImageEffectHandle  instance,
                        OfxPropertySetHandle inArgs,
                        OfxPropertySetHandle outArgs)
{
  OfxTime time;
  OfxRectI renderWindow;
  OfxStatus status = kOfxStatOK;
  
  gPropHost->propGetDouble(inArgs, kOfxPropTime, 0, &time);
  gPropHost->propGetIntN(inArgs, kOfxImageEffectPropRenderWindow, 4, &renderWindow.x1);

  OfxImageClipHandle outputClip;
  gEffectHost->clipGetHandle(instance, "Output", &outputClip, 0);
    

  OfxPropertySetHandle currentImg = NULL, prevImg = NULL, nextImg = NULL, outputImg = NULL;

  try {
    OfxPropertySetHandle outputImg;
    if(gEffectHost->clipGetImage(outputClip, time, NULL, &outputImg) != kOfxStatOK) {
      throw NoImageEx();
    }
      
    int dstRowBytes, dstBitDepth;
    OfxRectI dstRect;
    void *dstPtr;
    gPropHost->propGetInt(outputImg, kOfxImagePropRowBytes, 0, &dstRowBytes);
    gPropHost->propGetIntN(outputImg, kOfxImagePropBounds, 4, &dstRect.x1);
    gPropHost->propGetInt(outputImg, kOfxImagePropRowBytes, 0, &dstRowBytes);
    gPropHost->propGetPointer(outputImg, kOfxImagePropData, 0, &dstPtr);
      
    OfxImageClipHandle sourceClip;
    gEffectHost->clipGetHandle(instance, "Source", &sourceClip, 0);
      
    if(gEffectHost->clipGetImage(sourceClip, time > 1 ? (time - 1) : time, NULL, &prevImg) != kOfxStatOK) {
      throw NoImageEx();
    }
    
    if(gEffectHost->clipGetImage(sourceClip, time < 50 ? (time + 1) : time, NULL, &nextImg) != kOfxStatOK) {
      throw NoImageEx();
    }

    if (gEffectHost->clipGetImage(sourceClip, time, NULL, &currentImg) != kOfxStatOK) {
      throw NoImageEx();
    }
      
    int srcRowBytes, srcBitDepth;
    OfxRectI srcRect;
    void *curPtr, *prevPtr, *nextPtr;
    gPropHost->propGetInt(currentImg, kOfxImagePropRowBytes, 0, &srcRowBytes);
    gPropHost->propGetIntN(currentImg, kOfxImagePropBounds, 4, &srcRect.x1);
    gPropHost->propGetInt(currentImg, kOfxImagePropRowBytes, 0, &srcRowBytes);
    gPropHost->propGetPointer(prevImg, kOfxImagePropData, 0, &prevPtr);
    gPropHost->propGetPointer(currentImg, kOfxImagePropData, 0, &curPtr);
    gPropHost->propGetPointer(nextImg, kOfxImagePropData, 0, &nextPtr);

    OfxRGBAColourB *prev = (OfxRGBAColourB *) prevPtr;
    OfxRGBAColourB *cur = (OfxRGBAColourB *) curPtr;
    OfxRGBAColourB *next = (OfxRGBAColourB *) nextPtr;
    OfxRGBAColourB *dst = (OfxRGBAColourB *) dstPtr;

    for(int y = renderWindow.y1; y < renderWindow.y2; y++) {
      if(gEffectHost->abort(instance)) break;

      OfxRGBAColourB *dstPix = pixelAddress(dst, dstRect, renderWindow.x1, y, dstRowBytes);

      for(int x = renderWindow.x1; x < renderWindow.x2; x++) {
        
        OfxRGBAColourB *prevPix = pixelAddress(prev, srcRect, x, y, srcRowBytes);
        OfxRGBAColourB *curPix = pixelAddress(cur, srcRect, x, y, srcRowBytes);
        OfxRGBAColourB *nextPix = pixelAddress(next, srcRect, x, y, srcRowBytes);

        if(curPix) {
            dstPix->r = (prevPix->r + curPix->r + nextPix->r) / 3;
            dstPix->g = (prevPix->g + curPix->g + nextPix->g) / 3;
            dstPix->b = (prevPix->b + curPix->b + nextPix->b) / 3;
            dstPix->a = 255;
        }
        else {
          dstPix->r = 0;
          dstPix->g = 0;
          dstPix->b = 0;
          dstPix->a = 0;
        }
        dstPix++;
      }
    }
  }
  catch(NoImageEx &) {
    // if we were interrupted, the failed fetch is fine, just return kOfxStatOK
    // otherwise, something wierd happened
    if(!gEffectHost->abort(instance)) {
      status = kOfxStatFailed;
    }      
  }

  if(prevImg)
    gEffectHost->clipReleaseImage(prevImg);
  if(currentImg)
    gEffectHost->clipReleaseImage(currentImg);
  if(outputImg)
    gEffectHost->clipReleaseImage(outputImg);
  
  return status;
}
예제 #2
0
파일: invert.cpp 프로젝트: mick50/openfx
// the process code  that the host sees
static OfxStatus render(OfxImageEffectHandle  instance,
                        OfxPropertySetHandle inArgs,
                        OfxPropertySetHandle /*outArgs*/)
{
  // get the render window and the time from the inArgs
  OfxTime time;
  OfxRectI renderWindow;
  OfxStatus status = kOfxStatOK;
  
  gPropHost->propGetDouble(inArgs, kOfxPropTime, 0, &time);
  gPropHost->propGetIntN(inArgs, kOfxImageEffectPropRenderWindow, 4, &renderWindow.x1);

  // fetch output clip
  OfxImageClipHandle outputClip;
  gEffectHost->clipGetHandle(instance, kOfxImageEffectOutputClipName, &outputClip, 0);
    

  OfxPropertySetHandle outputImg = NULL, sourceImg = NULL;
  try {
    // fetch image to render into from that clip
    OfxPropertySetHandle outputImg;
    if(gEffectHost->clipGetImage(outputClip, time, NULL, &outputImg) != kOfxStatOK) {
      throw NoImageEx();
    }
      
    // fetch output image info from that handle
    int dstRowBytes;
    OfxRectI dstRect;
    void *dstPtr;
    gPropHost->propGetInt(outputImg, kOfxImagePropRowBytes, 0, &dstRowBytes);
    gPropHost->propGetIntN(outputImg, kOfxImagePropBounds, 4, &dstRect.x1);
    gPropHost->propGetInt(outputImg, kOfxImagePropRowBytes, 0, &dstRowBytes);
    gPropHost->propGetPointer(outputImg, kOfxImagePropData, 0, &dstPtr);
      
    // fetch main input clip
    OfxImageClipHandle sourceClip;
    gEffectHost->clipGetHandle(instance, kOfxImageEffectSimpleSourceClipName, &sourceClip, 0);
      
    // fetch image at render time from that clip
    if (gEffectHost->clipGetImage(sourceClip, time, NULL, &sourceImg) != kOfxStatOK) {
      throw NoImageEx();
    }
      
    // fetch image info out of that handle
    int srcRowBytes;
    OfxRectI srcRect;
    void *srcPtr;
    gPropHost->propGetInt(sourceImg, kOfxImagePropRowBytes, 0, &srcRowBytes);
    gPropHost->propGetIntN(sourceImg, kOfxImagePropBounds, 4, &srcRect.x1);
    gPropHost->propGetInt(sourceImg, kOfxImagePropRowBytes, 0, &srcRowBytes);
    gPropHost->propGetPointer(sourceImg, kOfxImagePropData, 0, &srcPtr);

    // cast data pointers to 8 bit RGBA
    OfxRGBAColourB *src = (OfxRGBAColourB *) srcPtr;
    OfxRGBAColourB *dst = (OfxRGBAColourB *) dstPtr;

    // and do some inverting
    for(int y = renderWindow.y1; y < renderWindow.y2; y++) {
      if(gEffectHost->abort(instance)) break;

      OfxRGBAColourB *dstPix = pixelAddress(dst, dstRect, renderWindow.x1, y, dstRowBytes);

      for(int x = renderWindow.x1; x < renderWindow.x2; x++) {
        
        OfxRGBAColourB *srcPix = pixelAddress(src, srcRect, x, y, srcRowBytes);

        if(srcPix) {
          dstPix->r = 255 - srcPix->r;
          dstPix->g = 255 - srcPix->g;
          dstPix->b = 255 - srcPix->b;
          dstPix->a = 255 - srcPix->a;
        }
        else {
          dstPix->r = 0;
          dstPix->g = 0;
          dstPix->b = 0;
          dstPix->a = 0;
        }
        dstPix++;
      }
    }

    // we are finished with the source images so release them
  }
  catch(NoImageEx &) {
    // if we were interrupted, the failed fetch is fine, just return kOfxStatOK
    // otherwise, something wierd happened
    if(!gEffectHost->abort(instance)) {
      status = kOfxStatFailed;
    }      
  }

  if(sourceImg)
    gEffectHost->clipReleaseImage(sourceImg);
  if(outputImg)
    gEffectHost->clipReleaseImage(outputImg);
  
  // all was well
  return status;
}