This repository has been archived by the owner. It is now read-only.
Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ImageIO/utils/lsmClasses/@LSMLookupTable/LSMLookupTable.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
112 lines (106 sloc)
5 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
classdef LSMLookupTable | |
%LSMLOOKUPTABLE Class representation of a LookupTable in LSM files | |
% | |
% AUTHOR: Stefano Masneri | |
% Date: 14.3.2017 | |
properties | |
size; | |
numberSubBlocks; % Number of sub blocks (without the List End Marker sub block) | |
numberChannels; % Number of channels handled in the description block. | |
% For the color palette it must be 3 and for the input | |
% lookup table it must be the number of data channels. | |
lutType; % Most recently selected type of the LUT. | |
% LUT_NORMAL = 0 LUT generated by the brightness and contrast properties. | |
% LUT_ORIGINAL = 1 LUT generated by 12 bit to 12 bit LUT and the | |
% brightness and contrast properties. | |
% LUT_RAMP = 2 LUT generated by a ramp defined by start and | |
% end point, the brightness and the contrast properties. | |
% LUT_POLYLINE = 3 LUT generated by multiple lines, the | |
% brightness and the contrast properties. | |
% LUT_SPLINE = 4 LUT generated by a cubic spline curve, | |
% the brightness and the contrast properties. | |
% LUT_GAMMA = 5 LUT generated by an exponential function, | |
% the brightness and the contrast properties (Not used in case of color palette). | |
advanced; % This flag is used for the input LUT and is unequal zero if the "More/Simple" | |
% button in the "Brightness and Contrast" dialog was pressed. | |
currentChannel; % Zero based number of the channel that was most recently | |
% selected for modifications in the LUT editor. | |
% A value of -1 means all channels were selected. | |
%subblocks. Each one is a structure, empty if not specified. | |
gamma; | |
brightness; | |
contrast; | |
ramp; | |
knots; | |
palette12To12; | |
end | |
properties (Constant = true) | |
SUBBLOCK_GAMMA = 1; | |
SUBBLOCK_BRIGHTNESS = 2; | |
SUBBLOCK_CONTRAST = 3; | |
SUBBLOCK_RAMP = 4; | |
SUBBLOCK_KNOTS = 5; | |
SUBBLOCK_PALETTE_12_TO_12 = 6; | |
SUBBLOCK_LIST_END = 0; | |
end | |
methods | |
function obj = LSMLookupTable(lsmPtr, byteOrder) | |
%LSMLOOKUPTABLE Constructor | |
% Assumes the file pointer in the correct position already | |
% PLEASE NOTE That the file format specification declares that the data | |
% for the case RAMP and KNOTS is float64, while actually it is stored | |
% as uint32!!! | |
obj.size = fread(lsmPtr, 1, 'uint32', byteOrder); | |
obj.numberSubBlocks = fread(lsmPtr, 1, 'uint32', byteOrder); | |
obj.numberChannels = fread(lsmPtr, 1, 'uint32', byteOrder); | |
obj.lutType = fread(lsmPtr, 1, 'uint32', byteOrder); | |
obj.advanced = fread(lsmPtr, 1, 'uint32', byteOrder); | |
obj.currentChannel = fread(lsmPtr, 1, 'uint32', byteOrder); | |
reserved = fread(lsmPtr, 9, 'uint32', byteOrder); | |
if any(reserved) | |
error('LSMLookupTable: Error parsing from file') | |
end | |
% now read all the subblocks. Refer to the LSM File format | |
% implementations for details on how the LUT is computed from these | |
% values | |
for k = 1:obj.numberSubBlocks | |
type = fread(lsmPtr, 1, 'uint32', byteOrder); | |
size = fread(lsmPtr, 1, 'uint32', byteOrder) - 8; % -8 bytes for type and size | |
if type == obj.SUBBLOCK_GAMMA | |
sizeToRead = size / 8; % we read doubles! | |
obj.gamma = fread(lsmPtr, sizeToRead, 'double', byteOrder); | |
elseif type == obj.SUBBLOCK_BRIGHTNESS | |
sizeToRead = size / 8; % we read doubles! | |
obj.brightness = fread(lsmPtr, sizeToRead, 'double', byteOrder); | |
elseif type == obj.SUBBLOCK_CONTRAST | |
sizeToRead = size / 8; % we read doubles! | |
obj.contrast = fread(lsmPtr, sizeToRead, 'double', byteOrder); | |
elseif type == obj.SUBBLOCK_RAMP | |
sizeToRead = size / 4; % we read int32! | |
data = fread(lsmPtr, sizeToRead, 'uint32', byteOrder); | |
obj.ramp.startX = data(1:4:end); | |
obj.ramp.startY = data(2:4:end); | |
obj.ramp.endX = data(3:4:end); | |
obj.ramp.endY = data(4:4:end); | |
elseif type == obj.SUBBLOCK_KNOTS | |
sizeToRead = size / 4; % we read int32! | |
obj.knots = fread(lsmPtr, sizeToRead, 'uint32', byteOrder); | |
elseif type == obj.SUBBLOCK_PALETTE_12_TO_12 | |
sizeToRead = size / 2; % here we are using 16 bit integers, not dowubles! | |
data = fread(lsmPtr, sizeToRead, 'int16', byteOrder); | |
numCh = length(data) / 4096; | |
if numCh ~= obj.numberChannels | |
error('LSMLookupTable: Error parsing from file') | |
end | |
obj.palette12To12 = reshape(data, numCh, 4096); | |
else | |
warning('LSMLookupTable: unrecognized subblock type') | |
end | |
end | |
subblockEnd = fread(lsmPtr, 1, 'uint32', byteOrder); | |
if subblockEnd ~= obj.SUBBLOCK_LIST_END | |
error('LSMLookupTable: Error parsing from file') | |
end | |
end | |
end | |
end | |