-
Notifications
You must be signed in to change notification settings - Fork 15
/
dxt_tester.cpp
66 lines (53 loc) · 1.74 KB
/
dxt_tester.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "fast_dct.h"
#include <cassert>
#include <cstdint>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
// #define VERBOSE
#include "encoder.h"
#include "decoder.h"
#include "gpu.h"
#include "kernel_cache.h"
#ifndef _MSC_VER
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#pragma warning(disable: 4996)
#endif
#define STB_IMAGE_WRITE_IMPLEMENTATION
#include "stb_image_write.h"
#ifndef _MSC_VER
#pragma GCC diagnostic pop
#else
#pragma warning(default: 4996)
#endif
int main(int argc, char **argv) {
// Make sure that we have the proper number of arguments...
if (argc != 2 && argc != 3) {
std::cerr << "Usage: " << argv[0] << "<original> [compressed]" << std::endl;
return 1;
}
std::unique_ptr<gpu::GPUContext> ctx = gpu::GPUContext::InitializeOpenCL(false);
const char *orig_fn = argv[1];
const char *cmp_fn = (argc == 2) ? NULL : argv[2];
#if 0
GenTC::DXTImage dxt_img = GenTC::DXTImage(orig_fn, cmp_fn);
#else
std::vector<uint8_t> cmp_img = GenTC::CompressDXT(orig_fn, cmp_fn);
GenTC::DXTImage dxt_img = GenTC::DecompressDXT(ctx, cmp_img);
#endif
// Decompress into image...
std::vector<uint8_t> decomp_rgba = dxt_img.DecompressedImage()->Pack();
stbi_write_png("img_dxt.png", dxt_img.Width(), dxt_img.Height(), 4, decomp_rgba.data(), 4 * dxt_img.Width());
// Visualize interpolation data...
std::vector<uint8_t> interp_img_data = std::move(dxt_img.InterpolationImage());
stbi_write_png("img_dxt_interp.png", dxt_img.Width(), dxt_img.Height(), 1, interp_img_data.data(), dxt_img.Width());
clFlush(ctx->GetDefaultCommandQueue());
clFinish(ctx->GetDefaultCommandQueue());
gpu::GPUKernelCache::Clear();
return 0;
}