~ubuntu-branches/ubuntu/oneiric/luatex/oneiric

« back to all changes in this revision

Viewing changes to source/libs/poppler/poppler-0.12.4/poppler/Movie.cc

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2011-04-10 21:08:04 UTC
  • mfrom: (0.3.1) (1.6.1) (19.1.5 natty)
  • Revision ID: package-import@ubuntu.com-20110410210804-m979ehyw4hnzvhu3
Tags: 0.65.0-1ubuntu3
RebuildĀ againstĀ libpoppler13.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//*********************************************************************************
 
2
//                               Movie.cc
 
3
//---------------------------------------------------------------------------------
 
4
// 
 
5
//---------------------------------------------------------------------------------
 
6
// Hugo Mercier <hmercier31[at]gmail.com> (c) 2008
 
7
// Pino Toscano <pino@kde.org> (c) 2008
 
8
//
 
9
// This program is free software; you can redistribute it and/or modify
 
10
// it under the terms of the GNU General Public License as published by
 
11
// the Free Software Foundation; either version 2 of the License, or
 
12
// (at your option) any later version.
 
13
//
 
14
// This program is distributed in the hope that it will be useful,
 
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
// GNU General Public License for more details.
 
18
//
 
19
// You should have received a copy of the GNU General Public License
 
20
// along with this program; if not, write to the Free Software
 
21
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
22
//*********************************************************************************
 
23
 
 
24
#include "Movie.h"
 
25
 
 
26
#include <GooList.h>
 
27
 
 
28
MovieWindowParameters::MovieWindowParameters() {
 
29
  // default values
 
30
  type = movieWindowEmbedded;
 
31
  width = -1;
 
32
  height = -1;
 
33
  relativeTo = windowRelativeToDocument;
 
34
  XPosition = 0.5;
 
35
  YPosition = 0.5;
 
36
  hasTitleBar = gTrue;
 
37
  hasCloseButton = gTrue;
 
38
  isResizeable = gTrue;
 
39
}
 
40
 
 
41
MovieWindowParameters::~MovieWindowParameters() {
 
42
}
 
43
 
 
44
void MovieWindowParameters::parseFWParams(Object* obj) {
 
45
  Object tmp;
 
46
 
 
47
  if (obj->dictLookup("D", &tmp)->isArray()) {
 
48
    Array * dim = tmp.getArray();
 
49
    
 
50
    if (dim->getLength() >= 2) {
 
51
      Object dd;
 
52
      if (dim->get(0, &dd)->isInt()) {
 
53
        width = dd.getInt();
 
54
      }
 
55
      dd.free();
 
56
      if (dim->get(1, &dd)->isInt()) {
 
57
        height = dd.getInt();
 
58
      }
 
59
      dd.free();
 
60
    }
 
61
  }
 
62
  tmp.free();
 
63
 
 
64
  if (obj->dictLookup("RT", &tmp)->isInt()) {
 
65
    int t = tmp.getInt();
 
66
    switch(t) {
 
67
    case 0: relativeTo = windowRelativeToDocument; break;
 
68
    case 1: relativeTo = windowRelativeToApplication; break;
 
69
    case 2: relativeTo = windowRelativeToDesktop; break;
 
70
    }
 
71
  }
 
72
  tmp.free();
 
73
 
 
74
  if (obj->dictLookup("P",&tmp)->isInt()) {
 
75
    int t = tmp.getInt();
 
76
 
 
77
    switch(t) {
 
78
    case 0: // Upper left
 
79
      XPosition = 0.0;
 
80
      YPosition = 0.0;
 
81
      break;
 
82
    case 1: // Upper Center
 
83
      XPosition = 0.5;
 
84
      YPosition = 0.0;
 
85
      break;
 
86
    case 2: // Upper Right
 
87
      XPosition = 1.0;
 
88
      YPosition = 0.0;
 
89
      break;
 
90
    case 3: // Center Left
 
91
      XPosition = 0.0;
 
92
      YPosition = 0.5;
 
93
      break;
 
94
    case 4: // Center
 
95
      XPosition = 0.5;
 
96
      YPosition = 0.5;
 
97
      break;
 
98
    case 5: // Center Right
 
99
      XPosition = 1.0;
 
100
      YPosition = 0.5;
 
101
      break;
 
102
    case 6: // Lower Left
 
103
      XPosition = 0.0;
 
104
      YPosition = 1.0;
 
105
      break;
 
106
    case 7: // Lower Center
 
107
      XPosition = 0.5;
 
108
      YPosition = 1.0;
 
109
      break;
 
110
    case 8: // Lower Right
 
111
      XPosition = 1.0;
 
112
      YPosition = 1.0;
 
113
      break;
 
114
    }
 
115
  }
 
116
  tmp.free();
 
117
 
 
118
  if (obj->dictLookup("T", &tmp)->isBool()) {
 
119
    hasTitleBar = tmp.getBool();
 
120
  }
 
121
  tmp.free();
 
122
  if (obj->dictLookup("UC", &tmp)->isBool()) {
 
123
    hasCloseButton = tmp.getBool();
 
124
  }
 
125
  tmp.free();
 
126
  if (obj->dictLookup("R", &tmp)->isInt()) {
 
127
    isResizeable = (tmp.getInt() != 0);
 
128
  }
 
129
  tmp.free();
 
130
 
 
131
}
 
