function [X,map] = readgif(filename, varargin)
%READGIF Read an image from a GIF file.
%   [X,MAP] = READGIF(FILENAME) reads the image from the
%   specified file.
%
%   See also IMREAD, IMWRITE, IMFINFO.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.3 $  $Date: 2000/06/01 04:17:17 $

if (nargin < 1)
    error('Too few inputs.');
end

% do the reading in Java
g = com.mathworks.util.GIFObject(filename);

% Import the data from the Java object.  The "byte" data is returned as
% INT8 and needs the negative values to be augmented appropriately.
data = double(g.getPixels);
data(data < 0) = data(data < 0) + 256;
X = uint8(data);

X = reshape(X,g.getWidth,g.getHeight)';
map = double(g.getColorMap)./255;
