Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <vector>
- static const unsigned char ddsHeader[128] =
- {
- 0x44, 0x44, 0x53, 0x20, 0x7C, 0x00, 0x00, 0x00,
- 0x0F, 0x10, 0x02, 0x00, 0x21, 0x19, 0x00, 0x00,
- 0x21, 0x19, 0x00, 0x00, 0x84, 0x64, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x4E, 0x56, 0x54, 0x33,
- 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
- 0x04, 0x00, 0x00, 0x00, 0x72, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
- };
- int main(int argc, char **argv)
- {
- if (argc != 3)
- return 1;
- std::vector< unsigned short > inBuf(6432 * 6432 + 64, 0);
- std::vector< unsigned int > outBuf(6433 * 6433 + 32, 0);
- std::FILE *f = std::fopen(argv[1], "rb");
- if (!f)
- return 1;
- std::fread(inBuf.data(), sizeof(unsigned short), inBuf.size(), f);
- std::fclose(f);
- for (unsigned int i = 0; i < 128; i++)
- outBuf[i >> 2] |= (unsigned int) ddsHeader[i] << ((i & 3) << 3);
- for (int y = 0; y < 6433; y++)
- {
- for (int x = 0; x < 6433; x++)
- {
- int xc = x + 16;
- int yc = y - 16;
- xc = (xc > 0 ? (xc < 6431 ? xc : 6431) : 0);
- yc = (yc > 0 ? (yc < 6431 ? yc : 6431) : 0);
- int c = inBuf[yc * 6432 + xc + 64];
- union
- {
- unsigned int n;
- float f;
- }
- tmp;
- tmp.f = float(c) / 65535.0f;
- outBuf[y * 6433 + x + 32] = tmp.n;
- }
- }
- f = std::fopen(argv[2], "wb");
- if (!f)
- return 1;
- std::fwrite(outBuf.data(), sizeof(unsigned int), outBuf.size(), f);
- std::fclose(f);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment