Turo Lamminen
2015-04-29 467597813b3cc624d99a87ef268e0b23b2c48c97

ddsinfo now shows all miplevel sizes

1 files modified
27 ■■■■■ changed files
ddsinfo.c 27 ●●●●● patch | view | raw | blame | history
ddsinfo.c
@@ -1,10 +1,17 @@
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mojodds.h"
// from http://graphics.stanford.edu/~seander/bithacks.html
static bool isPow2(unsigned int v) {
    return v && !(v & (v - 1));
}
int main(int argc, char *argv[]) {
@@ -43,12 +50,30 @@
        int retval = MOJODDS_getTexture(contents, size, &tex, &texlen, &glfmt, &w, &h, &miplevels);
        uintptr_t texoffset = ((const char *)(tex)) - contents;
        printf("retval: %d\n", retval);
        printf("MOJODDS_getTexture retval: %d\n", retval);
        printf("texoffset: %u\n", (unsigned int)(texoffset));
        printf("texlen: %lu\n", texlen);
        printf("glfmt: 0x%x\n", glfmt);
        printf("width x height: %d x %d\n", w, h);
        printf("miplevels: %d\n", miplevels);
        printf("\n");
        for (unsigned int miplevel = 0; miplevel < miplevels; miplevel++) {
            const void *miptex = NULL;
            unsigned long miptexlen = 0;
            unsigned int mipW = 0, mipH = 0;
            retval = MOJODDS_getMipMapTexture(miplevel, glfmt, tex, texlen, w, h, &miptex, &miptexlen, &mipW, &mipH);
            if (!retval) {
                printf("MOJODDS_getMipMapTexture(%u) error: %d\n", miplevel, retval);
                continue;
            }
            uintptr_t miptexoffset = ((const char *)(miptex)) - ((const char *)(tex));
            bool npot = !(isPow2(mipW) || isPow2(mipH));
            printf("%4d x %4d  %s", mipW, mipH, npot ? "NPOT  " : "      ");
            printf("miptexoffset: %8u  ", (unsigned int)(miptexoffset));
            printf("miptexlen: %8lu\n", miptexlen);
        }
    }
    free(contents);