132
 
 
133
MovieParameters::MovieParameters() {
 
134
  // instanciate to default values
 
135
 
 
136
  rotationAngle = 0;
 
137
  rate = 1.0;
 
138
  volume = 100;
 
139
  fittingPolicy = fittingUndefined;
 
140
  autoPlay = gTrue;
 
141
  repeatCount = 1.0;
 
142
  opacity = 1.0;
 
143
  showControls = gFalse;
 
144
 
 
145
  
 
146
  start.units = 0;
 
147
  duration.units = 0;  
 
148
}
 
149
 
 
150
MovieParameters::~MovieParameters() {
 
151
}
 
152
 
 
153
void MovieParameters::parseAnnotMovie(AnnotMovie* annot) {
 
154
  windowParams.relativeTo = MovieWindowParameters::windowRelativeToDesktop;
 
155
 
 
156
  if (annot->needFloatingWindow()) {
 
157
    windowParams.type = MovieWindowParameters::movieWindowFloating;
 
158
  }
 
159
  if (annot->needFullscreen()) {
 
160
    windowParams.type = MovieWindowParameters::movieWindowFullscreen;
 
161
  }
 
162
 
 
163
  int w, h;
 
164
  int znum, zdenum;
 
165
  annot->getMovieSize(w, h);
 
166
  annot->getZoomFactor(znum, zdenum);
 
167
  windowParams.width = int(w * double(znum) / zdenum);
 
168
  windowParams.height = int(h * double(znum) / zdenum);
 
169
 
 
170
  double x,y;
 
171
  annot->getWindowPosition(x,y);
 
172
  windowParams.XPosition = x;
 
173
  windowParams.YPosition = y;
 
174
 
 
175
  rate = annot->getRate();
 
176
  // convert volume to [0 100]
 
177
  volume = int((annot->getVolume() + 1.0) * 50);
 
178
 
 
179
  AnnotMovie::RepeatMode mode = annot->getRepeatMode();
 
180
  if (mode == AnnotMovie::repeatModeRepeat)
 
181
    repeatCount = 0.0;
 
182
 
 
183
  showControls = annot->getShowControls();
 
184
 
 
185
  AnnotMovie::Time tStart = annot->getStart();
 
186
  AnnotMovie::Time tDuration = annot->getDuration();
 
187
 
 
188
  start.units = tStart.units;
 
189
  start.units_per_second = tStart.units_per_second;
 
190
 
 
191
  duration.units = tDuration.units;
 
192
  duration.units_per_second = tDuration.units_per_second;
 
193
}
 
