llimagetga.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * @file llimagetga.h
  3. * @brief Image implementation to compresses and decompressed TGA files.
  4. *
  5. * $LicenseInfo:firstyear=2001&license=viewergpl$
  6. *
  7. * Copyright (c) 2001-2009, Linden Research, Inc.
  8. *
  9. * Second Life Viewer Source Code
  10. * The source code in this file ("Source Code") is provided by Linden Lab
  11. * to you under the terms of the GNU General Public License, version 2.0
  12. * ("GPL"), unless you have obtained a separate licensing agreement
  13. * ("Other License"), formally executed by you and Linden Lab. Terms of
  14. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16. *
  17. * There are special exceptions to the terms and conditions of the GPL as
  18. * it is applied to this Source Code. View the full text of the exception
  19. * in the file doc/FLOSS-exception.txt in this software distribution, or
  20. * online at
  21. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22. *
  23. * By copying, modifying or distributing this software, you acknowledge
  24. * that you have read and understood your obligations described above,
  25. * and agree to abide by those obligations.
  26. *
  27. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29. * COMPLETENESS OR PERFORMANCE.
  30. * $/LicenseInfo$
  31. */
  32. #ifndef LL_LLIMAGETGA_H
  33. #define LL_LLIMAGETGA_H
  34. #include "llimage.h"
  35. // This class compresses and decompressed TGA (targa) files
  36. class LLImageTGA final : public LLImageFormatted
  37. {
  38. protected:
  39. LOG_CLASS(LLImageTGA);
  40. ~LLImageTGA() override;
  41. public:
  42. LLImageTGA();
  43. LLImageTGA(const std::string& file_name);
  44. std::string getExtension() override { return "tga"; }
  45. bool updateData() override;
  46. bool decode(LLImageRaw* raw_image) override;
  47. bool encode(const LLImageRaw* raw_image) override;
  48. bool decodeAndProcess(LLImageRaw* raw_image, F32 domain, F32 weight);
  49. private:
  50. bool decodeTruecolor(LLImageRaw* raw_image, bool rle, bool flipped);
  51. bool decodeTruecolorRle8(LLImageRaw* raw_image);
  52. bool decodeTruecolorRle15(LLImageRaw* raw_image);
  53. bool decodeTruecolorRle24(LLImageRaw* raw_image);
  54. bool decodeTruecolorRle32(LLImageRaw* raw_image, bool& alpha_opaque);
  55. void decodeTruecolorPixel15(U8* dst, const U8* src);
  56. bool decodeTruecolorNonRle(LLImageRaw* raw_image, bool& alpha_opaque);
  57. bool decodeColorMap(LLImageRaw* raw_image, bool rle, bool flipped);
  58. void decodeColorMapPixel8(U8* dst, const U8* src);
  59. void decodeColorMapPixel15(U8* dst, const U8* src);
  60. void decodeColorMapPixel24(U8* dst, const U8* src);
  61. void decodeColorMapPixel32(U8* dst, const U8* src);
  62. bool loadFile(const std::string& file_name);
  63. private:
  64. U32 mDataOffset; // Offset from start of data to the actual header.
  65. // Data from header
  66. U8 mIDLength; // Length of identifier string
  67. U8 mColorMapType; // 0 = No Map
  68. // Supported: 2 = Uncompressed true color, 3 = uncompressed monochrome
  69. // without colormap:
  70. U8 mImageType;
  71. U8 mColorMapIndexLo; // First color map entry (low order byte)
  72. U8 mColorMapIndexHi; // First color map entry (high order byte)
  73. U8 mColorMapLengthLo; // Color map length (low order byte)
  74. U8 mColorMapLengthHi; // Color map length (high order byte)
  75. U8 mColorMapDepth; // Size of color map entry (15, 16, 24, or 32 bits)
  76. U8 mXOffsetLo; // X offset of image (low order byte)
  77. U8 mXOffsetHi; // X offset of image (hi order byte)
  78. U8 mYOffsetLo; // Y offset of image (low order byte)
  79. U8 mYOffsetHi; // Y offset of image (hi order byte)
  80. U8 mWidthLo; // Width (low order byte)
  81. U8 mWidthHi; // Width (hi order byte)
  82. U8 mHeightLo; // Height (low order byte)
  83. U8 mHeightHi; // Height (hi order byte)
  84. U8 mPixelSize; // 8, 16, 24, 32 bits per pixel
  85. U8 mAttributeBits; // 4 bits: number of attributes per pixel
  86. U8 mOriginRightBit; // 1 bit: origin, 0 = left, 1 = right
  87. U8 mOriginTopBit; // 1 bit: origin, 0 = bottom, 1 = top
  88. // 2 bits: interleaved flag, 0 = none, 1 = interleaved 2, 2 = interleaved 4
  89. U8 mInterleave;
  90. U8* mColorMap;
  91. S32 mColorMapStart;
  92. S32 mColorMapLength;
  93. S32 mColorMapBytesPerEntry;
  94. bool mIs15Bit;
  95. static const U8 s5to8bits[32];
  96. };
  97. #endif