llpngwrapper.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * @file llpngwrapper.h
  3. *
  4. * $LicenseInfo:firstyear=2007&license=viewergpl$
  5. *
  6. * Copyright (c) 2007-2009, Linden Research, Inc.
  7. *
  8. * Second Life Viewer Source Code
  9. * The source code in this file ("Source Code") is provided by Linden Lab
  10. * to you under the terms of the GNU General Public License, version 2.0
  11. * ("GPL"), unless you have obtained a separate licensing agreement
  12. * ("Other License"), formally executed by you and Linden Lab. Terms of
  13. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  14. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  15. *
  16. * There are special exceptions to the terms and conditions of the GPL as
  17. * it is applied to this Source Code. View the full text of the exception
  18. * in the file doc/FLOSS-exception.txt in this software distribution, or
  19. * online at
  20. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  21. *
  22. * By copying, modifying or distributing this software, you acknowledge
  23. * that you have read and understood your obligations described above,
  24. * and agree to abide by those obligations.
  25. *
  26. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  27. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  28. * COMPLETENESS OR PERFORMANCE.
  29. * $/LicenseInfo$
  30. */
  31. #ifndef LL_LLPNGWRAPPER_H
  32. #define LL_LLPNGWRAPPER_H
  33. #include "png.h"
  34. #include "llimage.h"
  35. class LLPngWrapper
  36. {
  37. protected:
  38. LOG_CLASS(LLPngWrapper);
  39. void normalizeImage();
  40. void updateMetaData();
  41. public:
  42. LLPngWrapper();
  43. ~LLPngWrapper();
  44. struct ImageInfo
  45. {
  46. U16 mWidth;
  47. U16 mHeight;
  48. S8 mComponents;
  49. };
  50. bool isValidPng(U8* src);
  51. bool readPng(U8* src, S32 dataSize, LLImageRaw* rawImage,
  52. ImageInfo* infop = NULL);
  53. bool writePng(const LLImageRaw* rawImage, U8* dst);
  54. LL_INLINE U32 getFinalSize() { return mFinalSize; }
  55. LL_INLINE const std::string& getErrorMessage() { return mErrorMessage; }
  56. private:
  57. // Structure for writing/reading PNG data to/from memory as opposed to
  58. // using a file.
  59. struct PngDataInfo
  60. {
  61. U8* mData;
  62. U32 mOffset;
  63. S32 mDataSize;
  64. };
  65. // No-op since we are just writing to memory
  66. LL_INLINE static void writeFlush(png_structp png_ptr)
  67. {
  68. }
  69. static void errorHandler(png_structp png_ptr, png_const_charp msg);
  70. static void readDataCallback(png_structp png_ptr, png_bytep dest,
  71. png_size_t length);
  72. static void writeDataCallback(png_structp png_ptr, png_bytep src,
  73. png_size_t length);
  74. void releaseResources();
  75. private:
  76. png_structp mReadPngPtr;
  77. png_infop mReadInfoPtr;
  78. png_structp mWritePngPtr;
  79. png_infop mWriteInfoPtr;
  80. U8** mRowPointers;
  81. png_uint_32 mWidth;
  82. png_uint_32 mHeight;
  83. S32 mBitDepth;
  84. S32 mColorType;
  85. S32 mChannels;
  86. S32 mInterlaceType;
  87. S32 mCompressionType;
  88. S32 mFilterMethod;
  89. U32 mFinalSize;
  90. F64 mGamma;
  91. std::string mErrorMessage;
  92. };
  93. #endif