/src/FreeImage/Source/FreeImage/PluginMNG.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 153 lines · 83 code · 33 blank · 37 comment · 3 complexity · c79a17bb4a8767e10d3932f22a48518c MD5 · raw file

  1. // ==========================================================
  2. // MNG loader
  3. //
  4. // Design and implementation by
  5. // - Herve Drolon (drolon@infonie.fr)
  6. //
  7. // This file is part of FreeImage 3
  8. //
  9. // COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY
  10. // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES
  11. // THAT THE COVERED CODE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE
  12. // OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED
  13. // CODE IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT
  14. // THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY
  15. // SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL
  16. // PART OF THIS LICENSE. NO USE OF ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER
  17. // THIS DISCLAIMER.
  18. //
  19. // Use at your own risk!
  20. // ==========================================================
  21. #include "FreeImage.h"
  22. #include "Utilities.h"
  23. // ==========================================================
  24. // Plugin Interface
  25. // ==========================================================
  26. static int s_format_id;
  27. // ----------------------------------------------------------
  28. #define MNG_SIGNATURE_SIZE 8 // size of the signature
  29. // ----------------------------------------------------------
  30. // ----------------------------------------------------------
  31. // mng interface (see MNGHelper.cpp)
  32. // ----------------------------------------------------------
  33. FIBITMAP* mng_ReadChunks(int format_id, FreeImageIO *io, fi_handle handle, long Offset, int flags = 0);
  34. // ==========================================================
  35. // Plugin Implementation
  36. // ==========================================================
  37. static const char * DLL_CALLCONV
  38. Format() {
  39. return "MNG";
  40. }
  41. static const char * DLL_CALLCONV
  42. Description() {
  43. return "Multiple-image Network Graphics";
  44. }
  45. static const char * DLL_CALLCONV
  46. Extension() {
  47. return "mng";
  48. }
  49. static const char * DLL_CALLCONV
  50. RegExpr() {
  51. return NULL;
  52. }
  53. static const char * DLL_CALLCONV
  54. MimeType() {
  55. return "video/x-mng";
  56. }
  57. static BOOL DLL_CALLCONV
  58. Validate(FreeImageIO *io, fi_handle handle) {
  59. BYTE mng_signature[8] = { 138, 77, 78, 71, 13, 10, 26, 10 };
  60. BYTE signature[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
  61. io->read_proc(&signature, 1, MNG_SIGNATURE_SIZE, handle);
  62. return (memcmp(mng_signature, signature, MNG_SIGNATURE_SIZE) == 0) ? TRUE : FALSE;
  63. }
  64. static BOOL DLL_CALLCONV
  65. SupportsExportDepth(int depth) {
  66. return FALSE;
  67. }
  68. static BOOL DLL_CALLCONV
  69. SupportsExportType(FREE_IMAGE_TYPE type) {
  70. return FALSE;
  71. }
  72. static BOOL DLL_CALLCONV
  73. SupportsICCProfiles() {
  74. return TRUE;
  75. }
  76. static BOOL DLL_CALLCONV
  77. SupportsNoPixels() {
  78. return FALSE;
  79. }
  80. // ----------------------------------------------------------
  81. static void * DLL_CALLCONV
  82. Open(FreeImageIO *io, fi_handle handle, BOOL read) {
  83. return NULL;
  84. }
  85. static void DLL_CALLCONV
  86. Close(FreeImageIO *io, fi_handle handle, void *data) {
  87. }
  88. static FIBITMAP * DLL_CALLCONV
  89. Load(FreeImageIO *io, fi_handle handle, int page, int flags, void *data) {
  90. long offset = MNG_SIGNATURE_SIZE; // move to skip first 8 bytes of signature
  91. // check the signature (8 bytes)
  92. if(Validate(io, handle) == FALSE) {
  93. return NULL;
  94. }
  95. // parse chunks and decode a jng or mng bitmap
  96. return mng_ReadChunks(s_format_id, io, handle, offset, flags);
  97. }
  98. // ==========================================================
  99. // Init
  100. // ==========================================================
  101. void DLL_CALLCONV
  102. InitMNG(Plugin *plugin, int format_id) {
  103. s_format_id = format_id;
  104. plugin->format_proc = Format;
  105. plugin->description_proc = Description;
  106. plugin->extension_proc = Extension;
  107. plugin->regexpr_proc = RegExpr;
  108. plugin->open_proc = Open;
  109. plugin->close_proc = Close;
  110. plugin->pagecount_proc = NULL;
  111. plugin->pagecapability_proc = NULL;
  112. plugin->load_proc = Load;
  113. plugin->save_proc = NULL;
  114. plugin->validate_proc = Validate;
  115. plugin->mime_proc = MimeType;
  116. plugin->supports_export_bpp_proc = SupportsExportDepth;
  117. plugin->supports_export_type_proc = SupportsExportType;
  118. plugin->supports_icc_profiles_proc = SupportsICCProfiles;
  119. plugin->supports_no_pixels_proc = SupportsNoPixels;
  120. }