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 #include "common/config-manager.h" // for ConfMan
26 #include "common/path.h" // for Path
27 #include "common/ptr.h"
28 #include "common/rect.h" // for Rect
29 #include "common/scummsys.h" // for int16, uint8, uint16, int32
30 #include "sci/engine/vm_types.h" // for reg_t
31 #include "sci/video/robot_decoder.h" // for RobotDecoder
32 #include "sci/sound/audio32.h" // for Audio32::kMaxVolume
33 #include "video/avi_decoder.h" // for AVIDecoder::setVolume
34 #include "video/subtitles.h" // for Video::Subtitles
35 
36 namespace Video {
37 class AdvancedVMDDecoder;
38 }
39 namespace Sci {
40 class EventManager;
41 class Plane;
42 class ScreenItem;
43 class SegManager;
44 class SEQDecoder;
45 struct Palette;
46 
51 class VideoPlayer {
52 public:
53  enum EventFlags {
54  kEventFlagNone = 0,
55  kEventFlagEnd = 1,
56  kEventFlagEscapeKey = 2,
57  kEventFlagMouseDown = 4,
58  kEventFlagHotRectangle = 8,
59  kEventFlagToFrame = 0x10,
60  kEventFlagYieldToVM = 0x20,
61  kEventFlagReverse = 0x80
62  };
63 
64  friend EventFlags operator|(const EventFlags a, const EventFlags b) {
65  return static_cast<EventFlags>((int)a | (int)b);
66  }
67 
68  VideoPlayer(EventManager *eventMan, Video::VideoDecoder *decoder = nullptr) :
69  _eventMan(eventMan),
70  _decoder(decoder),
71  _needsUpdate(false),
72  _currentFrame(nullptr),
73  _hqVideoMode(false)
74  {}
75 
76  virtual ~VideoPlayer() {}
77 
78 protected:
79  EventManager *_eventMan;
80 
85 
91  bool open(const Common::Path &fileName);
92 
101  bool startHQVideo(const Graphics::PixelFormat &format);
102 
107  virtual bool shouldStartHQVideo() const {
108  if (!ConfMan.getBool("enable_hq_video")) {
109  return false;
110  }
111 
112  if (_decoder->getWidth() == _drawRect.width() &&
113  _decoder->getHeight() == _drawRect.height()) {
114  return false;
115  }
116 
117  return true;
118  }
119 
123  bool endHQVideo();
124 
132  virtual EventFlags playUntilEvent(const EventFlags flags, const uint32 maxSleepMs = 0xFFFFFFFF);
133 
138  virtual EventFlags checkForEvent(const EventFlags flags);
139 
143  virtual void submitPalette(const uint8 palette[256 * 3]) const;
144 
148  virtual void renderFrame(const Graphics::Surface &nextFrame) const;
149 
154  void renderLQToSurface(Graphics::Surface &out, const Graphics::Surface &nextFrame, const bool doublePixels, const bool blackLines) const;
155 
160  template <typename PixelType>
161  void renderLQToSurfaceDouble(Graphics::Surface &out, const Graphics::Surface &nextFrame, int lineCount) const;
162 
166  void setDrawRect(const int16 x, const int16 y, const int16 width, const int16 height);
167 
172  void setSubtitlePosition() const;
173 
178  void showUnsupportedFormatDialog();
179 
184 
191 
196 
201 
207 };
208 
209 #pragma mark SEQPlayer
210 
215 class SEQPlayer : public VideoPlayer {
216 public:
217  SEQPlayer(EventManager *eventMan);
218 
223  void play(const Common::Path &fileName, const int16 numTicks, const int16 x, const int16 y);
224 };
225 
226 #pragma mark -
227 #pragma mark AVIPlayer
228 
233 class AVIPlayer : public VideoPlayer {
234 public:
235  enum IOStatus {
236  kIOSuccess = 0,
237  kIOFileNotFound = 2,
238  kIOSeekFailed = 12
239  };
240 
241  enum AVIStatus {
242  kAVINotOpen = 0,
243  kAVIOpen = 1,
244  kAVIPlaying = 2,
245  kAVIPaused = 3
246  };
247 
248  AVIPlayer(EventManager *eventMan);
249 
253  IOStatus open(const Common::Path &fileName);
254 
259  IOStatus init(const bool doublePixels);
260 
264  IOStatus play(const int16 from, const int16 to, const int16 showStyle, const bool cue);
265 
266  EventFlags playUntilEvent(const EventFlags flags, const uint32 maxSleepMs = 0xFFFFFFFF) override;
267 
271  IOStatus close();
272 
276  IOStatus cue(const uint16 frameNo);
277 
281  uint16 getDuration() const;
282 
283 private:
287  AVIStatus _status;
288 };
289 
290 #pragma mark -
291 #pragma mark QuickTimePlayer
292 
297 class QuickTimePlayer : public VideoPlayer {
298 public:
299  QuickTimePlayer(EventManager *eventMan);
300 
304  void play(const Common::Path &fileName);
305 };
306 
307 #pragma mark -
308 #pragma mark VMDPlayer
309 
315 class VMDPlayer : public VideoPlayer {
316 public:
317  enum OpenFlags {
318  kOpenFlagNone = 0,
319  kOpenFlagMute = 1
320  };
321 
322  enum IOStatus {
323  kIOSuccess = 0,
324  kIOError = 0xFFFF
325  };
326 
327  enum PlayFlags {
328  kPlayFlagNone = 0,
329  kPlayFlagDoublePixels = 1,
330  kPlayFlagBlackLines = 4,
331  kPlayFlagBoost = 0x10,
332  kPlayFlagLeaveScreenBlack = 0x20,
333  kPlayFlagLeaveLastFrame = 0x40,
334  kPlayFlagBlackPalette = 0x80,
335  kPlayFlagStretchVertical = 0x100
336  };
337 
338  enum VMDStatus {
339  kVMDNotOpen = 0,
340  kVMDOpen = 1,
341  kVMDPlaying = 2,
342  kVMDPaused = 3,
343  kVMDStopped = 4,
344  kVMDFinished = 5
345  };
346 
347  VMDPlayer(EventManager *eventMan, SegManager *segMan);
348  ~VMDPlayer() override;
349 
350 private:
351  SegManager *_segMan;
352 
353 #pragma mark -
354 #pragma mark VMDPlayer - Playback
355 public:
359  IOStatus open(const Common::Path &fileName, const OpenFlags flags);
360 
365  void init(int16 x, int16 y, const PlayFlags flags, const int16 boostPercent, const int16 boostStartColor, const int16 boostEndColor);
366 
370  IOStatus close();
371 
375  VMDStatus getStatus() const;
376 
377  // Was WaitForEvent in SSCI
378  EventFlags kernelPlayUntilEvent(const EventFlags flags, const int16 lastFrameNo, const int16 yieldInterval);
379 
380 private:
384  bool _isOpen;
385 
389  bool _isInitialized;
390 
396  Resource *_bundledVmd;
397 
402  int32 _yieldFrame;
403 
408  int32 _yieldInterval;
409 
414  int _lastYieldedFrameNo;
415 
416  EventFlags playUntilEvent(const EventFlags flags, const uint32 = 0xFFFFFFFF) override;
417  EventFlags checkForEvent(const EventFlags flags) override;
418 
419 #pragma mark -
420 #pragma mark VMDPlayer - Rendering
421 public:
426  void ignorePalettes() { _ignorePalettes = true; }
427 
431  void setPlane(const int16 priority, const reg_t planeId);
432 
433 protected:
437  void renderFrame(const Graphics::Surface &nextFrame) const override;
438 
442  void submitPalette(const uint8 palette[256 * 3]) const override;
443 
444 private:
448  Plane *_plane;
449 
454  ScreenItem *_screenItem;
455 
459  reg_t _bitmapId;
460 
465  bool _planeIsOwned;
466 
471  int _priority;
472 
476  bool _doublePixels;
477 
481  bool _stretchVertical;
482 
486  bool _blackLines;
487 
492  bool _leaveScreenBlack;
493 
498  bool _leaveLastFrame;
499 
503  bool _ignorePalettes;
504 
508  bool _isComposited;
509 
514  void fillPalette(const uint8 rawPalette[256 * 3], Palette &outPalette) const;
515 
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 
547  bool shouldUseCompositing() const {
548  return isNormallyComposited() && !shouldStartHQVideo();
549  }
550 
551  bool isNormallyComposited() const {
552  return (getSciVersion() == SCI_VERSION_3) ||
553  (g_sci->getPlatform() == Common::kPlatformMacintosh &&
554  getSciVersion() >= SCI_VERSION_2_1_LATE);
555  }
556 
557  void initOverlay();
558  void renderOverlay(const Graphics::Surface &nextFrame) const;
559  void closeOverlay();
560 
561  void initComposited();
562  void renderComposited() const;
563  void closeComposited();
564 
565 #pragma mark -
566 #pragma mark VMDPlayer - Blackout
567 public:
572  void setBlackoutArea(const Common::Rect &rect) { _blackoutRect = rect; }
573 
574 private:
578  Common::Rect _blackoutRect;
579 
584  Plane *_blackoutPlane;
585 
586 #pragma mark -
587 #pragma mark VMDPlayer - Palette
588 public:
593  void restrictPalette(const uint8 startColor, const int16 endColor);
594 
595 private:
599  uint8 _startColor;
600 
604  uint8 _endColor;
605 
618 #ifdef SCI_VMD_BLACK_PALETTE
619  bool _blackPalette;
620 #endif
621 
622 #pragma mark -
623 #pragma mark VMDPlayer - Brightness boost
624 private:
629  int16 _boostPercent;
630 
634  uint8 _boostStartColor;
635 
639  uint8 _boostEndColor;
640 
641 #pragma mark -
642 #pragma mark VMDPlayer - Mouse cursor
643 public:
649  void setShowCursor(const bool shouldShow) { _showCursor = shouldShow; }
650 
651 private:
655  bool _showCursor;
656 
657 #pragma mark -
658 #pragma mark VMDPlayer - Censorship blobs
659 public:
666  int16 addBlob(int16 blockSize, int16 top, int16 left, int16 bottom, int16 right);
667  void deleteBlobs();
668  void deleteBlob(int16 blobNumber);
669 
670 private:
671  enum {
672  kMaxBlobs = 10
673  };
674 
675  struct Blob {
676  int16 blobNumber;
677  int16 blockSize;
678  int16 top;
679  int16 left;
680  int16 bottom;
681  int16 right;
682  };
683 
684  Common::List<Blob> _blobs;
685 
686  void drawBlobs(Graphics::Surface& frame) const;
687 };
688 
689 #pragma mark -
690 #pragma mark DuckPlayer
691 
696 class DuckPlayer : public VideoPlayer {
697 public:
698  enum DuckStatus {
699  kDuckClosed = 0,
700  kDuckOpen = 1,
701  kDuckPlaying = 2,
702  kDuckPaused = 3
703  };
704 
705  DuckPlayer(EventManager *eventMan, SegManager *segMan);
706 
710  void open(const GuiResourceId resourceId, const int displayMode, const int16 x, const int16 y);
711 
715  void close();
716 
720  void play(const int lastFrameNo);
721 
726  void setDoFrameOut(const bool value) { _doFrameOut = value; }
727 
731  void setVolume(const uint8 value) {
732  _volume = value * Audio::Mixer::kMaxChannelVolume / Audio32::kMaxVolume;
733  _decoder->setVolume(_volume);
734  }
735 
736 protected:
737  bool shouldStartHQVideo() const override {
738  if (!VideoPlayer::shouldStartHQVideo() || _blackLines) {
739  return false;
740  }
741 
742  return true;
743  }
744 
745  void renderFrame(const Graphics::Surface &nextFrame) const override;
746 
747 private:
752  Plane *_plane;
753 
757  DuckStatus _status;
758 
762  uint8 _volume;
763 
768  bool _doFrameOut;
769 
773  bool _doublePixels;
774 
778  bool _blackLines;
779 };
780 
781 #pragma mark -
782 #pragma mark Video32
783 
788 public:
789  Video32(SegManager *segMan, EventManager *eventMan) :
790  _SEQPlayer(eventMan),
791  _AVIPlayer(eventMan),
792  _QuickTimePlayer(eventMan),
793  _VMDPlayer(eventMan, segMan),
794  _robotPlayer(segMan),
795  _duckPlayer(eventMan, segMan) {}
796 
797  void beforeSaveLoadWithSerializer(Common::Serializer &ser);
798  void saveLoadWithSerializer(Common::Serializer &ser) override;
799 
800  SEQPlayer &getSEQPlayer() { return _SEQPlayer; }
801  AVIPlayer &getAVIPlayer() { return _AVIPlayer; }
802  QuickTimePlayer &getQuickTimePlayer() { return _QuickTimePlayer; }
803  VMDPlayer &getVMDPlayer() { return _VMDPlayer; }
804  RobotDecoder &getRobotPlayer() { return _robotPlayer; }
805  DuckPlayer &getDuckPlayer() { return _duckPlayer; }
806 
807 private:
808  SEQPlayer _SEQPlayer;
809  AVIPlayer _AVIPlayer;
810  QuickTimePlayer _QuickTimePlayer;
811  VMDPlayer _VMDPlayer;
812  RobotDecoder _robotPlayer;
813  DuckPlayer _duckPlayer;
814 };
815 
816 } // End of namespace Sci
817 
818 #endif // SCI_GRAPHICS_VIDEO32_H
Common::ScopedPtr< Video::VideoDecoder > _decoder
Definition: video32.h:84
Common::Rect _drawRect
Definition: video32.h:183
Definition: surface.h:67
Definition: video32.h:297
Video::Subtitles _subtitles
Definition: video32.h:200
Definition: pixelformat.h:138
void setDoFrameOut(const bool value)
Definition: video32.h:726
Definition: video32.h:51
bool shouldStartHQVideo() const override
Definition: video32.h:737
SciEngine * g_sci
Definition: plane32.h:103
Definition: rect.h:524
Definition: path.h:52
Definition: serializer.h:79
Definition: subtitles.h:78
Definition: video32.h:215
const Graphics::Surface * _currentFrame
Definition: video32.h:195
Definition: video32.h:233
Definition: video32.h:696
Definition: video_decoder.h:53
Common::Platform getPlatform() const
Definition: resource.h:256
bool _needsUpdate
Definition: video32.h:190
bool _hqVideoMode
Definition: video32.h:206
Definition: console.h:28
Definition: serializer.h:308
virtual uint16 getWidth() const
Definition: seg_manager.h:48
Definition: mixer.h:82
virtual uint16 getHeight() const
Definition: video32.h:315
void setVolume(const uint8 value)
Definition: video32.h:731
Definition: screen_item32.h:53
void setShowCursor(const bool shouldShow)
Definition: video32.h:649
virtual bool shouldStartHQVideo() const
Definition: video32.h:107
Definition: helpers.h:247
Definition: animation.h:37
Definition: event.h:151
Definition: vm_types.h:39
void ignorePalettes()
Definition: video32.h:426
Definition: robot_decoder.h:455
void setBlackoutArea(const Common::Rect &rect)
Definition: video32.h:572
Definition: video32.h:787
Definition: atari-screen.h:42