~ubuntu-branches/ubuntu/precise/ipe/precise

« back to all changes in this revision

Viewing changes to src/ipelib/ipedct.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Steve M. Robbins
  • Date: 2009-12-11 21:22:35 UTC
  • mfrom: (4.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20091211212235-5iio4nzpra64snab
Tags: 7.0.10-1
* New upstream.  Closes: #551192.
  - New build-depends: libcairo2-dev, liblua5.1-0-dev, gsfonts
  - patches/config.diff: Remove.  Upstream build system replaced.
  - Runtime lib package changed to libipe7.0.10 from libipe1c2a
  - Devel package renamed to libipe-dev (from libipe1-dev)
  - Package ipe depends on lua5.1 due to ipe-update-master.

* rules: Re-write to use dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
/*
7
7
 
8
8
    This file is part of the extensible drawing editor Ipe.
9
 
    Copyright (C) 1993-2007  Otfried Cheong
 
9
    Copyright (C) 1993-2009  Otfried Cheong
10
10
 
11
11
    Ipe is free software; you can redistribute it and/or modify it
12
12
    under the terms of the GNU General Public License as published by
13
 
    the Free Software Foundation; either version 2 of the License, or
 
13
    the Free Software Foundation; either version 3 of the License, or
14
14
    (at your option) any later version.
15
15
 
16
16
    As a special exception, you have permission to link Ipe with the
31
31
*/
32
32
 
33
33
#include "ipebase.h"
34
 
#include <cstring>
 
34
 
 
35
using namespace ipe;
35
36
 
36
37
// --------------------------------------------------------------------
37
38
 
66
67
class DCTStream {
67
68
public:
68
69
 
69
 
  DCTStream(IpeDataSource &source);
 
70
  DCTStream(DataSource &source);
70
71
  ~DCTStream();
71
72
  void reset();
72
73
  int getChar();
73
74
 
74
75
private:
75
 
  IpeDataSource &iSource;
 
76
  DataSource &iSource;
76
77
 
77
78
  bool progressive;             // set if in progressive mode
78
79
  bool interleaved;             // set if in interleaved mode
172
173
 
173
174
// --------------------------------------------------------------------
174
175
 
175
 
DCTStream::DCTStream(IpeDataSource &source)
 
176
DCTStream::DCTStream(DataSource &source)
176
177
  : iSource(source)
177
178
{
178
179
  int i, j;
271
272
    bufHeight = ((height + mcuHeight - 1) / mcuHeight) * mcuHeight;
272
273
    for (i = 0; i < numComps; ++i) {
273
274
      frameBuf[i] = new int[bufWidth * bufHeight];
274
 
      ::memset(frameBuf[i], 0, bufWidth * bufHeight * sizeof(int));
 
275
      memset(frameBuf[i], 0, bufWidth * bufHeight * sizeof(int));
275
276
    }
276
277
 
277
278
    // read the image data
1113
1114
  int c, c2;
1114
1115
 
1115
1116
  if (inputBits == 0) {
1116
 
    if ((c = iSource.GetChar()) == EOF)
 
1117
    if ((c = iSource.getChar()) == EOF)
1117
1118
      return EOF;
1118
1119
    if (c == 0xff) {
1119
1120
      do {
1120
 
        c2 = iSource.GetChar();
 
1121
        c2 = iSource.getChar();
1121
1122
      } while (c2 == 0xff);
1122
1123
      if (c2 != 0x00) {
1123
1124
        ipeDebug("Bad DCT data: missing 00 after ff");
1192
1193
      if (c >= 0xe0) {
1193
1194
        n = read16() - 2;
1194
1195
        for (i = 0; i < n; ++i) {
1195
 
          iSource.GetChar();
 
1196
          iSource.getChar();
1196
1197
        }
1197
1198
      } else {
1198
1199
        ipeDebug("Unknown DCT marker <%02x>", c);
1208
1209
bool DCTStream::readBaselineSOF()
1209
1210
{
1210
1211
  (void) read16(); // length
1211
 
  int prec = iSource.GetChar();
 
1212
  int prec = iSource.getChar();
1212
1213
  height = read16();
1213
1214
  width = read16();
1214
 
  numComps = iSource.GetChar();
 
1215
  numComps = iSource.getChar();
1215
1216
  if (prec != 8) {
1216
1217
    ipeDebug("Bad DCT precision %d", prec);
1217
1218
    return false;
1218
1219
  }
1219
1220
  for (int i = 0; i < numComps; ++i) {
1220
 
    compInfo[i].id = iSource.GetChar();
1221
 
    int c = iSource.GetChar();
 
1221
    compInfo[i].id = iSource.getChar();
 
1222
    int c = iSource.getChar();
1222
1223
    compInfo[i].hSample = (c >> 4) & 0x0f;
1223
1224
    compInfo[i].vSample = c & 0x0f;
1224
 
    compInfo[i].quantTable = iSource.GetChar();
 
1225
    compInfo[i].quantTable = iSource.getChar();
1225
1226
  }
1226
1227
  progressive = false;
1227
1228
  return true;
1230
1231
bool DCTStream::readProgressiveSOF()
1231
1232
{
1232
1233
  (void) read16(); // length
1233
 
  int prec = iSource.GetChar();
 
1234
  int prec = iSource.getChar();
1234
1235
  height = read16();
1235
1236
  width = read16();
1236
 
  numComps = iSource.GetChar();
 
1237
  numComps = iSource.getChar();
1237
1238
  if (prec != 8) {
1238
1239
    ipeDebug("Bad DCT precision %d", prec);
1239
1240
    return false;
1240
1241
  }
1241
1242
  for (int i = 0; i < numComps; ++i) {
1242
 
    compInfo[i].id = iSource.GetChar();
1243
 
    int c = iSource.GetChar();
 
1243
    compInfo[i].id = iSource.getChar();
 
1244
    int c = iSource.getChar();
1244
1245
    compInfo[i].hSample = (c >> 4) & 0x0f;
1245
1246
    compInfo[i].vSample = c & 0x0f;
1246
 
    compInfo[i].quantTable = iSource.GetChar();
 
1247
    compInfo[i].quantTable = iSource.getChar();
1247
1248
  }
1248
1249
  progressive = true;
1249
1250
  return true;
1256
1257
  int i, j;
1257
1258
 
1258
1259
  length = read16() - 2;
1259
 
  scanInfo.numComps = iSource.GetChar();
 
1260
  scanInfo.numComps = iSource.getChar();
1260
1261
  --length;
1261
1262
  if (length != 2 * scanInfo.numComps + 3) {
1262
1263
    ipeDebug("Bad DCT scan info block");
1267
1268
    scanInfo.comp[j] = false;
1268
1269
  }
1269
1270
  for (i = 0; i < scanInfo.numComps; ++i) {
1270
 
    id = iSource.GetChar();
 
1271
    id = iSource.getChar();
1271
1272
    for (j = 0; j < numComps; ++j) {
1272
1273
      if (id == compInfo[j].id) {
1273
1274
        break;
1278
1279
      return false;
1279
1280
    }
1280
1281
    scanInfo.comp[j] = true;
1281
 
    c = iSource.GetChar();
 
1282
    c = iSource.getChar();
1282
1283
    scanInfo.dcHuffTable[j] = (c >> 4) & 0x0f;
1283
1284
    scanInfo.acHuffTable[j] = c & 0x0f;
1284
1285
  }
1285
 
  scanInfo.firstCoeff = iSource.GetChar();
1286
 
  scanInfo.lastCoeff = iSource.GetChar();
1287
 
  c = iSource.GetChar();
 
1286
  scanInfo.firstCoeff = iSource.getChar();
 
1287
  scanInfo.lastCoeff = iSource.getChar();
 
1288
  c = iSource.getChar();
1288
1289
  scanInfo.ah = (c >> 4) & 0x0f;
1289
1290
  scanInfo.al = c & 0x0f;
1290
1291
  return true;
1298
1299
 
1299
1300
  length = read16() - 2;
1300
1301
  while (length > 0) {
1301
 
    index = iSource.GetChar();
 
1302
    index = iSource.getChar();
1302
1303
    if ((index & 0xf0) || index >= 4) {
1303
1304
      ipeDebug("Bad DCT quantization table");
1304
1305
      return false;
1306
1307
    if (index == numQuantTables)
1307
1308
      numQuantTables = index + 1;
1308
1309
    for (i = 0; i < 64; ++i)
1309
 
      quantTables[index][dctZigZag[i]] = uchar(iSource.GetChar());
 
1310
      quantTables[index][dctZigZag[i]] = uchar(iSource.getChar());
1310
1311
    length -= 65;
1311
1312
  }
1312
1313
  return true;
1324
1325
 
1325
1326
  length = read16() - 2;
1326
1327
  while (length > 0) {
1327
 
    index = iSource.GetChar();
 
1328
    index = iSource.getChar();
1328
1329
    --length;
1329
1330
    if ((index & 0x0f) >= 4) {
1330
1331
      ipeDebug("Bad DCT Huffman table");
1343
1344
    sym = 0;
1344
1345
    code = 0;
1345
1346
    for (i = 1; i <= 16; ++i) {
1346
 
      c = iSource.GetChar();
 
1347
      c = iSource.getChar();
1347
1348
      tbl->firstSym[i] = sym;
1348
1349
      tbl->firstCode[i] = code;
1349
1350
      tbl->numCodes[i] = ushort(c);
1352
1353
    }
1353
1354
    length -= 16;
1354
1355
    for (i = 0; i < sym; ++i)
1355
 
      tbl->sym[i] = uchar(iSource.GetChar());
 
1356
      tbl->sym[i] = uchar(iSource.getChar());
1356
1357
    length -= sym;
1357
1358
  }
1358
1359
  return true;
1382
1383
    goto err;
1383
1384
  }
1384
1385
  for (i = 0; i < 12; ++i) {
1385
 
    if ((c = iSource.GetChar()) == EOF) {
 
1386
    if ((c = iSource.getChar()) == EOF) {
1386
1387
      goto err;
1387
1388
    }
1388
1389
    buf[i] = char(c);
1393
1394
  colorXform = buf[11];
1394
1395
  gotAdobeMarker = true;
1395
1396
  for (i = 14; i < length; ++i) {
1396
 
    if (iSource.GetChar() == EOF) {
 
1397
    if (iSource.getChar() == EOF) {
1397
1398
      goto err;
1398
1399
    }
1399
1400
  }
1422
1423
 
1423
1424
  do {
1424
1425
    do {
1425
 
      c = iSource.GetChar();
 
1426
      c = iSource.getChar();
1426
1427
    } while (c != 0xff);
1427
1428
    do {
1428
 
      c = iSource.GetChar();
 
1429
      c = iSource.getChar();
1429
1430
    } while (c == 0xff);
1430
1431
  } while (c == 0x00);
1431
1432
  return c;
1435
1436
{
1436
1437
  int c1, c2;
1437
1438
 
1438
 
  if ((c1 = iSource.GetChar()) == EOF)
 
1439
  if ((c1 = iSource.getChar()) == EOF)
1439
1440
    return EOF;
1440
 
  if ((c2 = iSource.GetChar()) == EOF)
 
1441
  if ((c2 = iSource.getChar()) == EOF)
1441
1442
    return EOF;
1442
1443
  return (c1 << 8) + c2;
1443
1444
}
1444
1445
 
1445
1446
// --------------------------------------------------------------------
1446
1447
 
1447
 
bool dctDecode(IpeBuffer dctData, IpeBuffer pixelData)
 
1448
bool dctDecode(Buffer dctData, Buffer pixelData)
1448
1449
{
1449
 
  ipeDebug("dctDecode %d, %d", dctData.size(), pixelData.size());
1450
 
  IpeBufferSource source(dctData);
 
1450
  // ipeDebug("dctDecode %d, %d", dctData.size(), pixelData.size());
 
1451
  BufferSource source(dctData);
1451
1452
  DCTStream dct(source);
1452
1453
  dct.reset();
1453
1454
  char *p = pixelData.data();