194
 
 
195
void MovieParameters::parseMediaPlayParameters(Object* obj) {
 
196
  
 
197
  Object tmp;
 
198
 
 
199
  if (obj->dictLookup("V", &tmp)->isInt()) {
 
200
    volume = tmp.getInt();
 
201
  }
 
202
  tmp.free();
 
203
 
 
204
  if (obj->dictLookup("C", &tmp)->isBool()) {
 
205
    showControls = tmp.getBool();
 
206
  }
 
207
  tmp.free();
 
208
 
 
209
  if (obj->dictLookup("F", &tmp)->isInt()) {
 
210
    int t = tmp.getInt();
 
211
    
 
212
    switch(t) {
 
213
    case 0: fittingPolicy = fittingMeet; break;
 
214
    case 1: fittingPolicy = fittingSlice; break;
 
215
    case 2: fittingPolicy = fittingFill; break;
 
216
    case 3: fittingPolicy = fittingScroll; break;
 
217
    case 4: fittingPolicy = fittingHidden; break;
 
218
    case 5: fittingPolicy = fittingUndefined; break;
 
219
    }
 
220
  }
 
221
  tmp.free();
 
222
 
 
223
  // duration parsing
 
224
  // duration's default value is set to 0, which means : intrinsinc media duration
 
225
  if (obj->dictLookup("D", &tmp)->isDict()) {
 
226
    Object oname, ddict, tmp2;
 
227
    if (tmp.dictLookup("S", &oname)->isName()) {
 
228
      char* name = oname.getName();
 
229
      if (!strcmp(name, "F"))
 
230
        duration.units = -1; // infinity
 
231
      else if (!strcmp(name, "T")) {
 
232
        if (tmp.dictLookup("T", &ddict)->isDict()) {
 
233
          if (ddict.dictLookup("V", &tmp2)->isNum()) {
 
234
            duration.units = Gulong(tmp2.getNum());
 
235
          }
 
236
          tmp2.free();
 
237
        }
 
238
        ddict.free();
 
239
      }
 
240
    }
 
241
    oname.free();
 
242
  }
 
243
  tmp.free();
 
244
 
 
245
 
 
246
  if (obj->dictLookup("A", &tmp)->isBool()) {
 
247
    autoPlay = tmp.getBool();
 
248
  }
 
249
  tmp.free();
 
250
 
 
251
  if (obj->dictLookup("RC", &tmp)->isNum()) {
 
252
    repeatCount = tmp.getNum();
 
253
  }
 
254
  tmp.free();
 
255
 
 
256
}
 
257
 
 
258
void MovieParameters::parseMediaScreenParameters(Object* obj) {
 
259
  Object tmp;
 
260
 
 
261
  if (obj->dictLookup("W", &tmp)->isInt()) {
 
262
    int t = tmp.getInt();
 
263
    
 
264
    switch(t) {
 
265
    case 0: windowParams.type = MovieWindowParameters::movieWindowFloating; break;
 
266
    case 1: windowParams.type = MovieWindowParameters::movieWindowFullscreen; break;
 
267
    case 2: windowParams.type = MovieWindowParameters::movieWindowHidden; break;
 
268
    case 3: windowParams.type = MovieWindowParameters::movieWindowEmbedded; break;
 
269
    }
 
270
  }
 
271
  tmp.free();
 
272
 
 
273
  // background color
 
274
  if (obj->dictLookup("B", &tmp)->isArray()) {
 
275
    Array* color = tmp.getArray();
 
276
 
 
277
    Object component;
 
278
    
 
279
    color->get(0, &component);
 
280
    bgColor.r = component.getNum();
 
281
    component.free();
 
282
 
 
283
    color->get(1, &component);
 
284
    bgColor.g = component.getNum();
 
285
    component.free();
 
286
 
 
287
    color->get(2, &component);
 
288
    bgColor.b = component.getNum();
 
289
    component.free();
 
290
  }
 
291
  tmp.free();
 
292
 
 
293
 
 
294
  // opacity
 
295
  if (obj->dictLookup("O", &tmp)->isNum()) {
 
296
    opacity = tmp.getNum();
 
297
  }
 
298
  tmp.free();
 
299
 
 
300
  if (windowParams.type == MovieWindowParameters::movieWindowFloating) {
 
301
    Object winDict;
 
302
    if (obj->dictLookup("F",&winDict)->isDict()) {
 
303
      windowParams.parseFWParams(&winDict);
 
304
    }
 
305
  }
 
306
}
 
307
 
 
308
Movie::Movie() {
 
309
  fileName = NULL;
 
310
  contentType = NULL;
 
311
  isEmbedded = gFalse;
 
312
  embeddedStream = NULL;
 
313
  posterStream = NULL;
 
314
}
 
315
 
 
316
Movie::~Movie() {
 
317
  if (fileName)
 
318
    delete fileName;
 
319
  if (contentType)
 
320
    delete contentType;
 
321
 
 
322
  if (embeddedStream && (!embeddedStream->decRef())) {
 
323
    delete embeddedStream;
 
324
  }
 
325
  if (posterStream && (!posterStream->decRef())) {
 
326
    delete posterStream;
 
327
  }
 
328
}
 
329
 
 
330
void Movie::parseAnnotMovie(AnnotMovie* annot) {
 
331
  // AnnotMovie is not embedded
 
332
  isEmbedded = gFalse;
 
333
 
 
334
  fileName = annot->getFileName()->copy();
 
335
 
 
336
  if (annot->getPosterStream()) {
 
337
    posterStream = annot->getPosterStream();
 
338
    posterStream->incRef();
 
339
  }
 
340
 
 
341
  MH.parseAnnotMovie(annot);
 
342
  // deep copy of MH to BE
 
343
  // (no distinction is made with AnnotMovie)
 
344
  memcpy(&BE, &MH, sizeof(MH));
 
345
}
 
