Beispiel #1
0
  void doProcessing(OfxRectI procWindow)
  {
    PIX *src = (PIX *) srcV;
    PIX *dst = (PIX *) dstV;
    MASK *mask = (MASK *) maskV;

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

      PIX *dstPix = pixelAddress(dst, dstRect, procWindow.x1, y, dstBytesPerLine);

      for(int x = procWindow.x1; x < procWindow.x2; x++) {
        
        PIX *srcPix = pixelAddress(src, srcRect, x, y, srcBytesPerLine);
        
        
        // do any pixel masking?
        float maskV = 1.0f;
        if(mask) {
          MASK *maskPix = pixelAddress(mask, maskRect, x, y, maskBytesPerLine);
          if(maskPix) {
            maskV = float(*maskPix)/float(max);
          }
          else
            maskV = 0.0f;
          maskPix++;
        }

        // figure the scale values per component
        float sR = 1.0 + (rScale - 1.0) * maskV;
        float sG = 1.0 + (gScale - 1.0) * maskV;
        float sB = 1.0 + (bScale - 1.0) * maskV;
        float sA = 1.0 + (aScale - 1.0) * maskV;

        if(srcPix) {
          // switch will be compiled out
          if(isFloat) {
            dstPix->r = srcPix->r * sR;
            dstPix->g = srcPix->g * sG;
            dstPix->b = srcPix->b * sB;
            dstPix->a = srcPix->a * sA;
          }
          else {
            dstPix->r = Clamp(int(srcPix->r * sR), 0, max);
            dstPix->g = Clamp(int(srcPix->g * sG), 0, max);
            dstPix->b = Clamp(int(srcPix->b * sB), 0, max);
            dstPix->a = Clamp(int(srcPix->a * sA), 0, max);
          }
          srcPix++;
        }
        else {
          dstPix->r = dstPix->g = dstPix->b = dstPix->a= 0;
        }
        dstPix++;
      }
    }
  }
Beispiel #2
0
  void doProcessing(OfxRectI procWindow)
  {
    PIX *src = (PIX *) srcV;
    PIX *dst = (PIX *) dstV;
    MASK *mask = (MASK *) maskV;

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

      PIX *dstPix = pixelAddress(dst, dstRect, procWindow.x1, y, dstBytesPerLine);

      for(int x = procWindow.x1; x < procWindow.x2; x++) {
        
        PIX *srcPix = pixelAddress(src, srcRect, x, y, srcBytesPerLine);

        // do any pixel masking?
        float maskV = 1.0f;
        if(mask) {
          MASK *maskPix = pixelAddress(mask, maskRect, x, y, maskBytesPerLine);
          if(maskPix) {
            maskV = float(*maskPix)/float(max);
          }
        }

        // figure the scale values per component
        float theScale = 1.0 + (rScale - 1.0) * maskV;

        if(srcPix) {
          // switch will be compiled out
          if(isFloat) {
            *dstPix = *srcPix * theScale;
          }
          else {
            *dstPix = Clamp(int(*srcPix * theScale), 0, max);
          }
          srcPix++;
        }
        else {
          *dstPix = 0;
        }
        dstPix++;
      }
    }
  }
Beispiel #3
0
  void doProcessing(OfxRectI procWindow)
  {
    SRCPIX *src = (SRCPIX *) srcV;
    DSTPIX *dst = (DSTPIX *) dstV;

    float scaleF;
    scaleF = float(kDstMax)/float(kSrcMax);

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

      DSTPIX *dstPix = pixelAddress(dst, dstRect, procWindow.x1, y, dstBytesPerLine);

      for(int x = procWindow.x1; x < procWindow.x2; x++) {
        
        // if a generator, we have no source
        SRCPIX *srcPix = pixelAddress(src, srcRect, x, y, srcBytesPerLine);        
        
        // change my pixel depths
        if(srcPix) {
          for(int c = 0; c < nComponents; c++) {
            if(dstIsFloat)
              dstPix[c] = srcPix[c] * scaleF;
            else if (srcIsFloat) 
              dstPix[c] = Clamp(srcPix[c] * scaleF, 0, kDstMax);
            else
              dstPix[c] = Clamp(srcPix[c] * kDstMax/kSrcMax, 0, kDstMax);	    
          }
          srcPix += nComponents;
        }
        else {
          for(int c = 0; c < nComponents; c++)
            dstPix[c] = 0;
        }
        dstPix += nComponents;
      }
    }
  }
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;
}
Beispiel #5
0
// 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;
}