Home My Page Projects Code Snippets Project Openings 3D graphics for Standard ML
Summary Activity SCM

SCM Repository

[sml3d] View of /trunk/sml3d/src/image-io/ktx-glue.c
ViewVC logotype

View of /trunk/sml3d/src/image-io/ktx-glue.c

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1337 - (download) (as text) (annotate)
Thu Mar 20 15:37:41 2014 UTC (4 years, 1 month ago) by jhr
File size: 1955 byte(s)
  Thinking about KTX file support; but it probably should be in a different
  library (textures vs. images)
/*! \file ktx-glue.c
 * \author John Reppy
 * Glue code for handling Khronos Texture Files (KTX format).  The format specification
 * can be found at http://www.khronos.org/opengles/sdk/tools/KTX/file_format_spec.

 * COPYRIGHT (c) 2013 The SML3d Project (http://sml3d.cs.uchicago.edu)
 * All rights reserved.

#include "sml3d-config.h"
#include <stdio.h>
#include <stdlib.h>
#include "image-io-glue.h"

/* The KTX file header */
typedef struct {
    unsigned char       identifier[12];		// file ID (see below)
    uint32_t		endianness;		// endianess constant
    uint32_t		glType;			// 0 for compressed, otherwise see Table 8.2
						// of OpenGL Spec 4.4
    uint32_t		glTypeSize;		// the data type size that should be used when
						// endianness conversion is required
    uint32_t		glFormat;		// 0 for compressed, otherwise see Table 8.3
						// of OpenGL Spec 4.4
    uint32_t		glInternalFormat;
    uint32_t		glBaseInternalFormat;
    uint32_t		pixelWidth;		// width of the texture image for level 0
    uint32_t		pixelHeight;		// height of the texture image for level 0
    uint32_t		pixelDepth;		// depth of the texture image for level 0
    uint32_t		numberOfArrayElements;	// 0 for non-texture array; otherwise the number
						// of array elements
    uint32_t		numberOfFaces;		// the number of cubemap faces (1 for non-cubemaps)
    uint32_t		numberOfMipmapLevels;	// 1 for non-mipmapped textures; otherwise the
						// number of mipmap levels 
    uint32_t		bytesOfKeyValueData;	// number of bytes of meta data
} KTXHeader_t;

// the value of the file identifier
static unsigned char[12] FileIdentifier = {
	0xAB, 0x4B, 0x54, 0x58,
	0x20, 0x31, 0x31, 0xBB,
	0x0D, 0x0A, 0x1A, 0x0A

// expected value of the endianness field
#define ENDIANNESS		0x04030201	// same byte order
#define ENDIANNESS_SWAP		0x01020304	// opposite byte order

// Read the header from a KTX file.
KTXHeader_t *ReadHeader (FILE *inS)


ViewVC Help
Powered by ViewVC 1.0.0