346
 
 
347
void Movie::parseMediaRendition(Object* obj) {
 
348
 
 
349
  Object tmp, tmp2;
 
350
  if (obj->dictLookup("S", &tmp)->isName()) {
 
351
    if (!strcmp(tmp.getName(), "MR")) { // it's a media rendition
 
352
 
 
353
      //
 
354
      // parse Media Play Parameters
 
355
      if (obj->dictLookup("P", &tmp2)->isDict()) { // media play parameters
 
356
        Object params;
 
357
        if (tmp2.dictLookup("MH", &params)->isDict()) {
 
358
          MH.parseMediaPlayParameters(&params);
 
359
        }
 
360
        params.free();
 
361
        if (tmp2.dictLookup("BE", &params)->isDict()) {
 
362
          BE.parseMediaPlayParameters(&params);
 
363
        }
 
364
        params.free();
 
365
      }
 
366
      tmp2.free();
 
367
      //
 
368
      // parse Media Screen Parameters
 
369
      if (obj->dictLookup("SP", &tmp2)->isDict()) { // media screen parameters
 
370
        Object params;
 
371
        if (tmp2.dictLookup("MH", &params)->isDict()) {
 
372
          MH.parseMediaScreenParameters(&params);
 
373
        }
 
374
        params.free();
 
375
        if (tmp2.dictLookup("BE", &params)->isDict()) {
 
376
          BE.parseMediaScreenParameters(&params);
 
377
        }
 
378
        params.free();
 
379
      }
 
380
      tmp2.free();
 
381
 
 
382
      //
 
383
      // Parse media clip data
 
384
      //
 
385
      if (obj->dictLookup("C", &tmp2)->isDict()) { // media clip
 
386
        
 
387
        tmp.free();
 
388
        if (tmp2.dictLookup("S", &tmp)->isName()) {
 
389
          if (!strcmp(tmp.getName(), "MCD")) { // media clip data
 
390
            Object obj1, obj2;
 
391
            if (tmp2.dictLookup("D", &obj1)->isDict()) {
 
392
              if (obj1.dictLookup("F", &obj2)->isString()) {
 
393
                fileName = obj2.getString()->copy();
 
394
              }
 
395
              obj2.free();
 
396
              
 
397
              if (!obj1.dictLookup("EF", &obj2)->isNull()) {
 
398
                tmp.free();
 
399
                Object mref;
 
400
                if (!obj2.dictLookupNF("F", &mref)->isNull()) {
 
401
                  isEmbedded = gTrue;
 
402
                  Object embedded;
 
403
                  obj2.dictLookup("F", &embedded);
 
404
                  if (embedded.isStream()) {
 
405
                    embeddedStream = embedded.getStream();
 
406
                    // "copy" stream
 
407
                    embeddedStream->incRef();
 
408
                  }
 
409
                  embedded.free();
 
410
                }
 
411
                mref.free();
 
412
              }
 
413
              obj2.free();
 
414
            }
 
415
            obj1.free();
 
416
            
 
417
            if (tmp2.dictLookup("CT", &obj1)->isString()) {
 
418
              contentType = obj1.getString()->copy();
 
419
            }
 
420
            obj1.free();
 
421
          }
 
422
        }
 
423
        tmp.free();
 
424
      }
 
425
      tmp2.free();
 
426
    }
 
427
  }
 
428
}
 
429
 
 
430
 
 
431
void Movie::outputToFile(FILE* fp) {
 
432
  embeddedStream->reset();
 
433
 
 
434
  while (1) {
 
435
    int c = embeddedStream->getChar();
 
436
    if (c == EOF)
 
437
      break;
 
438
    
 
439
    fwrite(&c, 1, 1, fp);
 
440
  }
 
441
  
 
442
}
 
443
 
 
444
Movie* Movie::copy() {
 
445
 
 
446
  // call default copy constructor
 
447
  Movie* new_movie = new Movie(*this);
 
448
 
 
449
  if (contentType)
 
450
    new_movie->contentType = contentType->copy();
 
451
  if (fileName)
 
452
    new_movie->fileName = fileName->copy();
 
453
 
 
454
  if (new_movie->embeddedStream)
 
455
    new_movie->embeddedStream->incRef();
 
456
  
 
457
  if (new_movie->posterStream)
 
458
    new_movie->posterStream->incRef();
 
459
 
 
460
  return new_movie;
 
461
}