/indra/llimage/llimagejpeg.h

https://bitbucket.org/lindenlab/viewer-beta/ · C++ Header · 86 lines · 44 code · 16 blank · 26 comment · 0 complexity · 3339227099f727c2947bf47e3b0a23d0 MD5 · raw file

  1. /**
  2. * @file llimagejpeg.h
  3. * @brief This class compresses and decompresses JPEG files
  4. *
  5. * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2010, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #ifndef LL_LLIMAGEJPEG_H
  27. #define LL_LLIMAGEJPEG_H
  28. #include <csetjmp>
  29. #include "llimage.h"
  30. extern "C" {
  31. #ifdef LL_STANDALONE
  32. # include <jpeglib.h>
  33. # include <jerror.h>
  34. #else
  35. # include "jpeglib/jpeglib.h"
  36. # include "jpeglib/jerror.h"
  37. #endif
  38. }
  39. class LLImageJPEG : public LLImageFormatted
  40. {
  41. protected:
  42. virtual ~LLImageJPEG();
  43. public:
  44. LLImageJPEG(S32 quality = 75);
  45. /*virtual*/ std::string getExtension() { return std::string("jpg"); }
  46. /*virtual*/ BOOL updateData();
  47. /*virtual*/ BOOL decode(LLImageRaw* raw_image, F32 decode_time);
  48. /*virtual*/ BOOL encode(const LLImageRaw* raw_image, F32 encode_time);
  49. void setEncodeQuality( S32 q ) { mEncodeQuality = q; } // on a scale from 1 to 100
  50. S32 getEncodeQuality() { return mEncodeQuality; }
  51. // Callbacks registered with jpeglib
  52. static void encodeInitDestination ( j_compress_ptr cinfo );
  53. static boolean encodeEmptyOutputBuffer(j_compress_ptr cinfo);
  54. static void encodeTermDestination(j_compress_ptr cinfo);
  55. static void decodeInitSource(j_decompress_ptr cinfo);
  56. static boolean decodeFillInputBuffer(j_decompress_ptr cinfo);
  57. static void decodeSkipInputData(j_decompress_ptr cinfo, long num_bytes);
  58. static void decodeTermSource(j_decompress_ptr cinfo);
  59. static void errorExit(j_common_ptr cinfo);
  60. static void errorEmitMessage(j_common_ptr cinfo, int msg_level);
  61. static void errorOutputMessage(j_common_ptr cinfo);
  62. static BOOL decompress(LLImageJPEG* imagep);
  63. protected:
  64. U8* mOutputBuffer; // temp buffer used during encoding
  65. S32 mOutputBufferSize; // bytes in mOuputBuffer
  66. S32 mEncodeQuality; // on a scale from 1 to 100
  67. private:
  68. static jmp_buf sSetjmpBuffer; // To allow the library to abort.
  69. };
  70. #endif // LL_LLIMAGEJPEG_H