Advertisement
Guest User

Untitled

a guest
Feb 1st, 2025
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.79 KB | Source Code | 0 0
  1. #include "xraw.h"
  2. #include <direct.h>
  3. #include <stdio.h>
  4. #include <limits.h>
  5. #include <vector>
  6. #include "Vector.h"
  7. #include "Globals.h"
  8. #include "Constants.h"
  9.  
  10. //#include "VWorld.h"
  11.  
  12.  
  13. typedef struct {
  14.     char f[4];   //should say XRAW
  15.     unsigned char color_channel_data_type;
  16.     unsigned char num_color_channels;
  17.     unsigned char bits_perchannel;
  18.     unsigned char bits_per_index;
  19.     int width;
  20.     int height;
  21.     int depth;
  22.     int num_palette_clr;
  23.  
  24. }XRawHeader;
  25. static FILE* fp = NULL;
  26. static XRawHeader* sfh = NULL;
  27. static int m_flags;
  28. static block8* data;
  29. static unsigned int* colors;
  30.  
  31.  
  32. extern block8* blockarray;
  33. extern color8* colorarray;
  34. extern int g_offcx;
  35. extern int g_offcz;
  36.  
  37. void xraw::read(char* name, int flags) {
  38.     m_flags = flags;
  39.    
  40.     char buff[255];
  41.     char cwd[FILENAME_MAX];
  42.     if (_getcwd(cwd, sizeof(cwd)) != NULL) {
  43.         printf("Current working dir: %s\n", cwd);
  44.     }
  45.     else {
  46.         perror("getcwd() error");
  47.         return;
  48.     }
  49.  
  50.      fopen_s(&fp,name, "rb");
  51.     if (fp == NULL) {
  52.         printf("failed to open file: %s\n", name);
  53.         return;
  54.     }
  55.     sfh = (XRawHeader*)malloc(sizeof(XRawHeader));
  56.     if (!sfh)return;
  57.     fread(sfh, sizeof(XRawHeader), 1, fp);
  58.  
  59.    
  60.     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);
  61.     printf("palette info:  ccdt:%d    ncc:%d \n ", sfh->color_channel_data_type, sfh->num_color_channels);
  62.     int w = sfh->width;
  63.     int h = sfh->height;
  64.     int d = sfh->depth;
  65.     int ps = sfh->num_palette_clr;
  66.     data=(block8*)malloc(sizeof(block8)*w * h * d);
  67.     fread(data, sizeof(block8) * w * h * d, 1, fp);
  68.     colors = (unsigned int*)malloc(sizeof(unsigned int)*ps);
  69.     fread(colors, sizeof(unsigned int) *ps, 1, fp);
  70. #define GBLOCKIDXCLEAN(x,z,y)  ((x+g_offcx)%T_XSIZE)*(T_ZSIZE*T_HEIGHT) + ((z+g_offcz)%T_ZSIZE)*T_HEIGHT + y
  71. #define GBLOCKIDX(x,z,y) GBLOCKIDXCLEAN((x),(z),(y))
  72.     //!#define GBLOCK(x,z,y) blockarray[GBLOCKIDX(x,z,y)]
  73. #define GBLOCK_SAFE(x,z,y) blockarray[(GBLOCKIDX(x,z,y)+T_BLOCKS)%T_BLOCKS]
  74. #define GBLOCK(x,z,y) blockarray[(GBLOCKIDX(x,z,y)+T_BLOCKS)%T_BLOCKS]
  75. #define GCOLORIDXCLEAN(x,z,y)  ((x+g_offcx)%T_XSIZE)*(T_ZSIZE*T_HEIGHT) + ((z+g_offcz)%T_ZSIZE)*T_HEIGHT + y
  76. #define GCOLORIDX(x,z,y) GCOLORIDXCLEAN((x),(z),(y))
  77. //!#define GCOLOR(x,z,y) colorarray[GCOLORIDX(x,z,y)]
  78. #define GCOLOR_SAFE(x,z,y) colorarray[(GCOLORIDX(x,z,y)+T_BLOCKS)%T_BLOCKS]
  79. #define GCOLOR(x,z,y) colorarray[(GCOLORIDX(x,z,y)+T_BLOCKS)%T_BLOCKS]
  80.     for (int i = 0; i < 10; i++) {
  81.         for (int j = 0; j < 10; j++) {
  82.            
  83.  
  84.        
  85.     for (int x = 0; x < w; x++) {
  86.         for (int y = 0; y < h; y++) {
  87.             for (int z = 0; z < d; z++) {
  88.  
  89.                 int n= data[x + z * w + y * (w * h)];
  90.                 if (n == 0)continue;
  91.                 if (n > 255) {
  92.                     printf("n larger than palette\n");
  93.                 }
  94.                 GBLOCK_SAFE(64*i+x+T_XSIZE/2 , 64 * j+z + T_ZSIZE / 2, y + 25) = TYPE_CLOUD;
  95.                 GCOLOR_SAFE(64 * i+x + T_XSIZE / 2, 64 * j+z + T_ZSIZE / 2, y + 25) = n;
  96.  
  97.                 //GCOLOR_SAFE(x + T_SIZE / 2, z + T_SIZE / 2, y) = colors[x + z * w + y * (w * h)];
  98.                 //GBLOCK_SAFE(adj_cx * CHUNK_SIZE + x, adj_cz * CHUNK_SIZE + z, (T_HEIGHT - 1) - (cy * CHUNK_SIZE + y)) =
  99.                 //  chunk_block_array[x * CHUNK_SIZE * CHUNK_SIZE + z * CHUNK_SIZE + y];
  100.             }
  101.         }
  102.     }
  103.             }
  104.         }
  105.    
  106.  
  107.     extern Vector colorTable[256];
  108.  
  109.         for(int ii = 0; ii < 256; ii++) {
  110.  
  111.             unsigned int uni = (unsigned int)colors[ii];
  112.             //uni /= 256;
  113.             int b = uni % 256;
  114.             uni /= 256;
  115.             int g = uni % 256;
  116.             uni /= 256;
  117.             int red = uni % 256;
  118.  
  119.             if (b > 200)b = 255;
  120.             if (g > 200)g = 255;
  121.             if (red > 200)red = 255;
  122.  
  123.             extern GLubyte blockColor[][3];
  124.             //Setting& setting = cfg.lookup("misc.port");
  125.             //string s = setting.c_str();
  126.             colorTable[ii].x = (float)b / 255.0f;
  127.             colorTable[ii].y = (float)g / 255.0f;
  128.             colorTable[ii].z = (float)red / 255.0f;
  129.  
  130.  
  131.  
  132.         }
  133.  
  134.  
  135.  
  136.  
  137.    
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement