~ubuntu-branches/ubuntu/edgy/djvulibre/edgy

« back to all changes in this revision

Viewing changes to libdjvu/DjVuImage.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-07-03 11:38:23 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060703113823-un2te7742kk04c63
Tags: 3.5.17-1ubuntu1
* Sync with Debian
* debian/rules:
  - use dh_iconcache.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
//C- | MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
52
52
//C- +------------------------------------------------------------------
53
53
// 
54
 
// $Id: DjVuImage.cpp,v 1.10 2005/04/27 16:34:13 leonb Exp $
55
 
// $Name: debian_version_3_5_16-1 $
 
54
// $Id: DjVuImage.cpp,v 1.13 2006/01/19 15:20:41 leonb Exp $
 
55
// $Name: debian_version_3_5_17-1 $
56
56
 
57
57
#ifdef HAVE_CONFIG_H
58
58
# include "config.h"
1074
1074
{
1075
1075
    GRect rect=inrect;
1076
1076
    GRect all=inall;
1077
 
///* rotate code
1078
 
    if( dimg.get_rotate()%4 )
1079
 
    {
 
1077
    if( dimg.get_rotate() )
 
1078
      {
1080
1079
        GRectMapper mapper;
1081
 
        mapper.rotate((4-dimg.get_rotate())%4);
 
1080
        mapper.rotate(-dimg.get_rotate());
1082
1081
        mapper.map(rect);
1083
1082
        mapper.map(all);
1084
1083
    }
1085
 
///* rotate code ends
1086
 
 
 
1084
    
1087
1085
  // Sanity
1088
1086
  if (! ( all.contains(rect.xmin, rect.ymin) &&
1089
1087
          all.contains(rect.xmax-1, rect.ymax-1) ))
1102
1100
    {
1103
1101
        GP<GBitmap> bm=(dimg.*get)(zrect, red, align);
1104
1102
        if(bm)
1105
 
            return bm->rotate((4-dimg.get_rotate())%4);
 
1103
            return bm->rotate(dimg.get_rotate());
1106
1104
        else
1107
1105
                return NULL;
1108
1106
    }
1112
1110
         (rw*red*3 < w || rh*red*3 < h) )
1113
1111
      break;
1114
1112
  // Setup bitmap scaler
1115
 
  if (! (w && h)) return 0;
 
1113
  if (w<=0 || h<=0) return 0;
1116
1114
  GP<GBitmapScaler> gbs=GBitmapScaler::create();
1117
1115
  GBitmapScaler &bs=*gbs;
1118
1116
  bs.set_input_size( (w+red-1)/red, (h+red-1)/red );
1128
1126
  GP<GBitmap> bm = GBitmap::create(zrect.height(), zrect.width(), border);
1129
1127
  bs.scale(srect, *sbm, zrect, *bm);
1130
1128
  if( bm )
1131
 
      return bm->rotate((4-dimg.get_rotate())%4);
 
1129
      return bm->rotate(dimg.get_rotate());
1132
1130
  else
1133
1131
      return NULL;
1134
1132
}
1137
1135
do_pixmap(const DjVuImage &dimg, PImager get,
1138
1136
          const GRect &inrect, const GRect &inall, double gamma )
1139
1137
{
1140
 
 
1141
 
    GRect rect=inrect;
1142
 
    GRect all=inall;
1143
 
///* rotate code
1144
 
    if( dimg.get_rotate()%4 )
 
1138
  GRect rect=inrect;
 
1139
  GRect all=inall;
 
1140
  if( dimg.get_rotate()%4 )
1145
1141
    {
1146
 
        GRectMapper mapper;
1147
 
        mapper.rotate((4-dimg.get_rotate())%4);
1148
 
        mapper.map(rect);
1149
 
        mapper.map(all);
 
1142
      GRectMapper mapper;
 
1143
      mapper.rotate(-dimg.get_rotate());
 
1144
      mapper.map(rect);
 
1145
      mapper.map(all);
1150
1146
    }
1151
 
///* rotate code ends
1152
 
 
 
1147
  
1153
1148
  // Sanity
1154
1149
  if (! ( all.contains(rect.xmin, rect.ymin) &&
1155
1150
          all.contains(rect.xmax-1, rect.ymax-1) ))
1158
1153
  int red, w=0, h=0, rw=0, rh=0;
1159
1154
  w = dimg.get_real_width();
1160
1155
  h = dimg.get_real_height();
1161
 
  
1162
1156
 
1163
1157
  rw = all.width();
1164
1158
  rh = all.height();
1169
1163
    {
1170
1164
        GP<GPixmap> pm = (dimg.*get)(zrect, red, gamma);
1171
1165
        if( pm ) 
1172
 
            return pm->rotate((4-dimg.get_rotate())%4);
 
1166
            return pm->rotate(dimg.get_rotate());
1173
1167
        else
1174
1168
            return NULL;
1175
1169
    }
1181
1175
         (rw*red*3 < w || rh*red*3 < h) )
1182
1176
      break;
1183
1177
  // Setup pixmap scaler
1184
 
  if (w<0 || h<0) return 0;
 
1178
  if (w<=0 || h<=0) return 0;
1185
1179
  GP<GPixmapScaler> gps=GPixmapScaler::create();
1186
1180
  GPixmapScaler &ps=*gps;
1187
1181
  ps.set_input_size( (w+red-1)/red, (h+red-1)/red );
1196
1190
  GP<GPixmap> pm = GPixmap::create();
1197
1191
  ps.scale(srect, *spm, zrect, *pm);
1198
1192
  if(pm)
1199
 
      return pm->rotate((4-dimg.get_rotate())%4);
 
1193
      return pm->rotate(dimg.get_rotate());
1200
1194
  else
1201
1195
      return NULL;
1202
1196
}
1228
1222
int 
1229
1223
DjVuImage::get_rotate() const
1230
1224
{
1231
 
  return (rotate_count<0)?0:rotate_count;
 
1225
  return (rotate_count<0) ? 0 : rotate_count;
1232
1226
}
1233
1227
 
1234
1228
void
1235
1229
DjVuImage::init_rotate(const DjVuInfo &info)
1236
1230
1237
 
  rotate_count=((360-GRect::findangle(info.orientation))/90)%4;
 
1231
  rotate_count = info.orientation;
1238
1232
}
1239
1233
 
1240
1234
void DjVuImage::set_rotate(int count) 
1241
1235
1242
 
  rotate_count=((count%4)+4)%4;
 
1236
  rotate_count = count % 4;
1243
1237
}
1244
1238
 
1245
1239
GP<DjVuAnno> 
1246
1240
DjVuImage::get_decoded_anno()
1247
1241
{
 
1242
    GP<DjVuInfo> djvuinfo = get_info();
1248
1243
    GP<DjVuAnno> djvuanno = DjVuAnno::create();
1249
1244
    GP<ByteStream> bs=get_anno();
1250
1245
    if( bs )
1251
1246
    {
1252
 
        djvuanno->decode(bs);
1253
 
       
1254
 
        const int rotate_count=get_rotate(); 
1255
 
        if( rotate_count % 4 )
 
1247
      int rotate_count=get_rotate(); 
 
1248
      /// Brain damaged adjustment of annotation 
 
1249
      /// coordinates that reflect the orientation
 
1250
      /// flag in the info chunk....
 
1251
      if (djvuinfo)
 
1252
        rotate_count = rotate_count - djvuinfo->orientation;
 
1253
      ///decode
 
1254
      djvuanno->decode(bs);
 
1255
      ///map hyperlinks correctly for rotation           
 
1256
      if( rotate_count & 3 )
1256
1257
        {   
1257
 
            ///map hyperlinks correctly for rotation           
1258
 
            GRect input, output;
1259
 
            input = GRect(0,0,get_width(), get_height());
1260
 
            output = GRect(0,0,  get_real_width(), get_real_height());
1261
 
 
1262
 
            GRectMapper mapper;
1263
 
            mapper.clear();
1264
 
            mapper.set_input(input);
1265
 
            mapper.set_output(output);               
1266
 
            mapper.rotate((4-rotate_count)%4);
1267
 
 
1268
 
            GPList<GMapArea> &list=djvuanno->ant->map_areas;
1269
 
            for(GPosition pos=list;pos;++pos)
1270
 
            {
1271
 
                list[pos]->unmap(mapper);
1272
 
            }
 
1258
          GRect input, output;
 
1259
          input = GRect(0,0,get_width(),get_height());
 
1260
          if (rotate_count & 1)
 
1261
            output = GRect(0,0,get_height(),get_width());
 
1262
          else
 
1263
            output = GRect(0,0,get_width(),get_height());
 
1264
          GRectMapper mapper;
 
1265
          mapper.clear();
 
1266
          mapper.set_input(input);
 
1267
          mapper.set_output(output);               
 
1268
          mapper.rotate(-rotate_count);
 
1269
          GPList<GMapArea> &list=djvuanno->ant->map_areas;
 
1270
          for(GPosition pos=list;pos;++pos)
 
1271
            list[pos]->unmap(mapper);
1273
1272
        }
1274
 
        return djvuanno;
 
1273
      return djvuanno;
1275
1274
    }
1276
1275
    else
1277
 
        return NULL;
 
1276
      return NULL;
1278
1277
}
1279
1278
 
