MAIN.CPP 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 <graph.h>
  26. #include "portable.h"
  27. #include "flx.h"
  28. short ReadFlic(char* pszIn);
  29. short CopyFlic(char* pszIn, char* pszOut);
  30. void DumpHeader(FLX_FILE_HDR* pfilehdr);
  31. ///////////////////////////////////////////////////////////////////////////////
  32. //
  33. // Sample stuff
  34. //
  35. ///////////////////////////////////////////////////////////////////////////////
  36. void main(void)
  37. {
  38. // CopyFlic("BUS_DRIV.FLI", "MYBUS.FLI");
  39. ReadFlic("h:\\sidewalk\\jukebox\\assets\\abc\\ABC_B.FLI");
  40. }
  41. ///////////////////////////////////////////////////////////////////////////////
  42. //
  43. // Copy a flic frame by frame to test the reading and writing functions.
  44. //
  45. ///////////////////////////////////////////////////////////////////////////////
  46. short ReadFlic(char* pszIn)
  47. {
  48. static FLX_BUF buf1;
  49. short sError = 0;
  50. // Open existing FLI file for reading
  51. CFlx flxRead;
  52. static FLX_FILE_HDR filehdrRead;
  53. if (flxRead.Open(pszIn, TRUE, &filehdrRead, &buf1) == 0)
  54. {
  55. DumpHeader(&filehdrRead);
  56. // Read each frame
  57. for (short sFrame = 1; (sFrame <= filehdrRead.sNumFrames) && (sError == 0); sFrame++)
  58. {
  59. if (flxRead.ReadNextFrame(&buf1) == 0)
  60. {
  61. cout << "Frame #" << sFrame << " - bPixelsModified=" << buf1.bPixelsModified << " bColorsModified=" << buf1.bColorsModified << endl;
  62. }
  63. else
  64. {
  65. cout << "Error reported by CFlx::ReadNextFrame()!\n";
  66. sError = 1;
  67. }
  68. }
  69. flxRead.Close();
  70. }
  71. else
  72. {
  73. cout << "Error reported by CFlx::Open()!\n";
  74. sError = 1;
  75. }
  76. return sError;
  77. }
  78. ///////////////////////////////////////////////////////////////////////////////
  79. //
  80. // Copy a flic frame by frame to test the reading and writing functions.
  81. //
  82. ///////////////////////////////////////////////////////////////////////////////
  83. short CopyFlic(char* pszIn, char* pszOut)
  84. {
  85. static FLX_BUF buf1;
  86. short sError = 0;
  87. // Open existing FLI file for reading
  88. CFlx flxRead;
  89. static FLX_FILE_HDR filehdrRead;
  90. if (flxRead.Open(pszIn, TRUE, &filehdrRead, &buf1) == 0)
  91. {
  92. DumpHeader(&filehdrRead);
  93. // Create new FLI file for writing
  94. CFlx flxWrite;
  95. static FLX_FILE_HDR filehdrWrite;
  96. if (flxWrite.Create(pszOut, TRUE,
  97. filehdrRead.sWidth, filehdrRead.sHeight, filehdrRead.lMilliPerFrame,
  98. filehdrRead.sAspectX, filehdrRead.sAspectY,
  99. TRUE, TRUE, &filehdrWrite, NULL) == 0)
  100. {
  101. DumpHeader(&filehdrWrite);
  102. // Read each frame and write it out
  103. for (short sFrame = 1; (sFrame <= filehdrRead.sNumFrames) && (sError == 0); sFrame++)
  104. {
  105. if (flxRead.ReadNextFrame(&buf1) == 0)
  106. {
  107. cout << "Frame #" << sFrame << " - bPixelsModified=" << buf1.bPixelsModified << " bColorsModified=" << buf1.bColorsModified << endl;
  108. if (flxWrite.WriteNextFrame(&buf1) == 0)
  109. {
  110. }
  111. else
  112. {
  113. cout << "Error reported by CFlx::WriteNextFrame()!\n";
  114. sError = 1;
  115. }
  116. }
  117. else
  118. {
  119. cout << "Error reported by CFlx::ReadNextFrame()!\n";
  120. sError = 1;
  121. }
  122. }
  123. flxWrite.WriteFinish(NULL, NULL);
  124. flxWrite.Close();
  125. }
  126. else
  127. {
  128. cout << "Error reported by CFlx::Create()!\n";
  129. sError = 1;
  130. }
  131. flxRead.Close();
  132. }
  133. else
  134. {
  135. cout << "Error reported by CFlx::Open()!\n";
  136. sError = 1;
  137. }
  138. return sError;
  139. }
  140. ///////////////////////////////////////////////////////////////////////////////
  141. //
  142. // Dump all the info in a flx file header
  143. //
  144. ///////////////////////////////////////////////////////////////////////////////
  145. void DumpHeader(FLX_FILE_HDR* pfilehdr)
  146. {
  147. cout << "lEntireFileSize = " << pfilehdr->lEntireFileSize << endl;
  148. cout << "wMagic = " << pfilehdr->wMagic << endl;
  149. cout << "sNumFrames " << pfilehdr->sNumFrames << endl;
  150. cout << "sWidth " << pfilehdr->sWidth << endl;
  151. cout << "sHeight " << pfilehdr->sHeight << endl;
  152. cout << "sDepth " << pfilehdr->sDepth << endl;
  153. cout << "sFlags " << pfilehdr->sFlags << endl;
  154. cout << "lMilliPerFrame " << pfilehdr->lMilliPerFrame << endl;
  155. cout << "dCreatedTime " << pfilehdr->dCreatedTime << endl;
  156. cout << "dCreator " << pfilehdr->dCreator << endl;
  157. cout << "dUpdatedTime " << pfilehdr->dUpdatedTime << endl;
  158. cout << "dUpdater " << pfilehdr->dUpdater << endl;
  159. cout << "sAspectX " << pfilehdr->sAspectX << endl;
  160. cout << "sAspectY " << pfilehdr->sAspectY << endl;
  161. cout << "lOffsetFrame1 " << pfilehdr->lOffsetFrame1 << endl;
  162. cout << "lOffsetFrame2 " << pfilehdr->lOffsetFrame2 << endl;
  163. }
  164. ///////////////////////////////////////////////////////////////////////////////
  165. // Old code to display image and palette - takes about 10 minutes per frame!!!!
  166. ///////////////////////////////////////////////////////////////////////////////
  167. #if 0
  168. for (short c = 10; c < 246; c++)
  169. {
  170. long rgb = ((long)((long)(prgbColors[c].bR) >> (long)2) & 0x000000ffL) |
  171. ((long)((long)(prgbColors[c].bG) << (long)6) & 0x0000ff00L) |
  172. ((long)((long)(prgbColors[c].bB) << (long)14) & 0x00ff0000L);
  173. _remappalette(c, rgb);
  174. }
  175. for (short y = 0; y < filehdrRead.sHeight; y++)
  176. {
  177. for (short x = 0; x < filehdrRead.sWidth; x++)
  178. {
  179. _setcolor((short)(pbPixels[y][x]));
  180. _setpixel(x, y);
  181. }
  182. }
  183. #endif
  184. ///////////////////////////////////////////////////////////////////////////////
  185. // EOF
  186. ///////////////////////////////////////////////////////////////////////////////