TimToVram.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "TimToVram.h"
  2. #include <OgreStringConverter.h>
  3. #include "Logger.h"
  4. #include "common/File.h"
  5. void
  6. LoadTimFileToVram(File* file, int tim_offset, Vram* vram)
  7. {
  8. LOGGER->Log("Load image at offset " + HexToString(tim_offset, 4, '0') + " to VRAM.\n");
  9. int next_offset = file->GetU32LE(tim_offset + 0x08);
  10. int clut_vram_position_x = file->GetU16LE(tim_offset + 0x0c);
  11. int clut_vram_position_y = file->GetU16LE(tim_offset + 0x0e);
  12. int clut_width = file->GetU16LE(tim_offset + 0x10);
  13. int clut_height = file->GetU16LE(tim_offset + 0x12);
  14. LOGGER->Log("ClutVramPositionX (" + HexToString(clut_vram_position_x, 4, '0') + ") ClutVramPositionY (" + HexToString(clut_vram_position_y, 4, '0') + ") Width (" + HexToString(clut_width, 4, '0') + ") Height (" + HexToString(clut_height, 4, '0') + ")\n");
  15. for (int y = 0; y < clut_height; ++y)
  16. {
  17. for (int x = 0; x < clut_width; ++x)
  18. {
  19. u16 color = file->GetU16LE(tim_offset + 0x14 + y * clut_width * 2 + x * 2);
  20. vram->PutU16(x * 2 + clut_vram_position_x, y + clut_vram_position_y, color);
  21. }
  22. }
  23. //while (next_offset != 0)
  24. {
  25. // set image buffer
  26. int image_vram_position_x = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x4) * 2;
  27. int image_vram_position_y = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x6);
  28. int image_width = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x8) * 2;
  29. int image_height = file->GetU16LE(tim_offset + 0x08 + next_offset + 0xa);
  30. LOGGER->Log("ImageVramPositionX (" + HexToString(image_vram_position_x, 4, '0') + ") ImageVramPositionY (" + HexToString(image_vram_position_y, 4, '0') + ") ImageWidth (" + HexToString(image_width, 4, '0') + ") ImageHeight (" + HexToString(image_height, 4, '0') + ")\n");
  31. for (int y = 0; y < image_height; ++y)
  32. {
  33. for (int x = 0; x < image_width; ++x)
  34. {
  35. u8 data = file->GetU8(tim_offset + 0x08 + next_offset + 0xc + y * image_width + x);
  36. vram->PutU8(x + image_vram_position_x, y + image_vram_position_y, data);
  37. }
  38. }
  39. //next_offset = file->GetU16LE(tim_offset + 0x08 + next_offset + 0x0);
  40. }
  41. }