001    /*
002     * MemoryGray8Image
003     *
004     * Copyright (c) 2002 Marco Schmidt.
005     * All rights reserved.
006     */
007    
008    package net.sourceforge.jiu.data;
009    
010    import net.sourceforge.jiu.data.Gray8Image;
011    import net.sourceforge.jiu.data.MemoryByteChannelImage;
012    import net.sourceforge.jiu.data.PixelImage;
013    
014    /**
015     * An implementation of {@link Gray8Image} that keeps the complete image in memory.
016     * This class inherits most of its functionality from its parent class
017     * {@link MemoryByteChannelImage}, using one byte channel.
018     *
019     * @author Marco Schmidt
020     */
021    public class MemoryGray8Image extends MemoryByteChannelImage implements Gray8Image
022    {
023            /**
024             * Creates a new MemoryGray8Image object with the specified resolution.
025             * Simply gives <code>1</code> (for one channel) and the two resolution arguments
026             * to the super constructor (of the parent class {@link MemoryByteChannelImage}).
027             * @param width the horizontal resolution, must be non-zero and positive
028             * @param height the vertical resolution, must be non-zero and positive
029             */
030            public MemoryGray8Image(int width, int height)
031            {
032                    super(1, width, height);
033            }
034    
035            public PixelImage createCompatibleImage(int width, int height)
036            {
037                    return new MemoryGray8Image(width, height);
038            }
039    
040            public Class getImageType()
041            {
042                    return Gray8Image.class;
043            }
044    
045            public boolean isBlack(int x, int y)
046            {
047                    return getByteSample(x, y) == 0;
048            }
049    
050            public boolean isWhite(int x, int y)
051            {
052                    return getByteSample(x, y) == (byte)255;
053            }
054    
055            public void putBlack(int x, int y)
056            {
057                    putSample(x, y, 0);
058            }
059    
060            public void putWhite(int x, int y)
061            {
062                    putSample(x, y, 255);
063            }
064    }