Skip to content

Commit

Permalink
Add CVPixelBuffer support to visualize command
Browse files Browse the repository at this point in the history
Summary: I often run this three-liner to `visualize` a `CVPixelBuffer` so figured we could save some time by building it into the `visualize` command.

Differential Revision: D22653607

fbshipit-source-id: bf03acb4e091b8c93b7e1c73ea8b065755c706ad
  • Loading branch information
Chris Ellsworth authored and facebook-github-bot committed Jul 22, 2020
1 parent 5e64f4e commit 7c97beb
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion commands/FBVisualizationCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ def _showLayer(layer):
fb.evaluateEffect("UIGraphicsEndImageContext()")


def _showPixelBuffer(target):
fb.evaluateExpression("CGImageRef $imageOut = NULL")
fb.evaluateExpression("(OSStatus)VTCreateCGImageFromCVPixelBuffer(" + target + ", NULL, &$imageOut)")
image = fb.evaluateExpression("[UIImage imageWithCGImage:$imageOut]")
_showImage(image)
fb.evaluateExpression("CGImageRelease($imageOut)")


def _dataIsImage(data):
data = "(" + data + ")"

Expand Down Expand Up @@ -181,6 +189,12 @@ def _visualize(target):
+ ") == (unsigned long)CGImageGetTypeID()"
):
_showImage("(id)[UIImage imageWithCGImage:" + target + "]")
elif fb.evaluateBooleanExpression(
"(unsigned long)CFGetTypeID((CFTypeRef)"
+ target
+ ") == (unsigned long)CVPixelBufferGetTypeID()"
):
_showPixelBuffer(target)
else:
if objectHelpers.isKindOfClass(target, "UIImage"):
_showImage(target)
Expand Down Expand Up @@ -219,7 +233,7 @@ def name(self):

def description(self):
return (
"Open a UIImage, CGImageRef, UIView, or CALayer in Preview.app on your Mac."
"Open a UIImage, CGImageRef, UIView, CALayer, or CVPixelBuffer in Preview.app on your Mac."
)

def args(self):
Expand Down

0 comments on commit 7c97beb

Please sign in to comment.