Skip to content

Commit 69d2084

Browse files
examples: convert: Add support for RGBX output from 2712C1
By doubling the width, changing the output format to "UYVY" and applying a matrix to swap the first two colour components, we can output RGBX. The gotcha is that when downscaling, this can result in an oversharp/aliasy image. No support for RGBX input (though that would theoretically be possible at unity scale, using a customized Resample kernel). Signed-off-by: Nick Hollinghurst <[email protected]>
1 parent d23a3c3 commit 69d2084

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

src/examples/convert.cpp

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,9 @@ int main(int argc, char *argv[])
293293
global.bayer_enables = 0;
294294
global.rgb_enables = PISP_BE_RGB_ENABLE_INPUT + PISP_BE_RGB_ENABLE_OUTPUT0;
295295

296-
if ((in_file.format == "RGBX8888" || out_file.format == "RGBX8888") && !variant->BackendRGB32Supported(0))
296+
if (in_file.format == "RGBX8888" && !variant->BackendRGB32Supported(0))
297297
{
298-
std::cerr << "Backend hardware does not support RGBX formats" << std::endl;
298+
std::cerr << "Backend hardware does not support RGBX input" << std::endl;
299299
exit(-1);
300300
}
301301
pisp_image_format_config i = {};
@@ -307,9 +307,32 @@ int main(int argc, char *argv[])
307307
be.SetInputFormat(i);
308308

309309
pisp_be_output_format_config o = {};
310-
o.image.width = out_file.width;
311-
o.image.height = out_file.height;
312-
o.image.format = libpisp::get_pisp_image_format(out_file.format);
310+
if (out_file.format == "RGBX8888" && !variant->BackendRGB32Supported(0))
311+
{
312+
// Hack to generate RGBX even when BE_MINOR_VERSION < 1 using Resample
313+
if (out_file.width < i.width)
314+
std::cerr << "Backend hardware has limited RGBX support; resize artifacts may be present" << std::endl;
315+
316+
o.image.width = out_file.width * 2 - 1;
317+
o.image.height = out_file.height;
318+
o.image.format = libpisp::get_pisp_image_format("UYVY");
319+
320+
pisp_be_ccm_config csc = {}; // Define a matrix to swap components [0] and [1]
321+
csc.coeffs[1] = 1024;
322+
csc.coeffs[3] = 1024;
323+
csc.coeffs[8] = 1024;
324+
csc.offsets[0] = 131072; // round to nearest after Resample, for 8-bit output
325+
csc.offsets[1] = 131072;
326+
csc.offsets[2] = 131072;
327+
be.SetCsc(0, csc);
328+
global.rgb_enables |= PISP_BE_RGB_ENABLE_CSC0;
329+
}
330+
else
331+
{
332+
o.image.width = out_file.width;
333+
o.image.height = out_file.height;
334+
o.image.format = libpisp::get_pisp_image_format(out_file.format);
335+
}
313336
assert(o.image.format);
314337
libpisp::compute_optimal_stride(o.image, true);
315338
be.SetOutputFormat(0, o);

0 commit comments

Comments
 (0)