PageRenderTime 19ms CodeModel.GetById 9ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/llimage/llimagedimensionsinfo.h

https://bitbucket.org/lindenlab/viewer-beta/
C Header | 136 lines | 85 code | 21 blank | 30 comment | 1 complexity | 5c00898b9d606f4c03a60698d9c822ef MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llimagedimentionsinfo.h
  3. *
  4. * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  5. * Second Life Viewer Source Code
  6. * Copyright (C) 2010, Linden Research, Inc.
  7. *
  8. * This library is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU Lesser General Public
  10. * License as published by the Free Software Foundation;
  11. * version 2.1 of the License only.
  12. *
  13. * This library is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * Lesser General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Lesser General Public
  19. * License along with this library; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  23. * $/LicenseInfo$
  24. */
  25. #ifndef LL_LLIMAGEDIMENSIONSINFO_H
  26. #define LL_LLIMAGEDIMENSIONSINFO_H
  27. //-----------------------------------------------------------------------------
  28. // LLImageDimensionsInfo
  29. // helper class to get image dimensions WITHOUT loading image to memore
  30. // usefull when image may be too large...
  31. //-----------------------------------------------------------------------------
  32. class LLImageDimensionsInfo
  33. {
  34. public:
  35. LLImageDimensionsInfo():
  36. mData(NULL)
  37. ,mHeight(0)
  38. ,mWidth(0)
  39. {}
  40. ~LLImageDimensionsInfo()
  41. {
  42. clean();
  43. }
  44. bool load(const std::string& src_filename,U32 codec);
  45. S32 getWidth() const { return mWidth;}
  46. S32 getHeight() const { return mHeight;}
  47. const std::string& getLastError()
  48. {
  49. return mLastError;
  50. }
  51. protected:
  52. void clean()
  53. {
  54. mInfile.close();
  55. delete[] mData;
  56. mData = NULL;
  57. mWidth = 0;
  58. mHeight = 0;
  59. }
  60. U8* getData()
  61. {
  62. return mData;
  63. }
  64. void setLastError(const std::string& message, const std::string& filename)
  65. {
  66. std::string error = message;
  67. if (!filename.empty())
  68. error += std::string(" FILE: ") + filename;
  69. mLastError = error;
  70. }
  71. bool getImageDimensionsBmp();
  72. bool getImageDimensionsTga();
  73. bool getImageDimensionsPng();
  74. bool getImageDimensionsJpeg();
  75. S32 read_s32()
  76. {
  77. char p[4];
  78. mInfile.read(&p[0],4);
  79. S32 temp = (((S32)p[3]) & 0x000000FF) |
  80. (((S32)p[2] << 8 ) & 0x0000FF00) |
  81. (((S32)p[1] << 16) & 0x00FF0000) |
  82. (((S32)p[0] << 24) & 0xFF000000);
  83. return temp;
  84. }
  85. S32 read_reverse_s32()
  86. {
  87. char p[4];
  88. mInfile.read(&p[0],4);
  89. S32 temp = (((S32)p[0]) & 0x000000FF) |
  90. (((S32)p[1] << 8 ) & 0x0000FF00) |
  91. (((S32)p[2] << 16) & 0x00FF0000) |
  92. (((S32)p[3] << 24) & 0xFF000000);
  93. return temp;
  94. }
  95. U8 read_byte()
  96. {
  97. U8 bt;
  98. mInfile.read(&bt,1);
  99. return bt;
  100. }
  101. U16 read_short()
  102. {
  103. return read_byte() << 8 | read_byte();
  104. }
  105. /// Check if the file is not shorter than min_len bytes.
  106. bool checkFileLength(S32 min_len);
  107. protected:
  108. LLAPRFile mInfile ;
  109. std::string mSrcFilename;
  110. std::string mLastError;
  111. U8* mData;
  112. S32 mWidth;
  113. S32 mHeight;
  114. };
  115. #endif