TimToVram.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <OgreStringConverter.h>
  16. #include "TimToVram.h"
  17. #include "Logger.h"
  18. #include "common/File.h"
  19. void LoadTimFileToVram(File* file, int tim_offset, Vram* vram){
  20. LOGGER->Log(
  21. "Load image at offset " + HexToString(tim_offset, 4, '0') + " to VRAM.\n"
  22. );
  23. int next_offset = file->GetU32LE(tim_offset + 0x08);
  24. int clut_vram_position_x = file->GetU16LE(tim_offset + 0x0c);
  25. int clut_vram_position_y = file->GetU16LE(tim_offset + 0x0e);
  26. int clut_width = file->GetU16LE(tim_offset + 0x10);
  27. int clut_height = file->GetU16LE(tim_offset + 0x12);
  28. LOGGER->Log(
  29. "ClutVramPositionX (" + HexToString(clut_vram_position_x, 4, '0')
  30. + ") ClutVramPositionY (" + HexToString(clut_vram_position_y, 4, '0')
  31. + ") Width (" + HexToString(clut_width, 4, '0') + ") Height ("
  32. + HexToString(clut_height, 4, '0') + ")\n"
  33. );
  34. for (int y = 0; y < clut_height; ++ y){
  35. for (int x = 0; x < clut_width; ++ x){
  36. u16 color = file->GetU16LE(
  37. tim_offset + 0x14 + y * clut_width * 2 + x * 2
  38. );
  39. vram->PutU16(
  40. x * 2 + clut_vram_position_x, y + clut_vram_position_y, color
  41. );
  42. }
  43. }
  44. /*
  45. while (next_offset != 0){
  46. */
  47. // Set image buffer
  48. int image_vram_position_x
  49. = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x4) * 2;
  50. int image_vram_position_y
  51. = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x6);
  52. int image_width = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x8) * 2;
  53. int image_height = file->GetU16LE(tim_offset + 0x08 + next_offset + 0xa);
  54. LOGGER->Log(
  55. "ImageVramPositionX (" + HexToString(image_vram_position_x, 4, '0')
  56. + ") ImageVramPositionY (" + HexToString(image_vram_position_y, 4, '0')
  57. + ") ImageWidth (" + HexToString(image_width, 4, '0') + ") ImageHeight ("
  58. + HexToString(image_height, 4, '0') + ")\n"
  59. );
  60. for (int y = 0; y < image_height; ++ y){
  61. for (int x = 0; x < image_width; ++ x){
  62. u8 data = file->GetU8(
  63. tim_offset + 0x08 + next_offset + 0xc + y * image_width + x
  64. );
  65. vram->PutU8(
  66. x + image_vram_position_x, y + image_vram_position_y, data
  67. );
  68. }
  69. }
  70. /*
  71. }
  72. */
  73. //next_offset = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x0);
  74. }