MCPcopy Create free account
hub / github.com/OpenNFS/OpenNFS / makepal

Function makepal

tools/fshtool.c:340–374  ·  view source on GitHub ↗

convert a color palette from NFS format to BMP format */

Source from the content-addressed store, hash-verified

338
339/* convert a color palette from NFS format to BMP format */
340void makepal(unsigned char *pos,int *len,int *pal)
341{
342 int i,code;
343 struct ENTRYHDR *hdr;
344 unsigned char *ptr;
345 unsigned short *p16;
346
347 memset(pal,0,1024);
348 ptr=pos+16;
349 hdr=(struct ENTRYHDR *)pos;
350 code=hdr->code&0xff;
351 *len=hdr->width;
352
353 if (code==0x24) {
354 for (i=0;i<*len;i++,ptr+=3)
355 pal[i]=65536*ptr[0]+256*ptr[1]+ptr[2];
356 } else if (code==0x22) {
357 for (i=0;i<*len;i++,ptr+=3)
358 pal[i]=(65536*ptr[0]+256*ptr[1]+ptr[2])<<2;
359 } else if (code==0x2D) {
360 p16=(unsigned short *)ptr;
361 for (i=0;i<*len;i++,p16++) {
362 pal[i]=((*p16&0x1F)+256*((*p16>>5)&0x1F)+65536*((*p16>>10)&0x1F))<<3;
363 if (*p16&0x8000) pal[i]+=0xFF000000;
364 }
365 } else if (code==0x29) {
366 p16=(unsigned short *)ptr;
367 for (i=0;i<*len;i++,p16++) {
368 pal[i]=((*p16&0x1f)+128*((*p16>>5)&0x3F)+65536*((*p16>>11)&0x1F))<<3;
369 }
370 } else if (code==0x2A) {
371 memcpy(pal,ptr,4*(*len));
372 }
373 else { printf("Unknown palette format.\n"); abandon_ship(); }
374}
375
376/* write a line of alpha channel data text */
377

Callers 2

fsh_to_bmpFunction · 0.85
bmp_to_fshFunction · 0.85

Calls 1

abandon_shipFunction · 0.85

Tested by

no test coverage detected