virtual_image.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. XCC Utilities and Library
  3. Copyright (C) 2000 Olaf van der Spek <[email protected]>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #pragma once
  16. #include "cc_file.h"
  17. #include "palet.h"
  18. #include "virtual_file.h"
  19. class Cvirtual_image
  20. {
  21. public:
  22. const Cvirtual_image& palet(const t_palet_entry* palet, bool inflate = false);
  23. void remove_alpha();
  24. void add_alpha();
  25. void cb_pixel(int cb_pixel, const t_palet_entry* palet = NULL);
  26. void decrease_color_depth(int cb_pixel, const t_palet_entry* palet = NULL);
  27. void increase_color_depth(int cb_pixel);
  28. void increase_palet_depth();
  29. void flip();
  30. int get_clipboard();
  31. int set_clipboard() const;
  32. int load();
  33. int save() const;
  34. void load(const Cvirtual_binary& image, int cx, int cy, int cb_pixel, const t_palet_entry* palet, bool inflate = false);
  35. void load(const void* image, int cx, int cy, int cb_pixel, const t_palet_entry* palet, bool inflate = false);
  36. int load(const Cvirtual_binary& s);
  37. int load(const Cvirtual_file& f);
  38. int load(const string& fname);
  39. int save(Cvirtual_file& f, t_file_type ft) const;
  40. Cvirtual_file save(t_file_type ft) const;
  41. int save(const string& fname, t_file_type ft) const;
  42. void swap_rb();
  43. Cvirtual_image() = default;
  44. Cvirtual_image(const Cvirtual_binary& image, int cx, int cy, int cb_pixel, const t_palet_entry* palet = NULL, bool inflate = false);
  45. Cvirtual_image(const void* image, int cx, int cy, int cb_pixel, const t_palet_entry* palet = NULL, bool inflate = false);
  46. const byte* image() const
  47. {
  48. return m_image.data();
  49. }
  50. byte* image_edit()
  51. {
  52. return m_image.data_edit();
  53. }
  54. int cx() const
  55. {
  56. return m_cx;
  57. }
  58. int cy() const
  59. {
  60. return m_cy;
  61. }
  62. int cb_pixel() const
  63. {
  64. return mcb_pixel;
  65. }
  66. const t_palet_entry* palet() const
  67. {
  68. return reinterpret_cast<const t_palet_entry*>(m_palet.data());
  69. }
  70. int cb_image() const
  71. {
  72. return m_cx * m_cy * mcb_pixel;
  73. }
  74. int ofs8(int x, int y) const
  75. {
  76. return x + m_cx * y;
  77. }
  78. int ofs24(int x, int y) const
  79. {
  80. return ofs8(x, y) * 3;
  81. }
  82. int pixel8(int x, int y) const
  83. {
  84. return m_image.data()[ofs8(x, y)];
  85. }
  86. void pixel8(int x, int y, int v)
  87. {
  88. m_image.data_edit()[ofs8(x, y)] = v;
  89. }
  90. t_palet_entry pixel24(int x, int y) const
  91. {
  92. return reinterpret_cast<const t_palet_entry*>(m_image.data())[ofs8(x, y)];
  93. }
  94. void pixel24(int x, int y, t_palet_entry v)
  95. {
  96. reinterpret_cast<t_palet_entry*>(m_image.data_edit())[ofs8(x, y)] = v;
  97. }
  98. private:
  99. Cvirtual_binary m_image;
  100. Cvirtual_binary m_palet;
  101. int m_cx = 0;
  102. int m_cy = 0;
  103. int mcb_pixel = 0;
  104. };