~ubuntu-branches/ubuntu/vivid/emscripten/vivid

« back to all changes in this revision

Viewing changes to tests/poppler/poppler/JPEG2000Stream.h

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2013-05-02 13:11:51 UTC
  • Revision ID: package-import@ubuntu.com-20130502131151-q8dvteqr1ef2x7xz
Tags: upstream-1.4.1~20130504~adb56cb
ImportĀ upstreamĀ versionĀ 1.4.1~20130504~adb56cb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//========================================================================
 
2
//
 
3
// JPEG2000Stream.h
 
4
//
 
5
// A JPX stream decoder using OpenJPEG
 
6
//
 
7
// Copyright 2008, 2010 Albert Astals Cid <aacid@kde.org>
 
8
//
 
9
// Licensed under GPLv2 or later
 
10
//
 
11
//========================================================================
 
12
 
 
13
 
 
14
#ifndef JPEG2000STREAM_H
 
15
#define JPEG2000STREAM_H
 
16
 
 
17
#include <openjpeg.h>
 
18
 
 
19
#include "goo/gtypes.h"
 
20
#include "Object.h"
 
21
#include "Stream.h"
 
22
 
 
23
class JPXStream: public FilterStream {
 
24
public:
 
25
 
 
26
  JPXStream(Stream *strA);
 
27
  virtual ~JPXStream();
 
28
  virtual StreamKind getKind() { return strJPX; }
 
29
  virtual void reset();
 
30
  virtual void close();
 
31
  virtual int getPos();
 
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);
 
37
 
 
38
private:
 
39
  void init();
 
40
  void init2(unsigned char *buf, int bufLen, OPJ_CODEC_FORMAT format);
 
41
 
 
42
  virtual GBool hasGetChars() { return true; }
 
43
  virtual int getChars(int nChars, Guchar *buffer);
 
44
 
 
45
  inline int doGetChar() {
 
46
    int result = doLookChar();
 
47
    ++counter;
 
48
    return result;
 
49
  }
 
50
 
 
51
  inline int doLookChar() {
 
52
    if (inited == gFalse) init();
 
53
 
 
54
    if (!image) return EOF;
 
55
 
 
56
    int w = image->comps[0].w;
 
57
    int h = image->comps[0].h;
 
58
 
 
59
    int y = (counter / image->numcomps) / w;
 
60
    int x = (counter / image->numcomps) % w;
 
61
    if (y >= h) return EOF;
 
62
 
 
63
    int component = counter % image->numcomps;
 
64
 
 
65
    int adjust = 0;
 
66
    if (image->comps[component].prec > 8) {
 
67
      adjust = image->comps[component].prec - 8;
 
68
    }
 
69
 
 
70
    if (unlikely(image->comps[component].data == NULL)) return EOF;
 
71
 
 
72
    int r = image->comps[component].data[y * w + x];
 
73
    r += (image->comps[component].sgnd ? 1 << (image->comps[0].prec - 1) : 0);
 
74
 
 
75
    unsigned char rc = (unsigned char) ((r >> adjust)+((r >> (adjust-1))%2));
 
76
 
 
77
    return rc;
 
78
  }
 
79
 
 
80
  opj_image_t *image;
 
81
  opj_dinfo_t *dinfo;
 
82
  int counter;
 
83
  GBool inited;
 
84
};
 
85
 
 
86
#endif