Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "xraw.h"
- #include <direct.h>
- #include <stdio.h>
- #include <limits.h>
- #include <vector>
- #include "Vector.h"
- #include "Globals.h"
- #include "Constants.h"
- //#include "VWorld.h"
- typedef struct {
- char f[4]; //should say XRAW
- unsigned char color_channel_data_type;
- unsigned char num_color_channels;
- unsigned char bits_perchannel;
- unsigned char bits_per_index;
- int width;
- int height;
- int depth;
- int num_palette_clr;
- }XRawHeader;
- static FILE* fp = NULL;
- static XRawHeader* sfh = NULL;
- static int m_flags;
- static block8* data;
- static unsigned int* colors;
- extern block8* blockarray;
- extern color8* colorarray;
- extern int g_offcx;
- extern int g_offcz;
- void xraw::read(char* name, int flags) {
- m_flags = flags;
- char buff[255];
- char cwd[FILENAME_MAX];
- if (_getcwd(cwd, sizeof(cwd)) != NULL) {
- printf("Current working dir: %s\n", cwd);
- }
- else {
- perror("getcwd() error");
- return;
- }
- fopen_s(&fp,name, "rb");
- if (fp == NULL) {
- printf("failed to open file: %s\n", name);
- return;
- }
- sfh = (XRawHeader*)malloc(sizeof(XRawHeader));
- if (!sfh)return;
- fread(sfh, sizeof(XRawHeader), 1, fp);
- printf("xraw header: %d,%d,%d, bpi: %d, bpc:%d sp:%d\n", sfh->width, sfh->height, sfh->depth,sfh->bits_per_index,sfh->bits_perchannel,sfh->num_palette_clr);
- printf("palette info: ccdt:%d ncc:%d \n ", sfh->color_channel_data_type, sfh->num_color_channels);
- int w = sfh->width;
- int h = sfh->height;
- int d = sfh->depth;
- int ps = sfh->num_palette_clr;
- data=(block8*)malloc(sizeof(block8)*w * h * d);
- fread(data, sizeof(block8) * w * h * d, 1, fp);
- colors = (unsigned int*)malloc(sizeof(unsigned int)*ps);
- fread(colors, sizeof(unsigned int) *ps, 1, fp);
- #define GBLOCKIDXCLEAN(x,z,y) ((x+g_offcx)%T_XSIZE)*(T_ZSIZE*T_HEIGHT) + ((z+g_offcz)%T_ZSIZE)*T_HEIGHT + y
- #define GBLOCKIDX(x,z,y) GBLOCKIDXCLEAN((x),(z),(y))
- //!#define GBLOCK(x,z,y) blockarray[GBLOCKIDX(x,z,y)]
- #define GBLOCK_SAFE(x,z,y) blockarray[(GBLOCKIDX(x,z,y)+T_BLOCKS)%T_BLOCKS]
- #define GBLOCK(x,z,y) blockarray[(GBLOCKIDX(x,z,y)+T_BLOCKS)%T_BLOCKS]
- #define GCOLORIDXCLEAN(x,z,y) ((x+g_offcx)%T_XSIZE)*(T_ZSIZE*T_HEIGHT) + ((z+g_offcz)%T_ZSIZE)*T_HEIGHT + y
- #define GCOLORIDX(x,z,y) GCOLORIDXCLEAN((x),(z),(y))
- //!#define GCOLOR(x,z,y) colorarray[GCOLORIDX(x,z,y)]
- #define GCOLOR_SAFE(x,z,y) colorarray[(GCOLORIDX(x,z,y)+T_BLOCKS)%T_BLOCKS]
- #define GCOLOR(x,z,y) colorarray[(GCOLORIDX(x,z,y)+T_BLOCKS)%T_BLOCKS]
- for (int i = 0; i < 10; i++) {
- for (int j = 0; j < 10; j++) {
- for (int x = 0; x < w; x++) {
- for (int y = 0; y < h; y++) {
- for (int z = 0; z < d; z++) {
- int n= data[x + z * w + y * (w * h)];
- if (n == 0)continue;
- if (n > 255) {
- printf("n larger than palette\n");
- }
- GBLOCK_SAFE(64*i+x+T_XSIZE/2 , 64 * j+z + T_ZSIZE / 2, y + 25) = TYPE_CLOUD;
- GCOLOR_SAFE(64 * i+x + T_XSIZE / 2, 64 * j+z + T_ZSIZE / 2, y + 25) = n;
- //GCOLOR_SAFE(x + T_SIZE / 2, z + T_SIZE / 2, y) = colors[x + z * w + y * (w * h)];
- //GBLOCK_SAFE(adj_cx * CHUNK_SIZE + x, adj_cz * CHUNK_SIZE + z, (T_HEIGHT - 1) - (cy * CHUNK_SIZE + y)) =
- // chunk_block_array[x * CHUNK_SIZE * CHUNK_SIZE + z * CHUNK_SIZE + y];
- }
- }
- }
- }
- }
- extern Vector colorTable[256];
- for(int ii = 0; ii < 256; ii++) {
- unsigned int uni = (unsigned int)colors[ii];
- //uni /= 256;
- int b = uni % 256;
- uni /= 256;
- int g = uni % 256;
- uni /= 256;
- int red = uni % 256;
- if (b > 200)b = 255;
- if (g > 200)g = 255;
- if (red > 200)red = 255;
- extern GLubyte blockColor[][3];
- //Setting& setting = cfg.lookup("misc.port");
- //string s = setting.c_str();
- colorTable[ii].x = (float)b / 255.0f;
- colorTable[ii].y = (float)g / 255.0f;
- colorTable[ii].z = (float)red / 255.0f;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement