1
//========================================================================
5
// A JPX stream decoder using OpenJPEG
7
// Copyright 2008, 2010 Albert Astals Cid <aacid@kde.org>
9
// Licensed under GPLv2 or later
11
//========================================================================
14
#ifndef JPEG2000STREAM_H
15
#define JPEG2000STREAM_H
19
#include "goo/gtypes.h"
23
class JPXStream: public FilterStream {
26
JPXStream(Stream *strA);
28
virtual StreamKind getKind() { return strJPX; }
32
virtual int getChar();
33
virtual int lookChar();
34
virtual GooString *getPSFilter(int psLevel, char *indent);
35
virtual GBool isBinary(GBool last = gTrue);
36
virtual void getImageParams(int *bitsPerComponent, StreamColorSpaceMode *csMode);
40
void init2(unsigned char *buf, int bufLen, OPJ_CODEC_FORMAT format);
42
virtual GBool hasGetChars() { return true; }
43
virtual int getChars(int nChars, Guchar *buffer);
45
inline int doGetChar() {
46
int result = doLookChar();
51
inline int doLookChar() {
52
if (inited == gFalse) init();
54
if (!image) return EOF;
56
int w = image->comps[0].w;
57
int h = image->comps[0].h;
59
int y = (counter / image->numcomps) / w;
60
int x = (counter / image->numcomps) % w;
61
if (y >= h) return EOF;
63
int component = counter % image->numcomps;
66
if (image->comps[component].prec > 8) {
67
adjust = image->comps[component].prec - 8;
70
if (unlikely(image->comps[component].data == NULL)) return EOF;
72
int r = image->comps[component].data[y * w + x];
73
r += (image->comps[component].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
75
unsigned char rc = (unsigned char) ((r >> adjust)+((r >> (adjust-1))%2));