/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A class wrapping a buffer and its state. For efficiency,
* the members are made visible to other classes in this package.
*/
class JPEGBuffer {
private boolean debug = false;
/**
* The size of the buffer. This is large enough to hold all
* known marker segments (other than thumbnails and icc profiles)
*/
/**
* The actual buffer.
*/
byte [] buf;
/**
* The number of bytes available for reading from the buffer.
* Anytime data is read from the buffer, this should be updated.
*/
int bufAvail;
/**
* A pointer to the next available byte in the buffer. This is
* used to read data from the buffer and must be updated to
* move through the buffer.
*/
int bufPtr;
/**
* The ImageInputStream buffered.
*/
buf = new byte[BUFFER_SIZE];
bufAvail = 0;
bufPtr = 0;
}
/**
* Ensures that there are at least <code>count</code> bytes available
* in the buffer, loading more data and moving any remaining
* bytes to the front. A count of 0 means to just fill the buffer.
* If the count is larger than the buffer size, just fills the buffer.
* If the end of the stream is encountered before a non-0 count can
* be satisfied, an <code>IIOException</code> is thrown with the
* message "Image Format Error".
*/
if (debug) {
}
if (count != 0) {
return;
}
} else {
return;
}
}
// First copy any remaining bytes down to the beginning
}
// Now fill the rest of the buffer
if (debug) {
}
if (ret != -1) {
}
bufPtr = 0;
throw new IIOException ("Image Format Error");
}
}
/**
* Fills the data array from the stream, starting with
* the buffer and then reading directly from the stream
* if necessary. The buffer is left in an appropriate
* state. If the end of the stream is encountered, an
* <code>IIOException</code> is thrown with the
* message "Image Format Error".
*/
// First see what's left in the buffer.
return;
}
int offset = 0;
bufAvail = 0;
bufPtr = 0;
}
// Now read the rest directly from the stream
throw new IIOException ("Image format Error");
}
}
/**
* Skips <code>count</code> bytes, leaving the buffer
* in an appropriate state. If the end of the stream is
* encountered, an <code>IIOException</code> is thrown with the
* message "Image Format Error".
*/
// First see what's left in the buffer.
return;
}
bufAvail = 0;
bufPtr = 0;
}
// Now read the rest directly from the stream
throw new IIOException ("Image format Error");
}
}
/**
* Push back the remaining contents of the buffer by
* repositioning the input stream.
*/
bufAvail = 0;
bufPtr = 0;
}
/**
* Return the stream position corresponding to the next
* available byte in the buffer.
*/
}
/**
* Scan the buffer until the next 0xff byte, reloading
* the buffer as necessary. The buffer position is left
* pointing to the first non-0xff byte after a run of
* 0xff bytes. If the end of the stream is encountered,
* an EOI marker is inserted into the buffer and <code>true</code>
* is returned. Otherwise returns <code>false</code>.
*/
boolean retval = false;
boolean foundFF = false;
while (foundFF == false) {
while (bufAvail > 0) {
bufAvail--;
foundFF = true;
break; // out of inner while
}
bufAvail--;
}
// Reload the buffer and keep going
loadBuf(0);
// Skip any remaining pad bytes
if (foundFF == true) {
bufPtr++; // Only if it still is 0xff
bufAvail--;
}
}
// send out a warning, but treat it as EOI
//reader.warningOccurred(JPEGImageReader.WARNING_NO_EOI);
retval = true;
bufAvail = 1;
bufPtr = 0;
foundFF = true;
}
}
return retval;
}
/**
* Prints the contents of the buffer, in hex.
* @param count the number of bytes to print,
* starting at the current available byte.
*/
}
}
}
}