1280
1279
 
1283
1282
{
1284
1283
    GRect input, output;
1285
1284
    const int rotate_count=get_rotate(); 
1286
 
    if(rotate_count%4)
 
1285
    if(rotate_count>0)
1287
1286
    {  
1288
1287
        input = GRect(0,0,get_width(), get_height());
1289
1288
        output = GRect(0,0, get_real_width(), get_real_height());
1292
1291
        mapper.clear();
1293
1292
        mapper.set_input(input);
1294
1293
        mapper.set_output(output);               
1295
 
        mapper.rotate((4-rotate_count)%4);
 
1294
        mapper.rotate(-rotate_count);
1296
1295
        mapper.map(rect);
1297
1296
    }
1298
1297
}
1302
1301
{
1303
1302
    GRect input, output;
1304
1303
    const int rotate_count=get_rotate(); 
1305
 
    if(rotate_count%4)
 
1304
    if(rotate_count>0)
1306
1305
    {  
1307
1306
        input = GRect(0,0,get_width(), get_height());
1308
1307
        output = GRect(0,0, get_real_width(), get_real_height());
1311
1310
        mapper.clear();
1312
1311
        mapper.set_input(input);
1313
1312
        mapper.set_output(output);               
1314
 
        mapper.rotate((4-rotate_count)%4);
 
1313
        mapper.rotate(-rotate_count);
1315
1314
        mapper.unmap(rect);
1316
1315
    }
1317
1316
}
1321
1320
{
1322
1321
    GRect input, output;
1323
1322
    const int rotate_count=get_rotate(); 
1324
 
    if(rotate_count%4)
 
1323
    if(rotate_count>0)
1325
1324
    {  
1326
1325
        input = GRect(0,0,get_width(), get_height());
1327
1326
        output = GRect(0,0, get_real_width(), get_real_height());
1330
1329
        mapper.clear();
1331
1330
        mapper.set_input(input);
1332
1331
        mapper.set_output(output);               
1333
 
        mapper.rotate((4-rotate_count)%4);
 
1332
        mapper.rotate(-rotate_count);
1334
1333
        mapper.map(x, y);
1335
1334
    }
1336
1335
}
1340
1339
{
1341
1340
    GRect input, output;
1342
1341
    const int rotate_count=get_rotate(); 
1343
 
    if(rotate_count%4)
 
1342
    if(rotate_count>0)
1344
1343
    {  
1345
1344
        input = GRect(0,0,get_width(), get_height());
1346
1345
        output = GRect(0,0, get_real_width(), get_real_height());
1349
1348
        mapper.clear();
1350
1349
        mapper.set_input(input);
1351
1350
        mapper.set_output(output);               
1352
 
        mapper.rotate((4-rotate_count)%4);
 
1351
        mapper.rotate(-rotate_count);
1353
1352
        mapper.unmap(x, y);
1354
1353
    }
1355
1354
}