CALLBACK.CPP 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. # include <stdlib.h>
  5. #include "Main.h"
  6. //---------------------------------------------------------------------------
  7. mng_ptr __stdcall TMainForm::Alloc( mng_size_t iSize )
  8. {
  9. return (mng_ptr)calloc( 1, (size_t)iSize );
  10. }
  11. //---------------------------------------------------------------------------
  12. void __stdcall TMainForm::Free( mng_ptr pPtr, mng_size_t iSize )
  13. {
  14. free( pPtr );
  15. return;
  16. }
  17. //---------------------------------------------------------------------------
  18. mng_bool __stdcall TMainForm::FileReadData( mng_handle hMNG,
  19. mng_ptr pBuf,
  20. mng_uint32 iSize,
  21. mng_uint32 *iRead )
  22. {
  23. TMainForm *MainForm = (TMainForm *)mng_get_userdata( hMNG );
  24. *iRead = fread( pBuf, 1, iSize, MainForm->GetFd() );
  25. // iRead will indicate EOF
  26. MainForm->ProgressBar1->Position += (int)iRead;
  27. return MNG_TRUE;
  28. }
  29. //---------------------------------------------------------------------------
  30. mng_bool __stdcall TMainForm::ProcessHeader( mng_handle hHandle,
  31. mng_uint32 iWidth,
  32. mng_uint32 iHeight )
  33. {
  34. TMainForm *MainForm = (TMainForm *)mng_get_userdata( hHandle );
  35. MainForm->Caption = ExtractFileName( MainForm->OpenDialog1->FileName ) +
  36. " [" +
  37. String( iWidth ) +
  38. "x" +
  39. String( iHeight ) +
  40. "]";
  41. Application->Title = MainForm->asAppName + " " + MainForm->Caption;
  42. MainForm->ProgressBar1->Max = iWidth * iHeight;
  43. return MNG_TRUE;
  44. }
  45. //---------------------------------------------------------------------------
  46. mng_bool __stdcall TMainForm::OpenStream( mng_handle hMNG )
  47. {
  48. // nothing to do !
  49. return MNG_TRUE;
  50. }
  51. //---------------------------------------------------------------------------
  52. mng_bool __stdcall TMainForm::CloseStream( mng_handle hMNG )
  53. {
  54. MainForm->ProgressBar1->Position = 0;
  55. return MNG_TRUE;
  56. }
  57. //---------------------------------------------------------------------------
  58. mng_bool __stdcall TMainForm::IterateChunks( mng_handle hMNG,
  59. mng_handle hChunk,
  60. mng_chunkid iChunktype,
  61. mng_uint32 iChunkseq )
  62. {
  63. TMainForm *MainForm = (TMainForm *)mng_get_userdata( hMNG );
  64. char aCh[5];
  65. // decode the chunkname
  66. aCh[0] = (char)((iChunktype >> 24) & 0xFF);
  67. aCh[1] = (char)((iChunktype >> 16) & 0xFF);
  68. aCh[2] = (char)((iChunktype >> 8) & 0xFF);
  69. aCh[3] = (char)((iChunktype ) & 0xFF);
  70. aCh[4] = (char)0; // zero terminate - used as a "C" string below
  71. MainForm->RichEditReport->Lines->Add( "" );
  72. MainForm->RichEditReport->Lines->Add(
  73. "Chunk " + String( iChunkseq + 1 ) + " : " + String( aCh ) );
  74. // Add Chunk text to listbox
  75. MainForm->ListBoxChunks->Items->Add( aCh );
  76. // keep'm coming ... unless we encounter an error
  77. return MainForm->ShowChunk( hMNG, hChunk, iChunktype );
  78. }
  79. //---------------------------------------------------------------------------