File: BitsPlusPackMonoImage.m

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (42 lines) | stat: -rw-r--r-- 1,796 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [theColorImage,reconNewWay,reconOldWay] = BitsPlusPackMonoImage(theMonoImage)
% [theColorImage,reconNewWay,reconOldWay] = BitsPlusPackMonoImage(theMonoImage)
%
% In Mono++ mode, the Bits++ box uses the red and green
% channels to provide 14-bits per pixel true intensity
% resolution.  The blue channel is set to 0 to let the
% monochromatic image through.   Empirically, we concluded
% that the packing is left adjusted.  That is, the 8 MSB
% of the 14-bit input go into the red channel, and the 
% 6 LSB get left aligned in the green channel, with
% the remaining two bits set to 0.
%
% This routine packs the bits properly for this function.
%
% 11/17/03  dhb, ip	Wrote it.
% 8/13/04	dhb		Fix bug, the data were not packed quite right.
% 2/26/07   mk      Bugfix for LSB conversion: Added modulo operation.
% 3/01/07   mk      Bugfix for MSB conversion: Added floor operation.
% 3/04/07   dhb     Modified to return some debugging information and
%                   compare original with recent version.

[m,n] = size(theMonoImage);
theColorImage = uint8(zeros(m,n,3));

% Red channel gets high 8 bits
theColorImage(:,:,1) = uint8(floor(theMonoImage/256));

% Green channel gets low 6 bits, left justified
theColorImage(:,:,2) = uint8(mod(theMonoImage, 256));

% Optionally create debug images for testing:
if nargout > 1
    % This is the code from the original OS 9 version.  Buggy?
    oldRed = uint8(bitshift(theMonoImage,-6));
    oldGreen = uint8(bitshift(theMonoImage,2));

    % Reconstruct input vales from the two bytes produced for the packing
    reconNewWay = double(theColorImage(:,:,1))*256+double(theColorImage(:,:,2));
    reconNewWay = bitshift(reconNewWay,-2);
    reconOldWay = double(oldRed)*256+double(oldGreen);
    reconOldWay = bitshift(reconOldWay,-2);
end