function s = iccread(filename)
%ICCREAD Read ICC color profile.
% P = ICCREAD(FILENAME) reads the International Color Consortium (ICC)
% color profile data from the file specified by FILENAME. The file can
% be either an ICC profile file or a TIFF file containing an embedded
% ICC profile. ICCREAD returns the profile information in the
% structure P, which can be used by MAKECFORM and APPLYCFORM to compute
% color space transformations. P can also be written to a new
% ICC profile file by ICCWRITE. Both Version 2 and Version 4
% of the ICC specification are supported.
%
% The reference page for ICCREAD has additional information about the
% fields of the structure P. For complete details, see the
% specifications ICC.1:2001-04 for Version 2 and ICC.1:2001-12
% for Version 4.0 or ICC.1:2004-10 for Version 4.2.0.0 (available
% at www.color.org).
%
% Example
% -------
% Read in the sRGB profile.
%
% P = iccread('sRGB.icm');
%
% See also ISICC, ICCWRITE, MAKECFORM, APPLYCFORM.
% Copyright 2002-2015 The MathWorks, Inc.
% Check input argument
validateattributes(filename,{'char'},{'nonempty'},'iccread','FILENAME',1);
% Check to see that FILENAME is actually a file that exists
if exist(filename,'file') ~= 2
% Look in the system's ICC profile repository.
try
repository = iccroot;
catch
repository = '';
end
if (exist(fullfile(repository, filename), 'file'))
filename = fullfile(iccroot, filename);
else
error(message('images:iccread:fileNotFound'))
end
end
if istif(filename)
info = imfinfo(filename);
if ~isfield(info,'ICCProfileOffset')
error(message('images:iccread:noProfileInTiffFile'))
end
start = info.ICCProfileOffset;
elseif isiccprof(filename)
start = 0;
else
error(message('images:iccread:unrecognizedFileType'))
end
% "All profile data must be encoded as big-endian." Clause 6
[fid,msg] = fopen(filename,'r','b');
if (fid < 0)
error(message('images:iccread:errorOpeningProfile', filename, msg));
end
s = iccread_embedded(fid, start);
fclose(fid);
s.Filename = filename;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function tf = isiccprof(filename)
tf = false;
fid = fopen(filename, 'r', 'b');
if (fid < 0)
fclose(fid);
return;
end
[~, count] = fread(fid, 3, 'uint32');
if count ~= 3
fclose(fid);
return;
end
[device_class_code, count] = fread(fid, 4, 'uchar');
if count ~= 4
fclose(fid);
return;
end
valid_device_classes = get_device_classes;
if any(strcmp(char(device_class_code'), valid_device_classes(:, 1)))
tf = true;
end
fclose(fid);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function tf = istif(filename)
fid = fopen(filename, 'r', 'ieee-le');
if (fid < 0)
tf = false;
else
sig = fread(fid, 4, 'uint8');
fclose(fid);
tf = isequal(sig, [73; 73; 42; 0]) | isequal(sig, [77; 77; 0; 42]);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function s = iccread_embedded(fid, start)
% ICCREAD_EMBEDDED(FID, START) reads ICC profile data using the file
% identifier FID, starting at byte offset location START, as measured
% from the beginning of the file.
fseek_check(fid, start, 'bof');
s.Header = read_header(fid);
version = sscanf(s.Header.Version(1), '%d%');
% Skip past header -- 128 bytes (Clause 6.1)
fseek_check(fid, start + 128, 'bof'); % Use fixed length of header
% Read the Tag Table
tag_count = fread_check(fid, 1, 'uint32');
tag_table = cell(tag_count,3);
for k = 1:tag_count
tag_table{k,1} = char(fread_check(fid, 4, '*uint8'))';
tag_table{k,2} = fread_check(fid, 1, 'uint32');
tag_table{k,3} = fread_check(fid, 1, 'uint32');
end
s.TagTable = tag_table;
% Build up a list of defined public tags
public_tagnames = get_public_tagnames(version);
mattrc_tagnames = get_mattrc_tagnames(version);
private_tags = cell(0,0);
has_mattrc = false;
% Go through each tag in the tag table
for k = 1:size(s.TagTable,1)
signature = deblank(s.TagTable{k,1});
offset = s.TagTable{k,2};
data_size = s.TagTable{k,3};
pub_idx = strmatch(signature,public_tagnames,'exact');
mattrc_idx = strmatch(signature,mattrc_tagnames,'exact');
% Check to see if the tag is public, a mattrc tag, or private
if ~isempty(pub_idx)
% A public tag is found
tagname = public_tagnames{pub_idx, 2};
s.(tagname) = get_public_tag(fid, signature, offset + start, ...
data_size, version, s.Header.ConnectionSpace, tagname);
elseif ~isempty(mattrc_idx)
% A Mattrc element is found... and the MatTRC struct will
% now be generated or appended.
has_mattrc = true;
tagname = mattrc_tagnames{mattrc_idx, 2};
MatTRC.(tagname) = get_public_tag(fid, signature, offset + start, ...
data_size, version, s.Header.ConnectionSpace, tagname);
else
% The tag is a private tag
data = get_private_tag(fid,offset+start,data_size);
current_row = size(private_tags,1)+1;
private_tags{current_row,1} = signature;
private_tags{current_row,2} = data;
end
end
% Generate the MatTRC field
if has_mattrc
s.MatTRC = MatTRC;
end
% Populate the private tags
s.PrivateTags = private_tags;
% Verify the checksum if present and nonzero.
if isfield(s.Header, 'ProfileID') && any(s.Header.ProfileID)
fseek_check(fid, start, 'bof');
bytes = fread_check(fid, s.Header.Size, '*uint8');
% See clause 6.1.13. The checksum is computed after setting bytes
% 44-47 (indexed from 0), 64-67, and 84-99 to 0.
bytes([45:48 65:68 85:100]) = 0;
digest = compute_md5(bytes);
if ~isequal(digest, s.Header.ProfileID)
warning(message('images:iccread:badChecksum'));
end
end
%------------------------------------------
function header = read_header(fid)
% Clause 6.1.1 - Profile size
header.Size = fread_check(fid, 1, 'uint32');
% Clause 6.1.2 - CMM Type
header.CMMType = char(fread_check(fid, 4, 'uint8'))';
% Clause 6.1.3 - Profile Version
% Byte 0: Major Revision in BCD
% Byte 1: Minor Revision & Bug Fix Revision in each nibble in BCD
% Byte 2: Reserved; expected to be 0
% Byte 3: Reserved; expected to be 0
version_bytes = fread_check(fid, 4, 'uint8');
major_version = version_bytes(1);
% Minor version and bug fix version are in the two nibbles
% of the second version byte.
minor_version = bitshift(version_bytes(2), -4);
bugfix_version = bitand(version_bytes(2), 15);
header.Version = sprintf('%d.%d.%d', major_version, minor_version, ...
bugfix_version);
% Clause 6.1.4 - Profile/Device Class signature
% Profile/Device Class Signature
% ------------ ---------
% Input Device profile 'scnr'
% Display Device profile 'mntr'
% Output Device profile 'prtr'
% DeviceLink profile 'link'
% ColorSpace Conversion profile 'spac'
% Abstract profile 'abst'
% Named Color profile 'nmcl'
device_classes = get_device_classes(major_version);
device_class_char = char(fread_check(fid, 4, '*uint8'))';
idx = strmatch(device_class_char, device_classes(:, 1), 'exact');
if isempty(idx)
fclose(fid);
error(message('images:iccread:invalidProfileClass'))
end
header.DeviceClass = device_classes{idx, 2};
% Clause 6.1.5 - Color Space signature
% Four-byte string, although some signatures have a blank
% space at the end. Translate into more readable string.
colorspaces = get_colorspaces(major_version);
signature = char(fread_check(fid, 4, '*uint8'))';
idx = strmatch(signature, colorspaces(:, 1), 'exact');
if isempty(idx)
fclose(fid);
error(message('images:iccread:invalidColorSpaceSignature'));
else
header.ColorSpace = colorspaces{idx, 2};
end
% Clause 6.1.6 - Profile connection space signature
% E
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
colorspace.zip (119个子文件)
colorspace.html 22KB
swopcmyk.icm 492KB
sRGB.icm 3KB
colorspace_01.jpg 13KB
colorspace_03.jpg 12KB
colorspace_02.jpg 8KB
iccread.m 53KB
iccwrite.m 49KB
makecform.m 39KB
ColorConverter.m 24KB
applyclut.m 14KB
colorspace.m 14KB
lab2rgb.m 8KB
rgb2lab.m 8KB
encode_color.m 8KB
colorspace_demo.m 6KB
ycbcr2rgb.m 6KB
rgb2ycbcr.m 6KB
applycform.m 6KB
applyparametric.m 5KB
Deque.m 5KB
rgb2ycbcr.m 5KB
isicc.m 5KB
ColorEncoder.m 4KB
ycbcr2rgb.m 4KB
applycurve.m 4KB
lab2rgb.m 3KB
toColumns.m 3KB
xyz2rgb.m 3KB
rgb2lab.m 3KB
iccProfileCache.m 3KB
rgb2xyz.m 3KB
ntsc2rgb.m 3KB
xyzToAdobeRGBConverter.m 3KB
adobeRGBToXYZConverter.m 3KB
xyzToSRGBConverter.m 3KB
rgb2ntsc.m 2KB
get_public_tagnames.m 2KB
iccfind.m 2KB
sRGBToXYZConverter.m 2KB
Contents.m 2KB
whitepoint.m 2KB
lab2double.m 2KB
lab2uint16.m 2KB
lab2uint8.m 2KB
ICCLab2Encoder.m 2KB
iccroot.m 2KB
XYZChromaticAdaptationTransform.m 2KB
rgb2ycbcr.m 2KB
xyz2lab.m 2KB
lab2xyz.m 2KB
applyblackpoint.m 2KB
Scalar.m 2KB
ycbcr2rgb.m 2KB
get_technologies.m 2KB
checkSequence.m 2KB
get_colorspaces.m 2KB
colorspace_ciedemo.m 2KB
xyz2double.m 2KB
xyz2uint16.m 2KB
applynamedcolor.m 2KB
xyz2lab.m 2KB
applygraytrc_inv.m 2KB
applygraytrc_fwd.m 2KB
GenericColorEncoder.m 1KB
lab2xyz.m 1KB
luttagchans.m 1KB
linearRGBToXYZTransform.m 1KB
get_mattrc_tagnames.m 1KB
sRGBLinearEncoder.m 1KB
applymattrc_inv.m 1KB
XYZToLAB.m 1KB
getConversionParameters.m 1KB
decodeRGB.m 1KB
applymattrc_fwd.m 1KB
unencodedXYZToLAB.m 1KB
xyzToLABConverter.m 1KB
labToXYZConverter.m 1KB
checkWhitePoint.m 1KB
LABToXYZ.m 1KB
xyz2upvpl.m 1KB
xyz2uvl.m 1KB
get_device_classes.m 1KB
encodeRGB.m 1KB
linearizeSRGB.m 1KB
unencodedLABToXYZ.m 1KB
delinearizeSRGB.m 1KB
XYZEncoder.m 1KB
parametricCurveA.m 994B
applychad.m 972B
upvpl2xyz.m 925B
applyabsolute.m 889B
uvl2xyz.m 884B
adaptXYZ.m 882B
test_main.m 879B
compute_md5.m 857B
xyl2xyz.m 846B
checkColorSpaceString.m 831B
xyz2xyl.m 819B
lch2lab.m 793B
共 119 条
- 1
- 2
Carifee.
- 粉丝: 1w+
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论5