pal_file.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include "stdafx.h"
  16. #include "pal_file.h"
  17. #include <fstream>
  18. bool Cpal_file::is_valid() const
  19. {
  20. if (get_size() != sizeof(t_palet))
  21. return false;
  22. const t_palet_entry* p = get_palet();
  23. for (int i = 0; i < 256; i++)
  24. {
  25. if ((p[i].r | p[i].g | p[i].b) & 0xc0)
  26. return false;
  27. }
  28. return true;
  29. }
  30. ostream& Cpal_file::extract_as_pal_jasc(ostream& os, bool shift_left) const
  31. {
  32. os << "JASC-PAL" << endl
  33. << "0100" << endl
  34. << "256" << endl;
  35. t_palet palet;
  36. if (shift_left)
  37. convert_palet_18_to_24(get_palet(), palet);
  38. else
  39. memcpy(palet, get_palet(), sizeof(t_palet));
  40. for (int i = 0; i < 256; i++)
  41. os << static_cast<int>(palet[i].r) << ' ' << static_cast<int>(palet[i].g) << ' ' << static_cast<int>(palet[i].b) << endl;
  42. return os;
  43. }