File: voltex.c

package info (click to toggle)
devil 1.6.7-5%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 11,536 kB
  • ctags: 7,441
  • sloc: ansic: 35,573; sh: 8,075; cpp: 7,465; pascal: 792; makefile: 399; python: 47
file content (114 lines) | stat: -rw-r--r-- 2,986 bytes parent folder | download | duplicates (5)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//-----------------------------------------------------------------------------
//
// DevIL Volume Texture Splitter
// Copyright (C) 2000-2002 by Denton Woods
// Last modified:  4/22/2002 <--Y2K Compliant! =]
//
// Filename: test/VolTex/VolTex.c
//
// Description: Splits a volume texture into its individual slices
//              and saves them to separate files for analysis.
//
//-----------------------------------------------------------------------------

// Required include files.
#include <IL/il.h>
#include <IL/ilu.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char **argv)
{
	ILuint	i;
	ILuint	ImgId, id;
	ILenum	Error;
	char	FileName[256], FileNameNum[256], FName[256], Ext[256];
	ILuint	PlaneSize;
	ILubyte	*Data;
	ILinfo	Info;

	// We use the filename specified in the first argument of the command-line.
	if (argc < 2) {
		fprintf(stderr, "VolTex : DevIL volume texture application.\n");
		fprintf(stderr, "Usage : VolTex <file> [output]\n");
		fprintf(stderr, "Default output is test1-n.tga\n");
		return 1;
	}

	// Check if the shared lib's version matches the executable's version.
	if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
		iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
		printf("DevIL version is different...exiting!\n");
		return 2;
	}

	// Initialize DevIL.
	ilInit();

	// Generate the main image name to use.
	ilGenImages(1, &ImgId);

	// Bind this image name.
	ilBindImage(ImgId);

	// Loads the image specified by File into the image named by ImgId.
	if (!ilLoadImage(argv[1])) {
		printf("Could not open file...exiting.\n");
		return 3;
	}

	// Display the image's dimensions to the end user.
	printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n",
	       ilGetInteger(IL_IMAGE_WIDTH),
	       ilGetInteger(IL_IMAGE_HEIGHT),
	       ilGetInteger(IL_IMAGE_DEPTH),
	       ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL));

	// Enable this to let us overwrite the destination file if it already exists.
	ilEnable(IL_FILE_OVERWRITE);

	// If argv[2] is present, we save to this filename, else we save to test.tga.
	if (argc > 2)
		strcpy(FileName, argv[2]);
		//ilSaveImage(argv[2]);
	else
		strcpy(FileName, "test");
		//ilSaveImage("test.tga");

	if (argc > 3)
		strcpy(Ext, argv[3]);
	else
		strcpy(Ext, ".tga");

	iluGetImageInfo(&Info);
	PlaneSize = ilGetInteger(IL_IMAGE_PLANESIZE);
	Data = ilGetData();
	ilGenImages(1, &id);
	ilBindImage(id);

	for (i = 0; i < Info.Depth; i++) {
		strcpy(FName, FileName);
		itoa(i, FileNameNum, 10);
		strcat(FName, FileNameNum);
		strcat(FName, Ext);

		ilTexImage(Info.Width, Info.Height, 1, Info.Bpp, Info.Format, Info.Type,
			Data + PlaneSize * i);
		ilSaveImage(FName);
	}

	ilDeleteImages(1, &id);


	// We're done with the image, so let's delete it.
	ilDeleteImages(1, &ImgId);

	// Simple Error detection loop that displays the Error to the user in a human-readable form.
	while ((Error = ilGetError())) {
		printf("Error: %s\n", iluErrorString(Error));
	}

	return 0;

}