exImage.cpp
Convert and save a grayscale image. Load the Vision cover, convert its GPU-resident RGB pixels to Rec.709 grayscale, save the semantic Gray image, and optionally inspect it in Viewer.
Source
Example
1#include <oa/oa.h>23OA_MAIN_PREVIEW("ExampleVisionImage") {4 auto sourceResult = oa::FnImage::decodeFile(5 oa::Paths::asset("image/coverVision.jpg"), oa::ImageFormat::Rgb);6 if (not sourceResult.isOk()) return 1;7 auto source = oa::move(sourceResult).getValue();89 auto grayscale = oa::FnImage::grayscale(source);1011 const oa::Path output = oa::Paths::var("example/vision/coverVisionGrayscale.jpg");12 if (not oa::Filesystem::createDirectories(output.parentPath()).isOk()) return 1;13 if (not oa::FnImage::saveFile(output, grayscale, 92U).isOk()) return 1;1415 if (not grayscale.validate()) return 1;16 if (grayscale.width() != 1672 or grayscale.height() != 941) return 1;17 if (grayscale.format() != oa::ImageFormat::Gray) return 1;18 if (not oa::Filesystem::isFile(output)) return 1;1920 oa::print("Saved grayscale image: {}", output.cStr());2122 if (argc > 1 and oa::StringView(argv[1]) == "--preview") {23 oa::ViewerConfig previewConfig;24 previewConfig.mode = oa::ViewerMode::Image;25 previewConfig.title = "OA vision · grayscale cover";26 previewConfig.width = 1280U;27 previewConfig.height = 646U;28 if (not oa::Viewer::preview(engine, oa::Paths::var("example/vision/coverVisionGrayscale.jpg").string(),29 previewConfig).isOk()) {30 return 1;31 }32 }33 return 0;34}35
Output
Before / after. Compare the checked RGB source with the exact grayscale JPEG written by this example.

source
Vision cover
The full-resolution RGB source decoded through oa::FnImage.

processed
Grayscale output
The full-resolution Rec.709 grayscale image converted on the GPU and saved by the source-owned example.
Present
The Output section above remains the exact artifact evidence. These captures document the current interactive Viewer surface used by the presentation path.

OA Viewer · Presented state
Grayscale preview
The exact grayscale output above recaptured edge to edge in the current Viewer through this example's optional --preview path.