From 963588b2e1344ec1a8a98ec043a0454474f478ed Mon Sep 17 00:00:00 2001 From: Elian Dib <elian.di@laposte.net> Date: Mon, 8 Jun 2020 03:18:56 +0200 Subject: [PATCH] Added fullRange parameter in convert, write and read --- convert.m | 6 ++++-- read.m | 6 +++++- write.m | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/convert.m b/convert.m index 902125f..9742e31 100644 --- a/convert.m +++ b/convert.m @@ -8,18 +8,20 @@ p = inputParser; p.StructExpand = true; p.KeepUnmatched = true; p.addOptional('outColSpace' , 'ycbcr' , @ischar); p.addOptional( 'inColSpace' , 'rgb' , @ischar); p.addOptional( 'bitDepth' , bitDepth , @isnumeric); +p.addOptional( 'fullRange' , true , @islogical); p.parse(varargin{:}); inColSpace = p.Results.inColSpace; outColSpace = p.Results.outColSpace; bitDepth = p.Results.bitDepth; +fullRange = p.Results.fullRange; switch ndims(frames{1}) case 3 if (strcmp(inColSpace,'rgb') && strcmp(outColSpace,'ycbcr')) - frames = cellfun(@(f) utils.rgb2ycbcr(f,bitDepth),frames,'UniformOutput',false); + frames = cellfun(@(f) utils.rgb2ycbcr(f,bitDepth,fullRange),frames,'UniformOutput',false); elseif (strcmp(inColSpace,'ycbcr') && strcmp(outColSpace,'rgb')) - frames = cellfun(@(f) utils.ycbcr2rgb(f,bitDepth),frames,'UniformOutput',false); + frames = cellfun(@(f) utils.ycbcr2rgb(f,bitDepth,fullRange),frames,'UniformOutput',false); end case 2 warning('Monochrome image, no conversion'); diff --git a/read.m b/read.m index 6ba48f4..25800fb 100644 --- a/read.m +++ b/read.m @@ -48,13 +48,17 @@ else bitDepth = p.Results.bitDepth; end +fullRange = true; + p.addParameter( 'inColSpace', 'rgb' , @ischar); p.addParameter('outColSpace', 'ycbcr', @ischar); +p.addParameter('fullRange', fullRange , @islogical); p.parse(varargin{:}); inColSpace = p.Results.inColSpace; outColSpace = p.Results.outColSpace; +fullRange = p.Results.fullRange; precision = ['uint',num2str(max(8,2^ceil(log2(bitDepth))))]; @@ -103,7 +107,7 @@ fclose(fileID); %% Perform color space transform if ~strcmp(subSamp,'400') - frames = yuv.convert(frames,inColSpace,outColSpace,bitDepth); + frames = yuv.convert(frames,inColSpace,outColSpace,bitDepth,fullRange); end %% Reshape frames diff --git a/write.m b/write.m index db113db..08581ff 100644 --- a/write.m +++ b/write.m @@ -13,6 +13,7 @@ imgSize = size(frames{1}); imgSize(end+1:3) = 1; imgRes = size(frames); precision = class(frames{1}); [~,bitDepth] = utils.precision(precision); +fullRange = true; switch imgSize(3); case 1; subSamp = '400'; case 3; subSamp = '444'; end @@ -20,6 +21,7 @@ p = inputParser; p.StructExpand = true; p.KeepUnmatched = true; p.addParameter('filename' , filename, @ischar); p.addParameter('subSamp' , subSamp , @ischar); p.addParameter('bitDepth' , bitDepth, @isnumeric); +p.addParameter('fullRange' , fullRange, @islogical); p.addParameter( 'inColSpace', 'rgb' , @ischar); p.addParameter('outColSpace', 'ycbcr' , @ischar); @@ -32,6 +34,7 @@ params = p.Results; filename = params.filename; subSamp = params.subSamp; bitDepth = p.Results.bitDepth; +fullRange = p.Results.fullRange; inColSpace = p.Results.inColSpace; outColSpace = p.Results.outColSpace; @@ -59,7 +62,7 @@ end %% Perform color space transform if ~strcmp(subSamp,'400') - frames = yuv.convert(frames,outColSpace,inColSpace,bitDepth); + frames = yuv.convert(frames,outColSpace,inColSpace,bitDepth,fullRange); end %% YUV 420/422: define interpolation sampling grids -- GitLab