function [M,nbits] = makeBitMask(type,n,q)

% This function will make the type of bitmask described by type for a size
% n x n image matrix, with the number of levels specified (lev).

M = ones(n);
lev = length(q)-1;

% If the quantization is uniform, represent each pixel by 6 bits
switch type
case 'u'
   M = q(1).*M;
   nbits = sum(sum(M));
case 'a'
   % If the quantization is adaptive to the full matrix Haar Transform,
   % use more bits for the blocks in the upper left hand of the matrix.
   ind = n;
   for i = 1:(lev+1)
      M(1:ind,1:ind) = q(lev+2-i).*ones(ind);
      ind = ind/2;
   end
   nbits = sum(sum(M));
case 'b'
   % If the quantization is adaptive to the blocked matrix Haar Transform,
   % use more bits for the upper left hand of each individual block.
   % Each block is assumed to be 8 x 8, like the DCT.
   for i = 1:8:n
      for j = 1:8:n
         ind = 8;
         for k = 1:(lev+1)
            M(i:i+ind-1,j:j+ind-1) = q(lev+2-k).*ones(ind);
            ind = ind/2;
         end
      end
   end
   nbits = sum(sum(M));
otherwise
   disp('Invalid Bit Mask');
end