sdlpal 资源素材内存截取并保存到硬盘

分类:编程技术 时间:2024-02-20 17:49 浏览:0 评论:0
0

文章sdlpal精灵素材内存截取并保存到硬盘,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

github地址

://github.com/sdlpal/sdlpal

 

简单阅读了一下源码,虽然项目用到了stb_image.h,但是我们还需要stb_image_write.h来写文件,所以还得再搞一下

://github.com/nothings/stb

 

打开项目文件

sdlpal_20230502\win32\sdlpal.sln

确保先能编译,并正确运行,我以DOS仙剑为例测试的

 

项目中加入stb_image_write.h的include路径

打开 palette.c 文件,头部加入

#define STB_IMAGE_WRITE_IMPLEMENTATION#include "stb_image_write.h"

加入全局变量

SDL_Color pe_palette[256];int pe_palette_ready = 0;static int bOnce_day = 0;static int bOnce_night = 0;static int bRec_day = 0;static int bRec_night = 0;static int pe_id = 0;

在下面的 PAL_GetPalette 函数中找到 palette 部分代码,修改如下

for (i = 0; i < 256; i++)   {      palette[i].r = buf[(fNight ? 256 * 3 : 0) + i * 3] << 2;      palette[i].g = buf[(fNight ? 256 * 3 : 0) + i * 3 + 1] << 2;      palette[i].b = buf[(fNight ? 256 * 3 : 0) + i * 3 + 2] << 2;      if (iPaletteNum == 0)      {          if (pe_id == 1)          {              pe_palette[i].r = palette[i].r;              pe_palette[i].g = palette[i].g;              pe_palette[i].b = palette[i].b;          }                }#if 0      palette[i].r += (255 - palette[i].r) / 5;      palette[i].g += (255 - palette[i].g) / 5;      palette[i].b += (255 - palette[i].b) / 5;#endif   }      if (iPaletteNum == 0)   {       if (!fNight)       {           if (bRec_day)           {               if (pe_id == 1)               {                   if (!bOnce_day)                   {                       bOnce_day = 1;                       char* peOutFile = "pat_0_day.png";                       int w = 256;                       int h = 1;                       int n = 4;                       unsigned char* data = malloc(w * h * n);                       if (data != 0)                       {   for (int i = 0; i < 256; i++)   {       data[i * 4 + 0] = palette[i].r;       data[i * 4 + 1] = palette[i].g;       data[i * 4 + 2] = palette[i].b;       data[i * 4 + 3] = 255;   }   stbi_write_png(peOutFile, w, h, n, data, w * n);   free(data);                       }                   }               }           }                      if (pe_id == 1)           {               pe_palette_ready = 1;           }           pe_id++;       }       //night palette       else       {           if (bRec_night)           {               if (!bOnce_night)               {                   bOnce_night = 1;                   char* peOutFile = "pat_0_night.png";                   int w = 256;                   int h = 1;                   int n = 4;                   unsigned char* data = malloc(w * h * n);                   if (data != 0)                   {                       for (int i = 0; i < 256; i++)                       {   data[i * 4 + 0] = palette[i].r;   data[i * 4 + 1] = palette[i].g;   data[i * 4 + 2] = palette[i].b;   data[i * 4 + 3] = 255;                       }                       stbi_write_png(peOutFile, w, h, n, data, w * n);                       free(data);                   }               }           }       }   }

 



1. 本站所有资源来源于用户上传或网络,仅作为参考研究使用,如有侵权请邮件联系站长!
2. 本站积分货币获取途径以及用途的解读,想在本站混的好,请务必认真阅读!
3. 本站强烈打击盗版/破解等有损他人权益和违法作为,请各位会员支持正版!
4. 编程技术 > sdlpal 资源素材内存截取并保存到硬盘

用户评论