RAMMAIN.CPP 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 RWS Inc, All Rights Reserved
  4. //
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of version 2 of the GNU General Public License as published by
  7. // the Free Software Foundation
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License along
  15. // with this program; if not, write to the Free Software Foundation, Inc.,
  16. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. //
  18. // Sample shell for using FLC read/write stuff.
  19. //
  20. // This particular example is designed as a QuickWin application using
  21. // Microsoft Visual C/C++. The underlying FLC stuff should work in a
  22. // regular Windows app or as a DOS app, too.
  23. //
  24. ///////////////////////////////////////////////////////////////////////////////
  25. #include "Blue.h"
  26. #include "Image.h"
  27. #include "ramflx.h"
  28. #include "BLIT.H"
  29. #include "tools.h"
  30. void Test(void);
  31. void LoadBackImage(void);
  32. void BlitFlx(CRamFlx *pFlx, short sTrans);
  33. void DumpHeader(FLX_FILE_HDR* pfilehdr);
  34. int SmartHeap_far_malloc;
  35. static CImage* m_pBuf; // The image buffer where background and flx are combined
  36. static CPalImage m_Back; // The background image
  37. ///////////////////////////////////////////////////////////////////////////////
  38. //
  39. // AppMain is entry point for application.
  40. //
  41. ///////////////////////////////////////////////////////////////////////////////
  42. void AppMain(void)
  43. {
  44. // Create display
  45. if (Blu_CreateDisplay(640, 480, 16) == 0)
  46. {
  47. // Create screen buffer
  48. m_pBuf = Blit_CreateScrnBuf(640, 480, 16);
  49. if (m_pBuf != NULL)
  50. {
  51. // Tell blue layer about screen buffer for when we want to update screen
  52. Blu_SetDisplayBuf(m_pBuf->pData, m_pBuf->lWidth, m_pBuf->lHeight, 16 );
  53. // Tell blue layer to use same buffer to redraw screen when necessary
  54. Blu_SetRedrawBuf(m_pBuf->pData, m_pBuf->lWidth, m_pBuf->lHeight,
  55. 0, 0, 0, 0, m_pBuf->lWidth, m_pBuf->lHeight, 16 );
  56. // Test Flx
  57. Test();
  58. // Destroy screen buffer
  59. Blit_DestroyScrnBuf();
  60. }
  61. else
  62. {
  63. // Error creating buffer
  64. }
  65. }
  66. else
  67. {
  68. // Error creating display
  69. }
  70. }
  71. ///////////////////////////////////////////////////////////////////////////////
  72. //
  73. // Example of reading in an existing flic and creating and writing out a new
  74. // flic. In other words, we make a duplicate of the flic.
  75. //
  76. ///////////////////////////////////////////////////////////////////////////////
  77. void Test(void)
  78. {
  79. static CPalImage buf1;
  80. // Open existing FLI file for reading
  81. CRamFlx flxRead;
  82. static FLX_FILE_HDR filehdrRead;
  83. // Load the background image
  84. LoadBackImage();
  85. // Open file
  86. if (flxRead.Open("LEWLIT.FLC", &filehdrRead, NULL) == 0)
  87. {
  88. // Show header
  89. DumpHeader(&filehdrRead);
  90. TRACE("Processing frames:\n");
  91. // Read each frame until we reach the ring frame
  92. for (short sFrame = 1; sFrame <= filehdrRead.sNumFrames+3;)
  93. {
  94. if (GetLeftMouseEvent()==M_EVENT_DOWN)
  95. if (flxRead.ReadNextFrame(NULL) == 0)
  96. {
  97. TRACE("Actual %hd, Number %hd\n",flxRead.GetFrameNum(),sFrame);
  98. sFrame++;
  99. BlitFlx(&flxRead,TRUE);
  100. }
  101. else
  102. {
  103. TRACE("Error reported by CFlx::ReadNextFrame()!\n");
  104. break;
  105. }
  106. Blu_System();
  107. }
  108. flxRead.Close(NULL);
  109. }
  110. else
  111. TRACE("Error reported by CFlx::Open()!\n");
  112. }
  113. void LoadBackImage(void)
  114. {
  115. // Load background image
  116. if (m_Back.LoadDib("SR71.BMP",FCC_p555) == 0)
  117. {
  118. // Display background image
  119. Blit_Copy(&m_Back, 0, 0, m_pBuf, 0, 0, m_Back.image.lWidth, m_Back.image.lHeight, 0);
  120. Blu_UpdateDisplay(0, 0, 0, 0, m_Back.image.lWidth, m_Back.image.lHeight);
  121. }
  122. }
  123. void BlitFlx(CRamFlx *pFlx, short sTrans)
  124. {
  125. // Blit the image to the buffer
  126. CPalImage* ppi = pFlx->GetBuffer();
  127. if (sTrans)
  128. Blit_Combine( ppi,
  129. 0,
  130. 0,
  131. &m_Back,
  132. 0,
  133. 0,
  134. m_pBuf,
  135. 0,
  136. 0,
  137. ppi->image.lWidth,
  138. ppi->image.lHeight);
  139. else
  140. Blit_Copy( ppi,
  141. 0,
  142. 0,
  143. m_pBuf,
  144. 0,
  145. 0,
  146. ppi->image.lWidth,
  147. ppi->image.lHeight,
  148. sTrans);
  149. // Update screen from buffer
  150. Blu_UpdateDisplay(0, // buffer x
  151. 0, // buffer y
  152. 0, // screen x
  153. 0, // screen y
  154. ppi->image.lWidth, // width
  155. ppi->image.lHeight); // height
  156. }
  157. ///////////////////////////////////////////////////////////////////////////////
  158. //
  159. // Dump all the info in a flx file header
  160. //
  161. ///////////////////////////////////////////////////////////////////////////////
  162. void DumpHeader(FLX_FILE_HDR* pfilehdr)
  163. {
  164. TRACE("lEntireFileSize = %ld\n",pfilehdr->lEntireFileSize);
  165. TRACE("wMagic = %hu\n",pfilehdr->wMagic);
  166. TRACE("sNumFrames %hd\n",pfilehdr->sNumFrames);
  167. TRACE("sWidth %hd\n",pfilehdr->sWidth);
  168. TRACE("sHeight %hd\n",pfilehdr->sHeight);
  169. TRACE("sDepth %hd\n",pfilehdr->sDepth);
  170. TRACE("sFlags %hd\n",pfilehdr->sFlags);
  171. TRACE("lMilliPerFrame %ld\n",pfilehdr->lMilliPerFrame);
  172. TRACE("dCreatedTime %lu\n",pfilehdr->dCreatedTime);
  173. TRACE("dCreator %lu\n",pfilehdr->dCreator);
  174. TRACE("dUpdatedTime %lu\n",pfilehdr->dUpdatedTime);
  175. TRACE("dUpdater %lu\n",pfilehdr->dUpdater);
  176. TRACE("sAspectX %hd\n",pfilehdr->sAspectX);
  177. TRACE("sAspectY %hd\n",pfilehdr->sAspectY);
  178. TRACE("lOffsetFrame1 %ld\n",pfilehdr->lOffsetFrame1);
  179. TRACE("lOffsetFrame2 %ld\n",pfilehdr->lOffsetFrame2);
  180. }
  181. ///////////////////////////////////////////////////////////////////////////////
  182. // EOF
  183. ///////////////////////////////////////////////////////////////////////////////