我想对titltext.cel .CEL 图像格式进行逆向工程并在 SDL2 中呈现它。我碰巧对我正在使用的 CEL 文件有所了解。我知道它应该是字母表和一些符号的精灵表。
.CEL 图像格式是一种非常精简的格式,标题信息非常少。
谷歌搜索 让我找到了一些.CEL 规范.CEL 规范 2 文档,这些文档似乎有这个想法,但我认为缺少加载多个框架的内容。从文档中,我可以知道 CEL 图像中有多少帧以及第一帧从哪里开始。
知道第一帧从哪里开始我以为我可以绕过剥离的图像标题
图片标题:
37 00 00 00 E4 00 00 00 78 03 00 00 D6 05 00 00
18 08 00 00 B2 0A 00 00 02 0D 00 00 F8 0E 00 00
9D 11 00 00 07 14 00 00 4D 15 00 00 CB 16 00 00
04 19 00 00 9E 1A 00 00 1E 1E 00 00 ED 20 00 00
59 24 00 00 4C 26 00 00 78 29 00 00 E7 2B 00 00
1C 2E 00 00 18 30 00 00 AF 32 00 00 EC 34 00 00
BF 38 00 00 88 3B 00 00 8F 3D 00 00 EE 3F 00 00
4B 41 00 00 8E 43 00 00 D6 45 00 00 B4 47 00 00
06 4A 00 00 28 4C 00 00 E9 4D 00 00 4C 50 00 00
67 52 00 00 A9 55 00 00 09 57 00 00 D6 58 00 00
37 5C 00 00 19 5F 00 00 56 60 00 00 F4 61 00 00
A1 63 00 00 5D 64 00 00 93 65 00 00 B6 66 00 00
59 67 00 00 6A 68 00 00 7F 69 00 00 86 6A 00 00
70 6B 00 00 13 6C 00 00 A2 6C 00 00 8A 6E 00 00
45 70 00 00
在图像标题/第一帧开始之后。
D2 D2 D2 D2 D2 D2 D2 D2 D2 F9 03 F5 F4 F4 F3 03 F4 F4 F5
EC FD 07 F5 F5 F5 F5 F5 ED ......
>
根据文档,第一个 DWORD 是 .CEL 中的 FRAMES 数量。这是 0x37,它是十进制的 55,这似乎是准确的。据我了解,其余的只是框架位置。据我所知,每一帧的宽度应该为 45,高度为 46 像素。由于图像是 8 位颜色,这意味着每种颜色将是 1 个字节。
另外,我听说这些旧的图像类型被称为调色板或有助于改变颜色的东西。
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <SDL2/SDL_mixer.h>
#include <stdbool.h>
#include <stdio.h>
#include <errno.h>
SDL_Window *window; // SDL MAIN WINDOW
SDL_Renderer *renderer;
SDL_Texture *texture;
int SCREEN_WIDTH = 1920;
int SCREEN_HEIGHT = 1080;
SDL_Event e;
bool quit = false;
/** 32-bit in-memory backbuffer surface */
SDL_Surface *surface;
/** 8-bit surface wrapper around #gpBuffer */
SDL_Surface *pal_surface;
/** Currently active palette */
SDL_Palette *palette;
SDL_Texture* texture;
FILE* CELFILE;
unsigned char CELBuffer [3000];
// The CEL dementions I am trying to open are
// W 46 Height 45 Width 55 FRAMES
void LoadCEL (char * Path){
CELFILE = fopen(Path, "rb");
int CELHEADERSIZE = 228;
int CELFRAMESIZE = 2070;
//The Header Appears to be 228 bytes in size. I want to put a frame into CELBuffer
//
// I am assuming to get the size of the first framee I need a size of 2017 (45 * 55) ;
unsigned char c;
for (int i = 0; i < (CELFRAMESIZE+CELHEADERSIZE) ; i++){
if(i > CELHEADERSIZE ){
c = fgetc(CELFILE);
CELBuffer[i] = c;
printf("CELFILE HEADR %02x \n" ,CELBuffer[i] & 0xff);
}
}
void * pCELBuffer = CELBuffer;
surface = SDL_CreateRGBSurfaceFrom( pCELBuffer , 45, 55, 8,1 ,0, 0, 0, 0xff);
texture = SDL_CreateTextureFromSurface(renderer, surface);
}
void Create_SDL_Window()
{
SDL_Init(SDL_INIT_EVERYTHING);
IMG_Init(IMG_INIT_PNG);
window = SDL_CreateWindow("Test Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
renderer = SDL_CreateRenderer(window, -1, 0);
printf("Window And Renderer Created!\n");
}
int main(){
LoadCEL("/home/james/Desktop/titltext.cel");
Create_SDL_Window();
printf("THIS WORKD\n");
while (!quit){
SDL_RenderPresent(renderer);
while (SDL_PollEvent(&e)){
//If user closes the window
if (e.type == SDL_QUIT){
quit = true;
}
//If user presses any key
if (e.type == SDL_KEYDOWN){
// quit = true;
}
//If user clicks the mouse
if (e.type == SDL_MOUSEBUTTONDOWN){
/// quit = true;
}
}
SDL_RenderClear(renderer);
//renderTexture(image, renderer, x, y);
SDL_RenderPresent(renderer);
}
}
任何帮助深表感谢。