Skip to content

Commit

Permalink
improved speed by not converting to a cell array of strings but doing…
Browse files Browse the repository at this point in the history
… all operations on string arrays
  • Loading branch information
deichrenner committed Mar 10, 2016
1 parent d31edd7 commit 0224a0f
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions helperFunctions/prepBMP.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
numOfBytes = dec2hex(typecast(uint32(size(BMP1,1)*size(BMP1,2)*...
bitDepth),'uint8'),2);
backgroundColor = ['00'; '00'; '00'; '00'];
compression = '00';
compression = '02';

header = [signature; imageWidth; imageHeight; numOfBytes; ...
'FF'; 'FF'; 'FF'; 'FF'; 'FF'; 'FF'; 'FF'; 'FF'; backgroundColor; ...
Expand All @@ -28,19 +28,19 @@
BMP1 = BMP1'*1;

% expand to 24bit in 3x8bit decimal notation
BMP24 = cellstr(dec2hex(BMP1(:),6));
BMP24 = dec2hex(BMP1(:),6);

% clear return variable
data = '';

% % compress if whished
if strcmp(compression, '02')
% reshape in order to get 24bit pixel information line by line
BMP24 = reshape(BMP24, size(BMP1,1), [])';
for i = 1:size(BMP24,1)
[~, ~, ic] = unique(BMP24(i,:));
ind = find(diff([ic(1)-1, ic(:)']));
relMat = [formatRep(diff([ind, numel(BMP24(i,:))+1])), cell2mat(BMP24(i,ind)')];
[szy, szx] = size(BMP1);
for i = 1:szx
[~, ~, ic] = unique(BMP24((i-1)*szy+1:i*szy,:), 'rows');
ind = find(diff([ic(1)-1, ic(:)']))+(i-1)*szy;
relMat = [formatRep(diff([ind, i*szy+1])), BMP24(ind,:)];
data = [data sprintf(relMat(:,:)')];
end
% put together header, compressed data and end of image padding
Expand Down

0 comments on commit 0224a0f

Please # to comment.