@Override
    public void decodeImage() throws IOException {
        try {
            int bytesRead = 0;
            // Read from the input stream
            for (;;) {
                bytesRead = inputStream.read(buffer, 0, buffer_size);

                if (bytesRead < 0) {
                    // Break, nothing to read from buffer, image truncated?
                    releaseNativeDecoder(hNativeDecoder);
                    break;
                }

                hNativeDecoder = decode(buffer, bytesRead, hNativeDecoder);

                returnData();

                // OK, we decoded all the picture in the right way...
                if (hNativeDecoder == 0) {
                    break;
                }
            }

            imageComplete(ImageConsumer.STATICIMAGEDONE);
        } catch (IOException e) {
            throw e;
        } catch (RuntimeException e) {
            imageComplete(ImageConsumer.IMAGEERROR);
            throw e;
        } finally {
            closeStream();
        }
    }