Guest User

f76hmto4.cpp

a guest
Dec 27th, 2022
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.96 KB | None | 0 0
  1. #include <cstdio>
  2. #include <vector>
  3.  
  4. static const unsigned char ddsHeader[128] =
  5. {
  6.   0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00,
  7.   0x0F, 0x10, 0x02, 0x00, 0x21, 0x19, 0x00, 0x00,
  8.   0x21, 0x19, 0x00, 0x00, 0x84, 0x64, 0x00, 0x00,
  9.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  10.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  11.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  12.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  13.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  14.   0x00, 0x00, 0x00, 0x00, 0x4E, 0x56, 0x54, 0x33,
  15.   0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  16.   0x04, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00,
  17.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  18.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  19.   0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
  20.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  21.   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  22. };
  23.  
  24. int main(int argc, char **argv)
  25. {
  26.   if (argc != 3)
  27.     return 1;
  28.   std::vector< unsigned short > inBuf(6432 * 6432 + 64, 0);
  29.   std::vector< unsigned int > outBuf(6433 * 6433 + 32, 0);
  30.   std::FILE *f = std::fopen(argv[1], "rb");
  31.   if (!f)
  32.     return 1;
  33.   std::fread(inBuf.data(), sizeof(unsigned short), inBuf.size(), f);
  34.   std::fclose(f);
  35.   for (unsigned int i = 0; i < 128; i++)
  36.     outBuf[i >> 2] |= (unsigned int) ddsHeader[i] << ((i & 3) << 3);
  37.   for (int y = 0; y < 6433; y++)
  38.   {
  39.     for (int x = 0; x < 6433; x++)
  40.     {
  41.       int     xc = x + 16;
  42.       int     yc = y - 16;
  43.       xc = (xc > 0 ? (xc < 6431 ? xc : 6431) : 0);
  44.       yc = (yc > 0 ? (yc < 6431 ? yc : 6431) : 0);
  45.       int     c = inBuf[yc * 6432 + xc + 64];
  46.       union
  47.       {
  48.         unsigned int  n;
  49.         float   f;
  50.       }
  51.       tmp;
  52.       tmp.f = float(c) / 65535.0f;
  53.       outBuf[y * 6433 + x + 32] = tmp.n;
  54.     }
  55.   }
  56.   f = std::fopen(argv[2], "wb");
  57.   if (!f)
  58.     return 1;
  59.   std::fwrite(outBuf.data(), sizeof(unsigned int), outBuf.size(), f);
  60.   std::fclose(f);
  61.   return 0;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment