ScummVM API documentation
video32.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef SCI_GRAPHICS_VIDEO32_H
23 #define SCI_GRAPHICS_VIDEO32_H
24 
25 #ifdef USE_RGB_COLOR
26 #include "common/config-manager.h" // for ConfMan
27 #endif
28 #include "common/path.h" // for Path
29 #include "common/ptr.h"
30 #include "common/rect.h" // for Rect
31 #include "common/scummsys.h" // for int16, uint8, uint16, int32
32 #include "sci/engine/vm_types.h" // for reg_t
33 #include "sci/video/robot_decoder.h" // for RobotDecoder
34 #include "sci/sound/audio32.h" // for Audio32::kMaxVolume
35 #include "video/avi_decoder.h" // for AVIDecoder::setVolume
36 #include "video/subtitles.h" // for Video::Subtitles
37 
38 namespace Video {
39 class AdvancedVMDDecoder;
40 }
41 namespace Sci {
42 class EventManager;
43 class Plane;
44 class ScreenItem;
45 class SegManager;
46 class SEQDecoder;
47 struct Palette;
48 
53 class VideoPlayer {
54 public:
55  enum EventFlags {
56  kEventFlagNone = 0,
57  kEventFlagEnd = 1,
58  kEventFlagEscapeKey = 2,
59  kEventFlagMouseDown = 4,
60  kEventFlagHotRectangle = 8,
61  kEventFlagToFrame = 0x10,
62  kEventFlagYieldToVM = 0x20,
63  kEventFlagReverse = 0x80
64  };
65 
66  friend EventFlags operator|(const EventFlags a, const EventFlags b) {
67  return static_cast<EventFlags>((int)a | (int)b);
68  }
69 
70  VideoPlayer(EventManager *eventMan, Video::VideoDecoder *decoder = nullptr) :
71  _eventMan(eventMan),
72  _decoder(decoder),
73  _needsUpdate(false),
74  _currentFrame(nullptr)
75 #ifdef USE_RGB_COLOR
76  ,
77  _hqVideoMode(false)
78 #endif
79  {}
80 
81  virtual ~VideoPlayer() {}
82 
83 protected:
84  EventManager *_eventMan;
85 
90 
96  bool open(const Common::Path &fileName);
97 
106  bool startHQVideo();
107 
112  virtual bool shouldStartHQVideo() const {
113 #ifdef USE_RGB_COLOR
114  if (!ConfMan.getBool("enable_hq_video")) {
115  return false;
116  }
117 
118  if (_decoder->getWidth() == _drawRect.width() &&
119  _decoder->getHeight() == _drawRect.height()) {
120  return false;
121  }
122 
123  return true;
124 #else
125  return false;
126 #endif
127  }
128 
132  bool endHQVideo();
133 
141  virtual EventFlags playUntilEvent(const EventFlags flags, const uint32 maxSleepMs = 0xFFFFFFFF);
142 
147  virtual EventFlags checkForEvent(const EventFlags flags);
148 
152  virtual void submitPalette(const uint8 palette[256 * 3]) const;
153 
157  virtual void renderFrame(const Graphics::Surface &nextFrame) const;
158 
163  template <typename PixelType>
164  void renderLQToSurface(Graphics::Surface &out, const Graphics::Surface &nextFrame, const bool doublePixels, const bool blackLines) const;
165 
169  void setDrawRect(const int16 x, const int16 y, const int16 width, const int16 height);
170 
175  void setSubtitlePosition() const;
176 
181 
188 
193 
198 
199 #ifdef USE_RGB_COLOR
200 
204  bool _hqVideoMode;
205 #endif
206 };
207 
208 #pragma mark SEQPlayer
209 
214 class SEQPlayer : public VideoPlayer {
215 public:
216  SEQPlayer(EventManager *eventMan);
217 
222  void play(const Common::Path &fileName, const int16 numTicks, const int16 x, const int16 y);
223 };
224 
225 #pragma mark -
226 #pragma mark AVIPlayer
227 
232 class AVIPlayer : public VideoPlayer {
233 public:
234  enum IOStatus {
235  kIOSuccess = 0,
236  kIOFileNotFound = 2,
237  kIOSeekFailed = 12
238  };
239 
240  enum AVIStatus {
241  kAVINotOpen = 0,
242  kAVIOpen = 1,
243  kAVIPlaying = 2,
244  kAVIPaused = 3
245  };
246 
247  AVIPlayer(EventManager *eventMan);
248 
252  IOStatus open(const Common::Path &fileName);
253 
258  IOStatus init(const bool doublePixels);
259 
263  IOStatus play(const int16 from, const int16 to, const int16 showStyle, const bool cue);
264 
265  EventFlags playUntilEvent(const EventFlags flags, const uint32 maxSleepMs = 0xFFFFFFFF) override;
266 
270  IOStatus close();
271 
275  IOStatus cue(const uint16 frameNo);
276 
280  uint16 getDuration() const;
281 
282 private:
286  AVIStatus _status;
287 };
288 
289 #pragma mark -
290 #pragma mark QuickTimePlayer
291 
296 class QuickTimePlayer : public VideoPlayer {
297 public:
298  QuickTimePlayer(EventManager *eventMan);
299 
303  void play(const Common::Path &fileName);
304 };
305 
306 #pragma mark -
307 #pragma mark VMDPlayer
308 
314 class VMDPlayer : public VideoPlayer {
315 public:
316  enum OpenFlags {
317  kOpenFlagNone = 0,
318  kOpenFlagMute = 1
319  };
320 
321  enum IOStatus {
322  kIOSuccess = 0,
323  kIOError = 0xFFFF
324  };
325 
326  enum PlayFlags {
327  kPlayFlagNone = 0,
328  kPlayFlagDoublePixels = 1,
329  kPlayFlagBlackLines = 4,
330  kPlayFlagBoost = 0x10,
331  kPlayFlagLeaveScreenBlack = 0x20,
332  kPlayFlagLeaveLastFrame = 0x40,
333  kPlayFlagBlackPalette = 0x80,
334  kPlayFlagStretchVertical = 0x100
335  };
336 
337  enum VMDStatus {
338  kVMDNotOpen = 0,
339  kVMDOpen = 1,
340  kVMDPlaying = 2,
341  kVMDPaused = 3,
342  kVMDStopped = 4,
343  kVMDFinished = 5
344  };
345 
346  VMDPlayer(EventManager *eventMan, SegManager *segMan);
347  ~VMDPlayer() override;
348 
349 private:
350  SegManager *_segMan;
351 
352 #pragma mark -
353 #pragma mark VMDPlayer - Playback
354 public:
358  IOStatus open(const Common::Path &fileName, const OpenFlags flags);
359 
364  void init(int16 x, int16 y, const PlayFlags flags, const int16 boostPercent, const int16 boostStartColor, const int16 boostEndColor);
365 
369  IOStatus close();
370 
374  VMDStatus getStatus() const;
375 
376  // Was WaitForEvent in SSCI
377  EventFlags kernelPlayUntilEvent(const EventFlags flags, const int16 lastFrameNo, const int16 yieldInterval);
378 
379 private:
383  bool _isOpen;
384 
388  bool _isInitialized;
389 
395  Resource *_bundledVmd;
396 
401  int32 _yieldFrame;
402 
407  int32 _yieldInterval;
408 
413  int _lastYieldedFrameNo;
414 
415  EventFlags playUntilEvent(const EventFlags flags, const uint32 = 0xFFFFFFFF) override;
416  EventFlags checkForEvent(const EventFlags flags) override;
417 
418 #pragma mark -
419 #pragma mark VMDPlayer - Rendering
420 public:
425  void ignorePalettes() { _ignorePalettes = true; }
426 
430  void setPlane(const int16 priority, const reg_t planeId);
431 
432 protected:
436  void renderFrame(const Graphics::Surface &nextFrame) const override;
437 
441  void submitPalette(const uint8 palette[256 * 3]) const override;
442 
443 private:
447  Plane *_plane;
448 
453  ScreenItem *_screenItem;
454 
458  reg_t _bitmapId;
459 
464  bool _planeIsOwned;
465 
470  int _priority;
471 
475  bool _doublePixels;
476 
480  bool _stretchVertical;
481 
485  bool _blackLines;
486 
491  bool _leaveScreenBlack;
492 
497  bool _leaveLastFrame;
498 
502  bool _ignorePalettes;
503 
507  bool _isComposited;
508 
513  void fillPalette(const uint8 rawPalette[256 * 3], Palette &outPalette) const;
514 
515 #ifdef USE_RGB_COLOR
516 
521  void redrawGameScreen() const;
522 
531  bool shouldStartHQVideo() const override {
532  if (!VideoPlayer::shouldStartHQVideo()) {
533  return false;
534  }
535 
536  if (_priority != 0 || _leaveLastFrame || _showCursor || _blackLines) {
537  return false;
538  }
539 
540  return true;
541  }
542 #endif
543 
548  bool shouldUseCompositing() const {
549 #ifdef USE_RGB_COLOR
550  return isNormallyComposited() && !shouldStartHQVideo();
551 #else
552  return isNormallyComposited();
553 #endif
554  }
555 
556  bool isNormallyComposited() const {
557  return (getSciVersion() == SCI_VERSION_3) ||
558  (g_sci->getPlatform() == Common::kPlatformMacintosh &&
559  getSciVersion() >= SCI_VERSION_2_1_LATE);
560  }
561 
562  void initOverlay();
563  void renderOverlay(const Graphics::Surface &nextFrame) const;
564  void closeOverlay();
565 
566  void initComposited();
567  void renderComposited() const;
568  void closeComposited();
569 
570 #pragma mark -
571 #pragma mark VMDPlayer - Blackout
572 public:
577  void setBlackoutArea(const Common::Rect &rect) { _blackoutRect = rect; }
578 
579 private:
583  Common::Rect _blackoutRect;
584 
589  Plane *_blackoutPlane;
590 
591 #pragma mark -
592 #pragma mark VMDPlayer - Palette
593 public:
598  void restrictPalette(const uint8 startColor, const int16 endColor);
599 
600 private:
604  uint8 _startColor;
605 
609  uint8 _endColor;
610 
623 #ifdef SCI_VMD_BLACK_PALETTE
624  bool _blackPalette;
625 #endif
626 
627 #pragma mark -
628 #pragma mark VMDPlayer - Brightness boost
629 private:
634  int16 _boostPercent;
635 
639  uint8 _boostStartColor;
640 
644  uint8 _boostEndColor;
645 
646 #pragma mark -
647 #pragma mark VMDPlayer - Mouse cursor
648 public:
654  void setShowCursor(const bool shouldShow) { _showCursor = shouldShow; }
655 
656 private:
660  bool _showCursor;
661 
662 #pragma mark -
663 #pragma mark VMDPlayer - Censorship blobs
664 public:
671  int16 addBlob(int16 blockSize, int16 top, int16 left, int16 bottom, int16 right);
672  void deleteBlobs();
673  void deleteBlob(int16 blobNumber);
674 
675 private:
676  enum {
677  kMaxBlobs = 10
678  };
679 
680  struct Blob {
681  int16 blobNumber;
682  int16 blockSize;
683  int16 top;
684  int16 left;
685  int16 bottom;
686  int16 right;
687  };
688 
689  Common::List<Blob> _blobs;
690 
691  void drawBlobs(Graphics::Surface& frame) const;
692 };
693 
694 #pragma mark -
695 #pragma mark DuckPlayer
696 
701 class DuckPlayer : public VideoPlayer {
702 public:
703  enum DuckStatus {
704  kDuckClosed = 0,
705  kDuckOpen = 1,
706  kDuckPlaying = 2,
707  kDuckPaused = 3
708  };
709 
710  DuckPlayer(EventManager *eventMan, SegManager *segMan);
711 
715  void open(const GuiResourceId resourceId, const int displayMode, const int16 x, const int16 y);
716 
720  void close();
721 
725  void play(const int lastFrameNo);
726 
731  void setDoFrameOut(const bool value) { _doFrameOut = value; }
732 
736  void setVolume(const uint8 value) {
737  _volume = value * Audio::Mixer::kMaxChannelVolume / Audio32::kMaxVolume;
738  _decoder->setVolume(_volume);
739  }
740 
741 protected:
742  bool shouldStartHQVideo() const override {
743  if (!VideoPlayer::shouldStartHQVideo() || _blackLines) {
744  return false;
745  }
746 
747  return true;
748  }
749 
750  void renderFrame(const Graphics::Surface &nextFrame) const override;
751 
752 private:
757  Plane *_plane;
758 
762  DuckStatus _status;
763 
767  uint8 _volume;
768 
773  bool _doFrameOut;
774 
778  bool _doublePixels;
779 
783  bool _blackLines;
784 };
785 
786 #pragma mark -
787 #pragma mark Video32
788 
793 public:
794  Video32(SegManager *segMan, EventManager *eventMan) :
795  _SEQPlayer(eventMan),
796  _AVIPlayer(eventMan),
797  _QuickTimePlayer(eventMan),
798  _VMDPlayer(eventMan, segMan),
799  _robotPlayer(segMan),
800  _duckPlayer(eventMan, segMan) {}
801 
802  void beforeSaveLoadWithSerializer(Common::Serializer &ser);
803  void saveLoadWithSerializer(Common::Serializer &ser) override;
804 
805  SEQPlayer &getSEQPlayer() { return _SEQPlayer; }
806  AVIPlayer &getAVIPlayer() { return _AVIPlayer; }
807  QuickTimePlayer &getQuickTimePlayer() { return _QuickTimePlayer; }
808  VMDPlayer &getVMDPlayer() { return _VMDPlayer; }
809  RobotDecoder &getRobotPlayer() { return _robotPlayer; }
810  DuckPlayer &getDuckPlayer() { return _duckPlayer; }
811 
812 private:
813  SEQPlayer _SEQPlayer;
814  AVIPlayer _AVIPlayer;
815  QuickTimePlayer _QuickTimePlayer;
816  VMDPlayer _VMDPlayer;
817  RobotDecoder _robotPlayer;
818  DuckPlayer _duckPlayer;
819 };
820 
821 } // End of namespace Sci
822 
823 #endif // SCI_GRAPHICS_VIDEO32_H
Common::ScopedPtr< Video::VideoDecoder > _decoder
Definition: video32.h:89
Common::Rect _drawRect
Definition: video32.h:180
Definition: surface.h:66
Definition: video32.h:296
Video::Subtitles _subtitles
Definition: video32.h:197
void setDoFrameOut(const bool value)
Definition: video32.h:731
Definition: video32.h:53
bool shouldStartHQVideo() const override
Definition: video32.h:742
SciEngine * g_sci
Definition: plane32.h:103
Definition: rect.h:144
Definition: path.h:52
Definition: serializer.h:79
Definition: subtitles.h:61
Definition: video32.h:214
const Graphics::Surface * _currentFrame
Definition: video32.h:192
Definition: video32.h:232
Definition: video32.h:701
Definition: video_decoder.h:52
Common::Platform getPlatform() const
Definition: resource.h:256
bool _needsUpdate
Definition: video32.h:187
Definition: console.h:28
Definition: serializer.h:308
virtual uint16 getWidth() const
Definition: seg_manager.h:48
Definition: mixer.h:71
virtual uint16 getHeight() const
Definition: video32.h:314
void setVolume(const uint8 value)
Definition: video32.h:736
Definition: screen_item32.h:53
void setShowCursor(const bool shouldShow)
Definition: video32.h:654
virtual bool shouldStartHQVideo() const
Definition: video32.h:112
Definition: helpers.h:246
Definition: avi_frames.h:36
Definition: event.h:151
Definition: vm_types.h:39
void ignorePalettes()
Definition: video32.h:425
Definition: robot_decoder.h:455
void setBlackoutArea(const Common::Rect &rect)
Definition: video32.h:577
Definition: video32.h:792
Definition: display_client.h:78