Reformat all C files.
I'll push a formatting guide at some point. There may still be outstanding changes, but please feel free to resolve those as you arrive a them. To the best of my knowledge, there is no changes to the actual code content, but the formatter does have the occasional bug. If you run into an issue, please fix it!
This commit is contained in:
+264
-269
@@ -8,7 +8,7 @@
|
||||
* -> Programmcode *
|
||||
\****************************/
|
||||
/*
|
||||
* $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$
|
||||
* $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.3 $
|
||||
* $Date: 2002/01/05 21:06:00 $ $Revision: 1.1 $
|
||||
*/
|
||||
|
||||
@@ -24,321 +24,316 @@
|
||||
|
||||
#define IMG_COMPRESSED
|
||||
|
||||
typedef struct
|
||||
{
|
||||
UWORD img_version;
|
||||
UWORD img_headlen;
|
||||
UWORD img_nplanes;
|
||||
UWORD img_patlen;
|
||||
UWORD img_pixw;
|
||||
UWORD img_pixh;
|
||||
UWORD img_w;
|
||||
UWORD img_h;
|
||||
} IMG_HEADER;
|
||||
typedef struct {
|
||||
UWORD img_version;
|
||||
UWORD img_headlen;
|
||||
UWORD img_nplanes;
|
||||
UWORD img_patlen;
|
||||
UWORD img_pixw;
|
||||
UWORD img_pixh;
|
||||
UWORD img_w;
|
||||
UWORD img_h;
|
||||
} IMG_HEADER;
|
||||
|
||||
typedef enum {NONE, SOLID0, SOLID1, PATRUN, BITSTR} IMG_MODE;
|
||||
typedef enum { NONE, SOLID0, SOLID1, PATRUN, BITSTR } IMG_MODE;
|
||||
|
||||
typedef UBYTE IMG_SOLID;
|
||||
|
||||
typedef enum { RGB=0, CMY=1, Pantone=2 } XIMG_COLMODEL;
|
||||
typedef enum { RGB = 0, CMY = 1, Pantone = 2 } XIMG_COLMODEL;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
ULONG img_ximg;
|
||||
XIMG_COLMODEL img_colmodel;
|
||||
} XIMG_HEADER;
|
||||
typedef struct {
|
||||
ULONG img_ximg;
|
||||
XIMG_COLMODEL img_colmodel;
|
||||
} XIMG_HEADER;
|
||||
|
||||
typedef struct RGB XIMG_RGB;
|
||||
|
||||
int
|
||||
bitmap_to_img(FILE_TYP typ, int ww, int wh, unsigned int pixw,
|
||||
unsigned int pixh, unsigned int planes, unsigned int colors,
|
||||
const char *filename,
|
||||
void (*get_color)(unsigned int colind, struct RGB *rgb),
|
||||
void (*get_pixel)(int x, int y, unsigned int *colind))
|
||||
{
|
||||
int file, error, cnt;
|
||||
IMG_HEADER header;
|
||||
XIMG_HEADER xheader;
|
||||
XIMG_RGB xrgb;
|
||||
IMG_MODE mode;
|
||||
UBYTE *line_buf, *write_buf;
|
||||
register UBYTE *startpnt, *bufpnt;
|
||||
unsigned int colind, line_len, line, bit;
|
||||
register unsigned int byte;
|
||||
register UBYTE count;
|
||||
|
||||
int bitmap_to_img(FILE_TYP typ, int ww, int wh,
|
||||
unsigned int pixw, unsigned int pixh,
|
||||
unsigned int planes, unsigned int colors,
|
||||
const char *filename,
|
||||
void(*get_color)(unsigned int colind, struct RGB *rgb),
|
||||
void(*get_pixel)(int x, int y, unsigned int *colind) )
|
||||
{
|
||||
int file, error, cnt;
|
||||
IMG_HEADER header;
|
||||
XIMG_HEADER xheader;
|
||||
XIMG_RGB xrgb;
|
||||
IMG_MODE mode;
|
||||
UBYTE *line_buf, *write_buf;
|
||||
register UBYTE *startpnt, *bufpnt;
|
||||
unsigned int colind, line_len, line, bit;
|
||||
register unsigned int byte;
|
||||
register UBYTE count;
|
||||
/* fill in (X) IMG-Header */
|
||||
|
||||
/* fill in (X) IMG-Header */
|
||||
header.img_version = 1;
|
||||
header.img_headlen = (UWORD) sizeof(header) / 2;
|
||||
if (typ == XIMG)
|
||||
header.img_headlen +=
|
||||
(UWORD)(sizeof(xheader) + colors * sizeof(xrgb)) / 2;
|
||||
|
||||
header.img_version = 1;
|
||||
header.img_headlen = (UWORD) sizeof(header) /2;
|
||||
if (typ == XIMG)
|
||||
header.img_headlen += (UWORD)(sizeof(xheader)+colors*sizeof(xrgb))/2;
|
||||
header.img_nplanes = planes;
|
||||
header.img_patlen = 2;
|
||||
header.img_pixw = pixw;
|
||||
header.img_pixh = pixh;
|
||||
header.img_w = ww;
|
||||
header.img_h = wh;
|
||||
|
||||
header.img_nplanes = planes;
|
||||
header.img_patlen = 2;
|
||||
header.img_pixw = pixw;
|
||||
header.img_pixh = pixh;
|
||||
header.img_w = ww;
|
||||
header.img_h = wh;
|
||||
xheader.img_ximg = XIMG_MAGIC;
|
||||
xheader.img_colmodel = RGB;
|
||||
|
||||
xheader.img_ximg = XIMG_MAGIC;
|
||||
xheader.img_colmodel= RGB;
|
||||
/* calculate linelength, allocate buffer. */
|
||||
|
||||
/* calculate linelength, allocate buffer. */
|
||||
line_len = (ww + 7) / 8;
|
||||
|
||||
line_len = (ww+7)/8;
|
||||
line_buf = malloc((size_t) planes * line_len);
|
||||
if (line_buf == NULL)
|
||||
return (ENOMEM);
|
||||
|
||||
line_buf = malloc((size_t)planes*line_len);
|
||||
if (line_buf == NULL)
|
||||
return(ENOMEM);
|
||||
/* Worst case: the bufferd line could grow to max. 3 times the length */
|
||||
/* of the original!
|
||||
*/
|
||||
|
||||
/* Worst case: the bufferd line could grow to max. 3 times the length */
|
||||
/* of the original! */
|
||||
write_buf = malloc((size_t) 3 * line_len);
|
||||
if (write_buf == NULL) {
|
||||
free(line_buf);
|
||||
return (ENOMEM);
|
||||
};
|
||||
|
||||
write_buf = malloc((size_t)3*line_len);
|
||||
if (write_buf == NULL)
|
||||
{
|
||||
free(line_buf);
|
||||
return(ENOMEM);
|
||||
};
|
||||
/* open file */
|
||||
|
||||
/* open file */
|
||||
file = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
if (file < 0) {
|
||||
error = errno;
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return (error);
|
||||
};
|
||||
|
||||
file = open(filename, O_WRONLY | O_CREAT | O_TRUNC);
|
||||
if (file<0)
|
||||
{
|
||||
error = errno;
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return(error);
|
||||
};
|
||||
/* write Header */
|
||||
|
||||
/* write Header */
|
||||
if (write(file, &header, sizeof(header)) != sizeof(header)
|
||||
|| (typ == XIMG
|
||||
&& write(file, &xheader, sizeof(xheader)) != sizeof(xheader))) {
|
||||
error = errno;
|
||||
close(file);
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return (error);
|
||||
};
|
||||
|
||||
if (write (file, &header, sizeof(header)) != sizeof(header) ||
|
||||
(typ == XIMG && write (file, &xheader, sizeof(xheader) ) != sizeof(xheader)))
|
||||
{
|
||||
error = errno;
|
||||
close(file);
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return(error);
|
||||
};
|
||||
/* save the colortable if possible */
|
||||
|
||||
/* save the colortable if possible */
|
||||
if (typ == XIMG)
|
||||
for (cnt = 0; cnt < colors; cnt++) {
|
||||
get_color(cnt, &xrgb);
|
||||
if (write(file, &xrgb, sizeof(xrgb)) != sizeof(xrgb)) {
|
||||
error = errno;
|
||||
close(file);
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return (error);
|
||||
};
|
||||
};
|
||||
|
||||
if ( typ == XIMG )
|
||||
for (cnt=0; cnt<colors; cnt++)
|
||||
{
|
||||
get_color(cnt,&xrgb);
|
||||
if (write(file,&xrgb,sizeof(xrgb)) != sizeof(xrgb))
|
||||
{
|
||||
error = errno;
|
||||
close(file);
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return(error);
|
||||
};
|
||||
};
|
||||
/* And now line by line ... */
|
||||
|
||||
/* And now line by line ... */
|
||||
for (line = 0; line < wh; line++) {
|
||||
/* get pixel, split it up and */
|
||||
/* store it as planes in buffer */
|
||||
|
||||
for (line=0; line<wh; line++)
|
||||
{
|
||||
/* get pixel, split it up and */
|
||||
/* store it as planes in buffer */
|
||||
for (byte = 0; byte < line_len; byte++) {
|
||||
for (cnt = 0; cnt < planes; cnt++)
|
||||
line_buf[cnt * line_len + byte] = 0x00;
|
||||
|
||||
for (byte=0; byte<line_len; byte++)
|
||||
{
|
||||
for (cnt=0; cnt<planes; cnt++)
|
||||
line_buf[cnt*line_len+byte] = 0x00;
|
||||
for (bit = 0; bit < 8; bit++) {
|
||||
if (8 * byte + bit < ww)
|
||||
get_pixel(8 * byte + bit, line, &colind);
|
||||
|
||||
for (bit=0; bit<8; bit++)
|
||||
{
|
||||
if (8*byte+bit < ww)
|
||||
get_pixel(8*byte+bit, line, &colind);
|
||||
for (cnt = 0; cnt < planes; cnt++) {
|
||||
line_buf[cnt * line_len + byte] <<= 1;
|
||||
line_buf[cnt * line_len + byte] |= colind & 0x01;
|
||||
colind >>= 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
for (cnt=0; cnt<planes; cnt++)
|
||||
{
|
||||
line_buf[cnt*line_len+byte] <<= 1;
|
||||
line_buf[cnt*line_len+byte] |= colind & 0x01;
|
||||
colind >>= 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
/* compress bitstrings in buffer */
|
||||
/* and write it to file */
|
||||
|
||||
/* compress bitstrings in buffer */
|
||||
/* and write it to file */
|
||||
for (cnt = 0; cnt < planes; cnt++) {
|
||||
/* Bitstringpointer to start of plane */
|
||||
|
||||
for (cnt=0; cnt<planes; cnt++)
|
||||
{
|
||||
/* Bitstringpointer to start of plane */
|
||||
startpnt = &line_buf[cnt * line_len];
|
||||
bufpnt = write_buf;
|
||||
|
||||
startpnt = &line_buf[cnt*line_len];
|
||||
bufpnt = write_buf;
|
||||
while (startpnt < &line_buf[(cnt + 1) * line_len]) {
|
||||
/*********************************************/
|
||||
/* Which _new_ compression-mode "fits" the */
|
||||
/* the current byte?
|
||||
*/
|
||||
/* Note: the compressing modes get choosen */
|
||||
/* "positive". The non compressing BITSTR- */
|
||||
/* mode is choosen only if nothing else */
|
||||
/* "fits" ...
|
||||
*/
|
||||
/*********************************************/
|
||||
|
||||
while (startpnt < &line_buf[(cnt+1)*line_len])
|
||||
{
|
||||
/*********************************************/
|
||||
/* Which _new_ compression-mode "fits" the */
|
||||
/* the current byte? */
|
||||
/* Note: the compressing modes get choosen */
|
||||
/* "positive". The non compressing BITSTR- */
|
||||
/* mode is choosen only if nothing else */
|
||||
/* "fits" ... */
|
||||
/*********************************************/
|
||||
switch (*startpnt) {
|
||||
case 0x00:
|
||||
mode = SOLID0;
|
||||
break;
|
||||
case 0xFF:
|
||||
mode = SOLID1;
|
||||
break;
|
||||
default:
|
||||
if (startpnt < &line_buf[(cnt + 1) * line_len - 3]
|
||||
&& *(startpnt) == *(startpnt + 2)
|
||||
&& *(startpnt + 1) == *(startpnt + 3))
|
||||
mode = PATRUN;
|
||||
else
|
||||
mode = BITSTR;
|
||||
};
|
||||
|
||||
switch (*startpnt)
|
||||
{
|
||||
case 0x00:
|
||||
mode = SOLID0;
|
||||
break;
|
||||
case 0xFF:
|
||||
mode = SOLID1;
|
||||
break;
|
||||
default:
|
||||
if ( startpnt < &line_buf[(cnt+1)*line_len-3] &&
|
||||
*(startpnt) == *(startpnt+2) &&
|
||||
*(startpnt+1) == *(startpnt+3) )
|
||||
mode = PATRUN;
|
||||
else
|
||||
mode = BITSTR;
|
||||
};
|
||||
/************************************************/
|
||||
/* The mode is choosen, now work with it.
|
||||
*/
|
||||
/* The compressing modi stay current as long as */
|
||||
/* possible.
|
||||
*/
|
||||
/************************************************/
|
||||
|
||||
/************************************************/
|
||||
/* The mode is choosen, now work with it. */
|
||||
/* The compressing modi stay current as long as */
|
||||
/* possible. */
|
||||
/************************************************/
|
||||
count = 0;
|
||||
|
||||
count = 0;
|
||||
switch (mode) {
|
||||
case SOLID0:
|
||||
while ((startpnt < &line_buf[(cnt + 1) * line_len])
|
||||
&& (*(startpnt) == 0x00) && (count < 0x7F)) {
|
||||
startpnt++;
|
||||
count++;
|
||||
};
|
||||
*(bufpnt++) = count;
|
||||
break;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case SOLID0:
|
||||
while ( (startpnt < &line_buf[(cnt+1)*line_len]) &&
|
||||
(*(startpnt)==0x00) &&
|
||||
(count < 0x7F) )
|
||||
{
|
||||
startpnt++;
|
||||
count++;
|
||||
};
|
||||
*(bufpnt++) = count;
|
||||
break;
|
||||
case SOLID1:
|
||||
while ((startpnt < &line_buf[(cnt + 1) * line_len])
|
||||
&& (*(startpnt) == 0xFF) && (count < 0x7F)) {
|
||||
startpnt++;
|
||||
count++;
|
||||
};
|
||||
*(bufpnt++) = 0x80 | count;
|
||||
break;
|
||||
|
||||
case SOLID1:
|
||||
while ( (startpnt < &line_buf[(cnt+1)*line_len]) &&
|
||||
(*(startpnt)==0xFF) &&
|
||||
(count < 0x7F) )
|
||||
{
|
||||
startpnt++;
|
||||
count++;
|
||||
};
|
||||
*(bufpnt++) = 0x80 | count;
|
||||
break;
|
||||
case PATRUN:
|
||||
*(bufpnt++) = 0x00;
|
||||
startpnt += 2;
|
||||
count = 1;
|
||||
while (startpnt < &line_buf[(cnt + 1) * line_len - 1]
|
||||
&& *(startpnt) == *(startpnt - 2)
|
||||
&& *(startpnt + 1) == *(startpnt - 1)
|
||||
&& (count < 0xFF)) {
|
||||
count++;
|
||||
startpnt += 2;
|
||||
};
|
||||
*(bufpnt++) = count;
|
||||
*(bufpnt++) = *(startpnt - 2);
|
||||
*(bufpnt++) = *(startpnt - 1);
|
||||
break;
|
||||
|
||||
case PATRUN:
|
||||
*(bufpnt++) = 0x00;
|
||||
startpnt += 2;
|
||||
count = 1;
|
||||
while ( startpnt < &line_buf[(cnt+1)*line_len-1] &&
|
||||
*(startpnt) == *(startpnt-2) &&
|
||||
*(startpnt+1) == *(startpnt-1) &&
|
||||
(count < 0xFF) )
|
||||
{
|
||||
count++;
|
||||
startpnt += 2;
|
||||
};
|
||||
*(bufpnt++) = count;
|
||||
*(bufpnt++) = *(startpnt-2);
|
||||
*(bufpnt++) = *(startpnt-1);
|
||||
break;
|
||||
/************************************************/
|
||||
/* The while Condition is ment as follows: */
|
||||
/* */
|
||||
/* while ( NOT(2-Byte-Solidrun possible) &&
|
||||
*/
|
||||
/* NOT(6-Byte-Patternrun possible) &&
|
||||
*/
|
||||
/* count < 0xFF
|
||||
* && */
|
||||
/* still Bytes remaining )
|
||||
*/
|
||||
/* */
|
||||
/* As soon as a _compressing_ alternative shows */
|
||||
/* up, BITSTR gets cancelled!
|
||||
*/
|
||||
/************************************************/
|
||||
|
||||
/************************************************/
|
||||
/* The while Condition is ment as follows: */
|
||||
/* */
|
||||
/* while ( NOT(2-Byte-Solidrun possible) && */
|
||||
/* NOT(6-Byte-Patternrun possible) && */
|
||||
/* count < 0xFF && */
|
||||
/* still Bytes remaining ) */
|
||||
/* */
|
||||
/* As soon as a _compressing_ alternative shows */
|
||||
/* up, BITSTR gets cancelled! */
|
||||
/************************************************/
|
||||
case BITSTR:
|
||||
*(bufpnt++) = 0x80;
|
||||
while (!(((startpnt + count)
|
||||
< &line_buf[(cnt + 1) * line_len - 1])
|
||||
&& (((*(startpnt + count) == 0xFF)
|
||||
&& (*(startpnt + count + 1) == 0xFF))
|
||||
|| ((*(startpnt + count) == 0x00)
|
||||
&& (*(startpnt + count + 1) == 0x00))))
|
||||
&& !(((startpnt + count)
|
||||
< &line_buf[(cnt + 1) * line_len - 5])
|
||||
&& (*(startpnt + count)
|
||||
== *(startpnt + count + 2))
|
||||
&& (*(startpnt + count + 1)
|
||||
== *(startpnt + count + 3))
|
||||
&& (*(startpnt + count)
|
||||
== *(startpnt + count + 4))
|
||||
&& (*(startpnt + count + 1)
|
||||
== *(startpnt + count + 5)))
|
||||
&& (count < 0xFF)
|
||||
&& ((startpnt + count)
|
||||
< &line_buf[(cnt + 1) * line_len]))
|
||||
count++;
|
||||
*(bufpnt++) = count;
|
||||
for (; count > 0; count--)
|
||||
*(bufpnt++) = *(startpnt++);
|
||||
break;
|
||||
};
|
||||
};
|
||||
|
||||
case BITSTR:
|
||||
*(bufpnt++) = 0x80;
|
||||
while ( !(((startpnt+count)<&line_buf[(cnt+1)*line_len-1])&&
|
||||
(((*(startpnt+count)==0xFF) && (*(startpnt+count+1)==0xFF))||
|
||||
((*(startpnt+count)==0x00) && (*(startpnt+count+1)==0x00)))) &&
|
||||
!(((startpnt+count)<&line_buf[(cnt+1)*line_len-5])&&
|
||||
(*(startpnt+count) == *(startpnt+count+2))&&
|
||||
(*(startpnt+count+1) == *(startpnt+count+3))&&
|
||||
(*(startpnt+count) == *(startpnt+count+4))&&
|
||||
(*(startpnt+count+1) == *(startpnt+count+5))) &&
|
||||
(count < 0xFF) &&
|
||||
((startpnt+count) < &line_buf[(cnt+1)*line_len]) )
|
||||
count++;
|
||||
*(bufpnt++) = count;
|
||||
for(; count>0; count--)
|
||||
*(bufpnt++) = *(startpnt++);
|
||||
break;
|
||||
};
|
||||
};
|
||||
if (write(file, write_buf, bufpnt - write_buf)
|
||||
!= (bufpnt - write_buf)) {
|
||||
error = errno;
|
||||
close(file);
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return (error);
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
if (write(file,write_buf,bufpnt-write_buf) != (bufpnt-write_buf))
|
||||
{
|
||||
error = errno;
|
||||
close(file);
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return(error);
|
||||
};
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
/*close file, free buffer. */
|
||||
|
||||
close(file);
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return(0);
|
||||
/*close file, free buffer. */
|
||||
|
||||
close(file);
|
||||
free(line_buf);
|
||||
free(write_buf);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*---filetype-dispatcher--------------------*/
|
||||
|
||||
const char *get_file_ext(FILE_TYP typ)
|
||||
{
|
||||
switch (typ)
|
||||
{
|
||||
case IMG:
|
||||
case XIMG:
|
||||
return("IMG");
|
||||
default:
|
||||
return("");
|
||||
};
|
||||
const char *
|
||||
get_file_ext(FILE_TYP typ)
|
||||
{
|
||||
switch (typ) {
|
||||
case IMG:
|
||||
case XIMG:
|
||||
return ("IMG");
|
||||
default:
|
||||
return ("");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
int bitmap_to_file(FILE_TYP typ, int ww, int wh,
|
||||
unsigned int pwx, unsigned int pwy,
|
||||
unsigned int planes, unsigned int colors,
|
||||
const char *filename,
|
||||
void (*get_color)(unsigned int colind, struct RGB *rgb),
|
||||
void (*get_pixel)(int x, int y, unsigned int *colind))
|
||||
{
|
||||
|
||||
switch (typ)
|
||||
{
|
||||
case IMG:
|
||||
case XIMG:
|
||||
return(bitmap_to_img(typ,ww,wh,pwx,pwy,planes,colors,filename,get_color,get_pixel));
|
||||
default:
|
||||
return(-1);
|
||||
};
|
||||
int
|
||||
bitmap_to_file(FILE_TYP typ, int ww, int wh, unsigned int pwx,
|
||||
unsigned int pwy, unsigned int planes, unsigned int colors,
|
||||
const char *filename,
|
||||
void (*get_color)(unsigned int colind, struct RGB *rgb),
|
||||
void (*get_pixel)(int x, int y, unsigned int *colind))
|
||||
{
|
||||
switch (typ) {
|
||||
case IMG:
|
||||
case XIMG:
|
||||
return (bitmap_to_img(typ, ww, wh, pwx, pwy, planes, colors, filename,
|
||||
get_color, get_pixel));
|
||||
default:
|
||||
return (-1);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+187
-164
@@ -1,7 +1,8 @@
|
||||
/* NetHack 3.6 gr_rect.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 gr_rect.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */
|
||||
/* NetHack 3.6 gr_rect.c $Date: 2009/05/06 10:56:40 $ $Revision: 1.3 $ */
|
||||
/* SCCS Id: @(#)gr_rect.c 3.5 2001/12/10 */
|
||||
/* Copyright (c) Christian Bressler, 2001 */
|
||||
/* SCCS Id: @(#)gr_rect.c 3.5 2001/12/10
|
||||
*/
|
||||
/* Copyright (c) Christian Bressler, 2001 */
|
||||
/* NetHack may be freely redistributed. See license for details. */
|
||||
/* This is an almost exact copy of qt_clust.cpp */
|
||||
/* gr_rect.c */
|
||||
@@ -9,175 +10,197 @@
|
||||
#include <stdio.h>
|
||||
#include <limits.h>
|
||||
#include "gr_rect.h"
|
||||
dirty_rect *new_dirty_rect(int size){
|
||||
dirty_rect *new=NULL;
|
||||
if(size>0){
|
||||
new=(dirty_rect *)calloc(1L,sizeof(dirty_rect));
|
||||
if(new){
|
||||
new->rects=(GRECT *)calloc((long)size,sizeof(GRECT));
|
||||
if(new->rects==NULL){
|
||||
free(new);
|
||||
return(NULL);
|
||||
}
|
||||
new->max=size;
|
||||
}
|
||||
}
|
||||
return(new);
|
||||
dirty_rect *
|
||||
new_dirty_rect(int size)
|
||||
{
|
||||
dirty_rect *new = NULL;
|
||||
if (size > 0) {
|
||||
new = (dirty_rect *) calloc(1L, sizeof(dirty_rect));
|
||||
if (new) {
|
||||
new->rects = (GRECT *) calloc((long) size, sizeof(GRECT));
|
||||
if (new->rects == NULL) {
|
||||
free(new);
|
||||
return (NULL);
|
||||
}
|
||||
new->max = size;
|
||||
}
|
||||
}
|
||||
return (new);
|
||||
}
|
||||
void delete_dirty_rect(dirty_rect *this){
|
||||
if(this==NULL)
|
||||
return;
|
||||
if(this->rects)
|
||||
free(this->rects);
|
||||
/* In case the Pointer is reused wrongly */
|
||||
this->rects=NULL;
|
||||
this->max=0;
|
||||
this->used=0;
|
||||
free(this);
|
||||
void
|
||||
delete_dirty_rect(dirty_rect *this)
|
||||
{
|
||||
if (this == NULL)
|
||||
return;
|
||||
if (this->rects)
|
||||
free(this->rects);
|
||||
/* In case the Pointer is reused wrongly */
|
||||
this->rects = NULL;
|
||||
this->max = 0;
|
||||
this->used = 0;
|
||||
free(this);
|
||||
}
|
||||
static int gc_inside(GRECT *frame,GRECT *test);
|
||||
static int gc_touch(GRECT *frame,GRECT *test);
|
||||
static void gc_combine(GRECT *frame,GRECT *test);
|
||||
static int gc_inside(GRECT *frame, GRECT *test);
|
||||
static int gc_touch(GRECT *frame, GRECT *test);
|
||||
static void gc_combine(GRECT *frame, GRECT *test);
|
||||
static long gc_area(GRECT *area);
|
||||
int add_dirty_rect(dirty_rect *dr,GRECT *area){
|
||||
int cursor;
|
||||
long lowestcost=9999999L;
|
||||
int cheapest=-1;
|
||||
int cheapestmerge1=-1;
|
||||
int cheapestmerge2=-1;
|
||||
int merge1;
|
||||
int merge2;
|
||||
for (cursor=0; cursor<dr->used; cursor++) {
|
||||
if (gc_inside(&dr->rects[cursor],area)) {
|
||||
/* Wholly contained already. */
|
||||
return(TRUE);
|
||||
}
|
||||
}
|
||||
for (cursor=0; cursor<dr->used; cursor++) {
|
||||
if (gc_touch(&dr->rects[cursor],area)) {
|
||||
GRECT larger=dr->rects[cursor];
|
||||
long cost;
|
||||
gc_combine(&larger,area);
|
||||
cost=gc_area(&larger)-gc_area(&dr->rects[cursor]);
|
||||
if (cost < lowestcost) {
|
||||
int bad=FALSE,c;
|
||||
for (c=0; c<dr->used && !bad; c++) {
|
||||
bad=gc_touch(&dr->rects[c],&larger) && c!=cursor;
|
||||
}
|
||||
if (!bad) {
|
||||
cheapest=cursor;
|
||||
lowestcost=cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cheapest>=0) {
|
||||
gc_combine(&dr->rects[cheapest],area);
|
||||
return(TRUE);
|
||||
}
|
||||
if (dr->used < dr->max) {
|
||||
dr->rects[dr->used++]=*area;
|
||||
return(TRUE);
|
||||
}
|
||||
// Do cheapest of:
|
||||
// add to closest cluster
|
||||
// do cheapest cluster merge, add to new cluster
|
||||
lowestcost=9999999L;
|
||||
cheapest=-1;
|
||||
for (cursor=0; cursor<dr->used; cursor++) {
|
||||
GRECT larger=dr->rects[cursor];
|
||||
long cost;
|
||||
gc_combine(&larger,area);
|
||||
cost=gc_area(&larger)-gc_area(&dr->rects[cursor]);
|
||||
if (cost < lowestcost) {
|
||||
int bad=FALSE, c;
|
||||
for (c=0; c<dr->used && !bad; c++) {
|
||||
bad=gc_touch(&dr->rects[c],&larger) && c!=cursor;
|
||||
}
|
||||
if (!bad) {
|
||||
cheapest=cursor;
|
||||
lowestcost=cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
// XXX could make an heuristic guess as to whether we
|
||||
// XXX need to bother looking for a cheap merge.
|
||||
for (merge1=0; merge1<dr->used; merge1++) {
|
||||
for (merge2=0; merge2<dr->used; merge2++) {
|
||||
if (merge1!=merge2) {
|
||||
GRECT larger=dr->rects[merge1];
|
||||
long cost;
|
||||
gc_combine(&larger,&dr->rects[merge2]);
|
||||
cost=gc_area(&larger)-gc_area(&dr->rects[merge1])-gc_area(&dr->rects[merge2]);
|
||||
if (cost < lowestcost) {
|
||||
int bad=FALSE, c;
|
||||
for (c=0; c<dr->used && !bad; c++) {
|
||||
bad=gc_touch(&dr->rects[c],&larger) && c!=cursor;
|
||||
}
|
||||
if (!bad) {
|
||||
cheapestmerge1=merge1;
|
||||
cheapestmerge2=merge2;
|
||||
lowestcost=cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cheapestmerge1>=0) {
|
||||
gc_combine(&dr->rects[cheapestmerge1],&dr->rects[cheapestmerge2]);
|
||||
dr->rects[cheapestmerge2]=dr->rects[dr->used-1];
|
||||
dr->rects[dr->used-1]=*area;
|
||||
} else {
|
||||
gc_combine(&dr->rects[cheapest],area);
|
||||
}
|
||||
// NB: clusters do not intersect (or intersection will
|
||||
// overwrite). This is a result of the above algorithm,
|
||||
// given the assumption that (x,y) are ordered topleft
|
||||
// to bottomright.
|
||||
return(TRUE);
|
||||
int
|
||||
add_dirty_rect(dirty_rect *dr, GRECT *area)
|
||||
{
|
||||
int cursor;
|
||||
long lowestcost = 9999999L;
|
||||
int cheapest = -1;
|
||||
int cheapestmerge1 = -1;
|
||||
int cheapestmerge2 = -1;
|
||||
int merge1;
|
||||
int merge2;
|
||||
for (cursor = 0; cursor < dr->used; cursor++) {
|
||||
if (gc_inside(&dr->rects[cursor], area)) {
|
||||
/* Wholly contained already. */
|
||||
return (TRUE);
|
||||
}
|
||||
}
|
||||
for (cursor = 0; cursor < dr->used; cursor++) {
|
||||
if (gc_touch(&dr->rects[cursor], area)) {
|
||||
GRECT larger = dr->rects[cursor];
|
||||
long cost;
|
||||
gc_combine(&larger, area);
|
||||
cost = gc_area(&larger) - gc_area(&dr->rects[cursor]);
|
||||
if (cost < lowestcost) {
|
||||
int bad = FALSE, c;
|
||||
for (c = 0; c < dr->used && !bad; c++) {
|
||||
bad = gc_touch(&dr->rects[c], &larger) && c != cursor;
|
||||
}
|
||||
if (!bad) {
|
||||
cheapest = cursor;
|
||||
lowestcost = cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cheapest >= 0) {
|
||||
gc_combine(&dr->rects[cheapest], area);
|
||||
return (TRUE);
|
||||
}
|
||||
if (dr->used < dr->max) {
|
||||
dr->rects[dr->used++] = *area;
|
||||
return (TRUE);
|
||||
}
|
||||
// Do cheapest of:
|
||||
// add to closest cluster
|
||||
// do cheapest cluster merge, add to new cluster
|
||||
lowestcost = 9999999L;
|
||||
cheapest = -1;
|
||||
for (cursor = 0; cursor < dr->used; cursor++) {
|
||||
GRECT larger = dr->rects[cursor];
|
||||
long cost;
|
||||
gc_combine(&larger, area);
|
||||
cost = gc_area(&larger) - gc_area(&dr->rects[cursor]);
|
||||
if (cost < lowestcost) {
|
||||
int bad = FALSE, c;
|
||||
for (c = 0; c < dr->used && !bad; c++) {
|
||||
bad = gc_touch(&dr->rects[c], &larger) && c != cursor;
|
||||
}
|
||||
if (!bad) {
|
||||
cheapest = cursor;
|
||||
lowestcost = cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
// XXX could make an heuristic guess as to whether we
|
||||
// XXX need to bother looking for a cheap merge.
|
||||
for (merge1 = 0; merge1 < dr->used; merge1++) {
|
||||
for (merge2 = 0; merge2 < dr->used; merge2++) {
|
||||
if (merge1 != merge2) {
|
||||
GRECT larger = dr->rects[merge1];
|
||||
long cost;
|
||||
gc_combine(&larger, &dr->rects[merge2]);
|
||||
cost = gc_area(&larger) - gc_area(&dr->rects[merge1])
|
||||
- gc_area(&dr->rects[merge2]);
|
||||
if (cost < lowestcost) {
|
||||
int bad = FALSE, c;
|
||||
for (c = 0; c < dr->used && !bad; c++) {
|
||||
bad = gc_touch(&dr->rects[c], &larger) && c != cursor;
|
||||
}
|
||||
if (!bad) {
|
||||
cheapestmerge1 = merge1;
|
||||
cheapestmerge2 = merge2;
|
||||
lowestcost = cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cheapestmerge1 >= 0) {
|
||||
gc_combine(&dr->rects[cheapestmerge1], &dr->rects[cheapestmerge2]);
|
||||
dr->rects[cheapestmerge2] = dr->rects[dr->used - 1];
|
||||
dr->rects[dr->used - 1] = *area;
|
||||
} else {
|
||||
gc_combine(&dr->rects[cheapest], area);
|
||||
}
|
||||
// NB: clusters do not intersect (or intersection will
|
||||
// overwrite). This is a result of the above algorithm,
|
||||
// given the assumption that (x,y) are ordered topleft
|
||||
// to bottomright.
|
||||
return (TRUE);
|
||||
}
|
||||
int get_dirty_rect(dirty_rect* dr,GRECT *area){
|
||||
if(dr==NULL || area==NULL || dr->rects==NULL || dr->used<=0 || dr->max<=0)
|
||||
return(FALSE);
|
||||
*area=dr->rects[--dr->used];
|
||||
return(TRUE);
|
||||
int
|
||||
get_dirty_rect(dirty_rect *dr, GRECT *area)
|
||||
{
|
||||
if (dr == NULL || area == NULL || dr->rects == NULL || dr->used <= 0
|
||||
|| dr->max <= 0)
|
||||
return (FALSE);
|
||||
*area = dr->rects[--dr->used];
|
||||
return (TRUE);
|
||||
}
|
||||
int clear_dirty_rect(dirty_rect *dr){
|
||||
if(dr)
|
||||
dr->used=0;
|
||||
return(TRUE);
|
||||
int
|
||||
clear_dirty_rect(dirty_rect *dr)
|
||||
{
|
||||
if (dr)
|
||||
dr->used = 0;
|
||||
return (TRUE);
|
||||
}
|
||||
int resize_dirty_rect(dirty_rect *dr,int new_size){
|
||||
return(FALSE);
|
||||
int
|
||||
resize_dirty_rect(dirty_rect *dr, int new_size)
|
||||
{
|
||||
return (FALSE);
|
||||
}
|
||||
static int gc_inside(GRECT *frame,GRECT *test){
|
||||
if(frame && test && frame->g_x<=test->g_x && frame->g_y<=test->g_y &&
|
||||
frame->g_x+frame->g_w>=test->g_x+test->g_w &&
|
||||
frame->g_y+frame->g_h>=test->g_y+test->g_h
|
||||
)
|
||||
return(TRUE);
|
||||
return(FALSE);
|
||||
static int
|
||||
gc_inside(GRECT *frame, GRECT *test)
|
||||
{
|
||||
if (frame && test && frame->g_x <= test->g_x && frame->g_y <= test->g_y
|
||||
&& frame->g_x + frame->g_w >= test->g_x + test->g_w
|
||||
&& frame->g_y + frame->g_h >= test->g_y + test->g_h)
|
||||
return (TRUE);
|
||||
return (FALSE);
|
||||
}
|
||||
static int gc_touch(GRECT *frame,GRECT *test){
|
||||
GRECT tmp={test->g_x-1,test->g_y-1,test->g_w+2,test->g_h+2};
|
||||
return(rc_intersect(frame,&tmp));
|
||||
static int
|
||||
gc_touch(GRECT *frame, GRECT *test)
|
||||
{
|
||||
GRECT tmp = { test->g_x - 1, test->g_y - 1, test->g_w + 2,
|
||||
test->g_h + 2 };
|
||||
return (rc_intersect(frame, &tmp));
|
||||
}
|
||||
static void gc_combine(GRECT *frame,GRECT *test){
|
||||
if(!frame || !test)
|
||||
return;
|
||||
if(frame->g_x>test->g_x){
|
||||
frame->g_w+=frame->g_x-test->g_x;
|
||||
frame->g_x=test->g_x;
|
||||
}
|
||||
if(frame->g_y>test->g_y){
|
||||
frame->g_h+=frame->g_y-test->g_y;
|
||||
frame->g_y=test->g_y;
|
||||
}
|
||||
if(frame->g_x+frame->g_w<test->g_x+test->g_w)
|
||||
frame->g_w=test->g_x+test->g_w-frame->g_x;
|
||||
if(frame->g_y+frame->g_h<test->g_y+test->g_h)
|
||||
frame->g_h=test->g_y+test->g_h-frame->g_y;
|
||||
static void
|
||||
gc_combine(GRECT *frame, GRECT *test)
|
||||
{
|
||||
if (!frame || !test)
|
||||
return;
|
||||
if (frame->g_x > test->g_x) {
|
||||
frame->g_w += frame->g_x - test->g_x;
|
||||
frame->g_x = test->g_x;
|
||||
}
|
||||
if (frame->g_y > test->g_y) {
|
||||
frame->g_h += frame->g_y - test->g_y;
|
||||
frame->g_y = test->g_y;
|
||||
}
|
||||
if (frame->g_x + frame->g_w < test->g_x + test->g_w)
|
||||
frame->g_w = test->g_x + test->g_w - frame->g_x;
|
||||
if (frame->g_y + frame->g_h < test->g_y + test->g_h)
|
||||
frame->g_h = test->g_y + test->g_h - frame->g_y;
|
||||
}
|
||||
static long gc_area(GRECT *area){
|
||||
return((long)area->g_h*(long)area->g_w);
|
||||
static long
|
||||
gc_area(GRECT *area)
|
||||
{
|
||||
return ((long) area->g_h * (long) area->g_w);
|
||||
}
|
||||
|
||||
+267
-238
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$
|
||||
* $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.4 $
|
||||
* $Date: 2002/03/20 03:45:03 $ $Revision: 1.2 $
|
||||
*/
|
||||
#define __TCC_COMPAT__
|
||||
@@ -15,279 +15,308 @@
|
||||
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#define TRUE !FALSE
|
||||
#define TRUE !FALSE
|
||||
#endif
|
||||
|
||||
/* VDI <-> Device palette order conversion matrixes: */
|
||||
/* Four-plane vdi-device */
|
||||
int vdi2dev4[]={0,15,1,2,4,6,3,5,7,8,9,10,12,14,11,13};
|
||||
int vdi2dev4[] = { 0, 15, 1, 2, 4, 6, 3, 5, 7, 8, 9, 10, 12, 14, 11, 13 };
|
||||
/* Two-plane vdi-device */
|
||||
int vdi2dev2[]={0,3,1,2};
|
||||
int vdi2dev2[] = { 0, 3, 1, 2 };
|
||||
|
||||
void get_colors(int handle, short *palette, int col){
|
||||
int i, idx;
|
||||
void
|
||||
get_colors(int handle, short *palette, int col)
|
||||
{
|
||||
int i, idx;
|
||||
|
||||
/* get current color palette */
|
||||
for(i=0; i < col; i ++){
|
||||
/* device->vdi->device palette order */
|
||||
switch(planes){
|
||||
case 1:
|
||||
idx=i;break;
|
||||
case 2:
|
||||
idx=vdi2dev2[i];break;
|
||||
case 4:
|
||||
idx=vdi2dev4[i];break;
|
||||
default:
|
||||
if(i<16)
|
||||
idx=vdi2dev4[i];
|
||||
else
|
||||
idx= i==255 ? 1 : i;
|
||||
}
|
||||
vq_color(handle, i, 0, (int *)palette + idx * 3);
|
||||
}
|
||||
}
|
||||
|
||||
void img_set_colors(int handle, short *palette, int col){
|
||||
int i, idx, end;
|
||||
|
||||
/* set color palette */
|
||||
end=min(1<<col,1<<planes);
|
||||
for(i=0; i<end; i++){
|
||||
switch(planes){ /* MAR -- war col 10.01.2001 */
|
||||
case 1:
|
||||
idx=i;break;
|
||||
case 2:
|
||||
idx=vdi2dev2[i];break;
|
||||
case 4:
|
||||
idx=vdi2dev4[i];break;
|
||||
default:
|
||||
if(i<16)
|
||||
idx=vdi2dev4[i];
|
||||
else
|
||||
idx= i==255 ? 1 : i;
|
||||
/* get current color palette */
|
||||
for (i = 0; i < col; i++) {
|
||||
/* device->vdi->device palette order */
|
||||
switch (planes) {
|
||||
case 1:
|
||||
idx = i;
|
||||
break;
|
||||
case 2:
|
||||
idx = vdi2dev2[i];
|
||||
break;
|
||||
case 4:
|
||||
idx = vdi2dev4[i];
|
||||
break;
|
||||
default:
|
||||
if (i < 16)
|
||||
idx = vdi2dev4[i];
|
||||
else
|
||||
idx = i == 255 ? 1 : i;
|
||||
}
|
||||
vq_color(handle, i, 0, (int *) palette + idx * 3);
|
||||
}
|
||||
vs_color(handle, i, (int *)palette + idx * 3);
|
||||
}
|
||||
}
|
||||
|
||||
int convert(MFDB *image, long size){
|
||||
int plane, mplanes;
|
||||
char *line_addr, *buf_addr, *new_addr, *new1_addr, *image_addr, *screen_addr;
|
||||
MFDB dev_form, tmp;
|
||||
long new_size;
|
||||
void
|
||||
img_set_colors(int handle, short *palette, int col)
|
||||
{
|
||||
int i, idx, end;
|
||||
|
||||
/* convert size from words to bytes */
|
||||
size <<= 1;
|
||||
|
||||
/* memory for the device raster */
|
||||
new_size=size*(long)planes;
|
||||
if((new_addr=(char *) calloc(1,new_size)) == NULL)
|
||||
return(FALSE);
|
||||
|
||||
/* initialize MFDBs */
|
||||
tmp=*image;
|
||||
tmp.fd_nplanes=planes;
|
||||
tmp.fd_addr=new_addr;
|
||||
tmp.fd_stand=1; /* standard format */
|
||||
dev_form=tmp;
|
||||
screen_addr=new_addr;
|
||||
dev_form.fd_stand=0; /* device format */
|
||||
image_addr=(char *)image->fd_addr;
|
||||
|
||||
/* initialize some variables and zero temp. line buffer */
|
||||
mplanes=min(image->fd_nplanes, planes);
|
||||
/* convert image */
|
||||
line_addr=image_addr;
|
||||
buf_addr=screen_addr;
|
||||
if(mplanes>1){
|
||||
/* cut/pad color planes into temp buf */
|
||||
for(plane=0; plane<mplanes; plane ++){
|
||||
memcpy(buf_addr, line_addr, size);
|
||||
line_addr += size;
|
||||
buf_addr += size;
|
||||
}
|
||||
}else{
|
||||
/* fill temp line bitplanes with a b&w line */
|
||||
for(plane=0; plane < planes; plane ++){
|
||||
memcpy(buf_addr, line_addr, size);
|
||||
buf_addr += size;
|
||||
}
|
||||
}
|
||||
free(image->fd_addr);
|
||||
/* convert image line in temp into current device raster format */
|
||||
if((new1_addr=(char *) calloc(1,new_size)) == NULL)
|
||||
return(FALSE);
|
||||
dev_form.fd_addr=new1_addr;
|
||||
vr_trnfm(x_handle, &tmp, &dev_form);
|
||||
free(new_addr);
|
||||
|
||||
/* change image description */
|
||||
image->fd_stand=0; /* device format */
|
||||
image->fd_addr=new1_addr;
|
||||
image->fd_nplanes=planes;
|
||||
return(TRUE);
|
||||
/* set color palette */
|
||||
end = min(1 << col, 1 << planes);
|
||||
for (i = 0; i < end; i++) {
|
||||
switch (planes) { /* MAR -- war col 10.01.2001 */
|
||||
case 1:
|
||||
idx = i;
|
||||
break;
|
||||
case 2:
|
||||
idx = vdi2dev2[i];
|
||||
break;
|
||||
case 4:
|
||||
idx = vdi2dev4[i];
|
||||
break;
|
||||
default:
|
||||
if (i < 16)
|
||||
idx = vdi2dev4[i];
|
||||
else
|
||||
idx = i == 255 ? 1 : i;
|
||||
}
|
||||
vs_color(handle, i, (int *) palette + idx * 3);
|
||||
}
|
||||
}
|
||||
|
||||
int transform_img(MFDB *image){ /* return FALSE if transform_img fails */
|
||||
int success;
|
||||
long size;
|
||||
int
|
||||
convert(MFDB *image, long size)
|
||||
{
|
||||
int plane, mplanes;
|
||||
char *line_addr, *buf_addr, *new_addr, *new1_addr, *image_addr,
|
||||
*screen_addr;
|
||||
MFDB dev_form, tmp;
|
||||
long new_size;
|
||||
|
||||
if(!image->fd_addr)
|
||||
return(FALSE);
|
||||
/* convert size from words to bytes */
|
||||
size <<= 1;
|
||||
|
||||
size=(long)((long)image->fd_wdwidth * (long)image->fd_h);
|
||||
success=convert(image, size); /* Use vr_trfm(), which needs quite a lot memory. */
|
||||
if(success) return(TRUE);
|
||||
/* else show_error(ERR_ALLOC); */
|
||||
return(FALSE);
|
||||
/* memory for the device raster */
|
||||
new_size = size * (long) planes;
|
||||
if ((new_addr = (char *) calloc(1, new_size)) == NULL)
|
||||
return (FALSE);
|
||||
|
||||
/* initialize MFDBs */
|
||||
tmp = *image;
|
||||
tmp.fd_nplanes = planes;
|
||||
tmp.fd_addr = new_addr;
|
||||
tmp.fd_stand = 1; /* standard format */
|
||||
dev_form = tmp;
|
||||
screen_addr = new_addr;
|
||||
dev_form.fd_stand = 0; /* device format */
|
||||
image_addr = (char *) image->fd_addr;
|
||||
|
||||
/* initialize some variables and zero temp. line buffer */
|
||||
mplanes = min(image->fd_nplanes, planes);
|
||||
/* convert image */
|
||||
line_addr = image_addr;
|
||||
buf_addr = screen_addr;
|
||||
if (mplanes > 1) {
|
||||
/* cut/pad color planes into temp buf */
|
||||
for (plane = 0; plane < mplanes; plane++) {
|
||||
memcpy(buf_addr, line_addr, size);
|
||||
line_addr += size;
|
||||
buf_addr += size;
|
||||
}
|
||||
} else {
|
||||
/* fill temp line bitplanes with a b&w line */
|
||||
for (plane = 0; plane < planes; plane++) {
|
||||
memcpy(buf_addr, line_addr, size);
|
||||
buf_addr += size;
|
||||
}
|
||||
}
|
||||
free(image->fd_addr);
|
||||
/* convert image line in temp into current device raster format */
|
||||
if ((new1_addr = (char *) calloc(1, new_size)) == NULL)
|
||||
return (FALSE);
|
||||
dev_form.fd_addr = new1_addr;
|
||||
vr_trnfm(x_handle, &tmp, &dev_form);
|
||||
free(new_addr);
|
||||
|
||||
/* change image description */
|
||||
image->fd_stand = 0; /* device format */
|
||||
image->fd_addr = new1_addr;
|
||||
image->fd_nplanes = planes;
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
int
|
||||
transform_img(MFDB *image)
|
||||
{ /* return FALSE if transform_img fails */
|
||||
int success;
|
||||
long size;
|
||||
|
||||
if (!image->fd_addr)
|
||||
return (FALSE);
|
||||
|
||||
size = (long) ((long) image->fd_wdwidth * (long) image->fd_h);
|
||||
success = convert(
|
||||
image, size); /* Use vr_trfm(), which needs quite a lot memory. */
|
||||
if (success)
|
||||
return (TRUE);
|
||||
/* else show_error(ERR_ALLOC); */
|
||||
return (FALSE);
|
||||
}
|
||||
|
||||
/* Loads & depacks IMG (0 if succeded, else error). */
|
||||
/* Bitplanes are one after another in address IMG_HEADER.addr. */
|
||||
int depack_img(char *name, IMG_header *pic){
|
||||
int b, line, plane, width, word_aligned, opcode, patt_len, pal_size,
|
||||
byte_repeat, patt_repeat, scan_repeat, error = FALSE;
|
||||
char *pattern, *to, *endline, *puffer, sol_pat;
|
||||
long size;
|
||||
FILE *fp;
|
||||
int
|
||||
depack_img(char *name, IMG_header *pic)
|
||||
{
|
||||
int b, line, plane, width, word_aligned, opcode, patt_len, pal_size,
|
||||
byte_repeat, patt_repeat, scan_repeat, error = FALSE;
|
||||
char *pattern, *to, *endline, *puffer, sol_pat;
|
||||
long size;
|
||||
FILE *fp;
|
||||
|
||||
if((fp = fopen(name, "rb")) == NULL)
|
||||
return(ERR_FILE);
|
||||
if ((fp = fopen(name, "rb")) == NULL)
|
||||
return (ERR_FILE);
|
||||
|
||||
setvbuf(fp,NULL,_IOLBF,BUFSIZ);
|
||||
setvbuf(fp, NULL, _IOLBF, BUFSIZ);
|
||||
|
||||
/* read header info (bw & ximg) into image structure */
|
||||
fread((char *)&(pic->version), 2, 8 + 3, fp);
|
||||
/* read header info (bw & ximg) into image structure */
|
||||
fread((char *) &(pic->version), 2, 8 + 3, fp);
|
||||
|
||||
/* only 2-256 color imgs */
|
||||
if(pic->planes < 1 || pic->planes > 8){
|
||||
error = ERR_COLOR;
|
||||
goto end_depack;
|
||||
}
|
||||
/* only 2-256 color imgs */
|
||||
if (pic->planes < 1 || pic->planes > 8) {
|
||||
error = ERR_COLOR;
|
||||
goto end_depack;
|
||||
}
|
||||
|
||||
/* if XIMG, read info */
|
||||
if(pic->magic == XIMG && pic->paltype == 0){
|
||||
pal_size = (1 << pic->planes) * 3 * 2;
|
||||
if((pic->palette = (short *)calloc(1,pal_size))){
|
||||
fread((char *)pic->palette, 1, pal_size, fp);
|
||||
}
|
||||
}else{
|
||||
pic->palette = NULL;
|
||||
}
|
||||
/* if XIMG, read info */
|
||||
if (pic->magic == XIMG && pic->paltype == 0) {
|
||||
pal_size = (1 << pic->planes) * 3 * 2;
|
||||
if ((pic->palette = (short *) calloc(1, pal_size))) {
|
||||
fread((char *) pic->palette, 1, pal_size, fp);
|
||||
}
|
||||
} else {
|
||||
pic->palette = NULL;
|
||||
}
|
||||
|
||||
/* width in bytes word aliged */
|
||||
word_aligned = (pic->img_w + 15) >> 4;
|
||||
word_aligned <<= 1;
|
||||
/* width in bytes word aliged */
|
||||
word_aligned = (pic->img_w + 15) >> 4;
|
||||
word_aligned <<= 1;
|
||||
|
||||
/* width byte aligned */
|
||||
width = (pic->img_w + 7) >> 3;
|
||||
/* width byte aligned */
|
||||
width = (pic->img_w + 7) >> 3;
|
||||
|
||||
/* allocate memory for the picture */
|
||||
free(pic->addr);
|
||||
size = (long)((long)word_aligned * (long)pic->img_h * (long)pic->planes); /*MAR*/
|
||||
/* allocate memory for the picture */
|
||||
free(pic->addr);
|
||||
size = (long) ((long) word_aligned * (long) pic->img_h
|
||||
* (long) pic->planes); /*MAR*/
|
||||
|
||||
/* check for header validity & malloc long... */
|
||||
if (pic->length > 7 && pic->planes < 33 && pic->img_w > 0 && pic->img_h > 0){
|
||||
if(!(pic->addr=(char *)calloc(1,size))){
|
||||
error = ERR_ALLOC;
|
||||
goto end_depack;
|
||||
}
|
||||
}else{
|
||||
error = ERR_HEADER;
|
||||
goto end_depack;
|
||||
}
|
||||
/* check for header validity & malloc long... */
|
||||
if (pic->length > 7 && pic->planes < 33 && pic->img_w > 0
|
||||
&& pic->img_h > 0) {
|
||||
if (!(pic->addr = (char *) calloc(1, size))) {
|
||||
error = ERR_ALLOC;
|
||||
goto end_depack;
|
||||
}
|
||||
} else {
|
||||
error = ERR_HEADER;
|
||||
goto end_depack;
|
||||
}
|
||||
|
||||
patt_len = pic->pat_len;
|
||||
patt_len = pic->pat_len;
|
||||
|
||||
/* jump over the header and possible (XIMG) info */
|
||||
fseek(fp, (long) pic->length * 2L, SEEK_SET);
|
||||
/* jump over the header and possible (XIMG) info */
|
||||
fseek(fp, (long) pic->length * 2L, SEEK_SET);
|
||||
|
||||
for(line=0,to=pic->addr; line<pic->img_h; line+=scan_repeat){ /* depack whole img */
|
||||
for(plane=0,scan_repeat=1; plane<pic->planes; plane++){ /* depack one scan line */
|
||||
puffer=to=pic->addr+(long)(line+plane*pic->img_h)*(long)word_aligned;
|
||||
endline=puffer+width;
|
||||
do{ /* depack one line in one bitplane */
|
||||
switch((opcode= fgetc(fp))){
|
||||
case 0: /* pattern or scan repeat */
|
||||
if((patt_repeat=fgetc(fp))){ /* repeat a pattern */
|
||||
fread(to,patt_len,1,fp);
|
||||
pattern=to;
|
||||
to+=patt_len;
|
||||
while(--patt_repeat){ /* copy pattern */
|
||||
memcpy(to,pattern,patt_len);
|
||||
to+=patt_len;
|
||||
}
|
||||
}else{ /* repeat a line */
|
||||
if(fgetc(fp)==0xFF)
|
||||
scan_repeat=fgetc(fp);
|
||||
else{
|
||||
error = ERR_DEPACK;
|
||||
goto end_depack;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x80: /* Literal */
|
||||
byte_repeat=fgetc(fp);
|
||||
fread(to,byte_repeat,1,fp);
|
||||
to+=byte_repeat;
|
||||
break;
|
||||
default: /* Solid run */
|
||||
byte_repeat = opcode & 0x7F;
|
||||
sol_pat = opcode&0x80 ? 0xFF : 0x00;
|
||||
while(byte_repeat--) *to++=sol_pat;
|
||||
}
|
||||
}while(to<endline);
|
||||
for (line = 0, to = pic->addr; line < pic->img_h;
|
||||
line += scan_repeat) { /* depack whole img */
|
||||
for (plane = 0, scan_repeat = 1; plane < pic->planes;
|
||||
plane++) { /* depack one scan line */
|
||||
puffer = to =
|
||||
pic->addr
|
||||
+ (long) (line + plane * pic->img_h) * (long) word_aligned;
|
||||
endline = puffer + width;
|
||||
do { /* depack one line in one bitplane */
|
||||
switch ((opcode = fgetc(fp))) {
|
||||
case 0: /* pattern or scan repeat */
|
||||
if ((patt_repeat = fgetc(fp))) { /* repeat a pattern */
|
||||
fread(to, patt_len, 1, fp);
|
||||
pattern = to;
|
||||
to += patt_len;
|
||||
while (--patt_repeat) { /* copy pattern */
|
||||
memcpy(to, pattern, patt_len);
|
||||
to += patt_len;
|
||||
}
|
||||
} else { /* repeat a line */
|
||||
if (fgetc(fp) == 0xFF)
|
||||
scan_repeat = fgetc(fp);
|
||||
else {
|
||||
error = ERR_DEPACK;
|
||||
goto end_depack;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 0x80: /* Literal */
|
||||
byte_repeat = fgetc(fp);
|
||||
fread(to, byte_repeat, 1, fp);
|
||||
to += byte_repeat;
|
||||
break;
|
||||
default: /* Solid run */
|
||||
byte_repeat = opcode & 0x7F;
|
||||
sol_pat = opcode & 0x80 ? 0xFF : 0x00;
|
||||
while (byte_repeat--)
|
||||
*to++ = sol_pat;
|
||||
}
|
||||
} while (to < endline);
|
||||
|
||||
if(to == endline){
|
||||
/* ensure that lines aren't repeated past the end of the img */
|
||||
if(line + scan_repeat > pic->img_h)
|
||||
scan_repeat = pic->img_h - line;
|
||||
/* copy line to image buffer */
|
||||
if(scan_repeat>1){
|
||||
/* calculate address of a current line in a current bitplane */
|
||||
/* to=pic->addr+(long)(line+1+plane*pic->img_h)*(long)word_aligned;*/
|
||||
for(b=scan_repeat-1; b; --b){
|
||||
memcpy(to, puffer, width);
|
||||
to+=word_aligned;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
error = ERR_DEPACK;
|
||||
goto end_depack;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (to == endline) {
|
||||
/* ensure that lines aren't repeated past the end of the img
|
||||
*/
|
||||
if (line + scan_repeat > pic->img_h)
|
||||
scan_repeat = pic->img_h - line;
|
||||
/* copy line to image buffer */
|
||||
if (scan_repeat > 1) {
|
||||
/* calculate address of a current line in a current
|
||||
* bitplane */
|
||||
/* to=pic->addr+(long)(line+1+plane*pic->img_h)*(long)word_aligned;*/
|
||||
for (b = scan_repeat - 1; b; --b) {
|
||||
memcpy(to, puffer, width);
|
||||
to += word_aligned;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
error = ERR_DEPACK;
|
||||
goto end_depack;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
end_depack:
|
||||
fclose(fp);
|
||||
return(error);
|
||||
end_depack:
|
||||
fclose(fp);
|
||||
return (error);
|
||||
}
|
||||
|
||||
int half_img(MFDB *s, MFDB *d){
|
||||
int pxy[8], i, j;
|
||||
MFDB tmp;
|
||||
int
|
||||
half_img(MFDB *s, MFDB *d)
|
||||
{
|
||||
int pxy[8], i, j;
|
||||
MFDB tmp;
|
||||
|
||||
mfdb(&tmp,NULL,s->fd_w/2,s->fd_h,s->fd_stand,s->fd_nplanes);
|
||||
tmp.fd_w=s->fd_w/2;
|
||||
tmp.fd_addr=calloc(1,mfdb_size(&tmp));
|
||||
if(!tmp.fd_addr)
|
||||
return(FALSE);
|
||||
mfdb(&tmp, NULL, s->fd_w / 2, s->fd_h, s->fd_stand, s->fd_nplanes);
|
||||
tmp.fd_w = s->fd_w / 2;
|
||||
tmp.fd_addr = calloc(1, mfdb_size(&tmp));
|
||||
if (!tmp.fd_addr)
|
||||
return (FALSE);
|
||||
|
||||
pxy[1]=pxy[5]=0;
|
||||
pxy[3]=pxy[7]=s->fd_h-1;
|
||||
for(i=0;i<s->fd_w/2;i++){
|
||||
pxy[0]=pxy[2]=2*i;
|
||||
pxy[4]=pxy[6]=i;
|
||||
vro_cpyfm(x_handle,S_ONLY,pxy,s,&tmp);
|
||||
}
|
||||
pxy[0]=pxy[4]=0;
|
||||
pxy[2]=pxy[6]=s->fd_w/2-1;
|
||||
for(j=0;j<s->fd_h/2;j++){
|
||||
pxy[1]=pxy[3]=2*j;
|
||||
pxy[5]=pxy[7]=j;
|
||||
vro_cpyfm(x_handle,S_ONLY,pxy,&tmp,d);
|
||||
}
|
||||
free(tmp.fd_addr);
|
||||
return(TRUE);
|
||||
pxy[1] = pxy[5] = 0;
|
||||
pxy[3] = pxy[7] = s->fd_h - 1;
|
||||
for (i = 0; i < s->fd_w / 2; i++) {
|
||||
pxy[0] = pxy[2] = 2 * i;
|
||||
pxy[4] = pxy[6] = i;
|
||||
vro_cpyfm(x_handle, S_ONLY, pxy, s, &tmp);
|
||||
}
|
||||
pxy[0] = pxy[4] = 0;
|
||||
pxy[2] = pxy[6] = s->fd_w / 2 - 1;
|
||||
for (j = 0; j < s->fd_h / 2; j++) {
|
||||
pxy[1] = pxy[3] = 2 * j;
|
||||
pxy[5] = pxy[7] = j;
|
||||
vro_cpyfm(x_handle, S_ONLY, pxy, &tmp, d);
|
||||
}
|
||||
free(tmp.fd_addr);
|
||||
return (TRUE);
|
||||
}
|
||||
|
||||
+90
-87
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 tile2img.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 tile2img.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.5 $ */
|
||||
/* NetHack 3.6 tile2img.c $Date: 2009/05/06 10:56:40 $ $Revision: 1.2 $ */
|
||||
/* SCCS Id: @(#)tile2bmp.c 3.2 95/09/06 */
|
||||
/* Copyright (c) NetHack PC Development Team 1995 */
|
||||
@@ -18,16 +18,15 @@
|
||||
#include "bitmfile.h"
|
||||
|
||||
/* #define COLORS_IN_USE MAXCOLORMAPSIZE /* 256 colors */
|
||||
#define COLORS_IN_USE 16 /* 16 colors */
|
||||
|
||||
#define COLORS_IN_USE 16 /* 16 colors */
|
||||
|
||||
extern char *FDECL(tilename, (int, int));
|
||||
static void FDECL(build_ximgtile,(pixel (*)[TILE_X]));
|
||||
static void FDECL(build_ximgtile, (pixel(*) [TILE_X]));
|
||||
void get_color(unsigned int colind, struct RGB *rgb);
|
||||
void get_pixel(int x, int y, unsigned int *colind);
|
||||
|
||||
#if COLORS_IN_USE==16
|
||||
#define MAX_X 320 /* 2 per byte, 4 bits per pixel */
|
||||
#if COLORS_IN_USE == 16
|
||||
#define MAX_X 320 /* 2 per byte, 4 bits per pixel */
|
||||
#else
|
||||
#define MAX_X 640
|
||||
#endif
|
||||
@@ -37,9 +36,9 @@ FILE *tibfile2;
|
||||
|
||||
pixel tilepixels[TILE_Y][TILE_X];
|
||||
|
||||
char *tilefiles[] = { "..\\win\\share\\monsters.txt",
|
||||
"..\\win\\share\\objects.txt",
|
||||
"..\\win\\share\\other.txt"};
|
||||
char *tilefiles[] = { "..\\win\\share\\monsters.txt",
|
||||
"..\\win\\share\\objects.txt",
|
||||
"..\\win\\share\\other.txt" };
|
||||
|
||||
unsigned int **Bild_daten;
|
||||
int num_colors = 0;
|
||||
@@ -48,7 +47,7 @@ int max_tiles_in_row = 40;
|
||||
int tiles_in_row;
|
||||
int filenum;
|
||||
int initflag;
|
||||
int yoffset,xoffset;
|
||||
int yoffset, xoffset;
|
||||
char bmpname[128];
|
||||
FILE *fp;
|
||||
|
||||
@@ -57,102 +56,106 @@ main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (argc != 2) {
|
||||
Fprintf(stderr, "usage: tile2img outfile.img\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else
|
||||
strcpy(bmpname, argv[1]);
|
||||
if (argc != 2) {
|
||||
Fprintf(stderr, "usage: tile2img outfile.img\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else
|
||||
strcpy(bmpname, argv[1]);
|
||||
|
||||
#ifdef OBSOLETE
|
||||
bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
|
||||
if (bmpfile2 == (FILE *)0) {
|
||||
Fprintf(stderr, "Unable to open output file %s\n",
|
||||
NETHACK_PACKED_TILEFILE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
bmpfile2 = fopen(NETHACK_PACKED_TILEFILE, WRBMODE);
|
||||
if (bmpfile2 == (FILE *) 0) {
|
||||
Fprintf(stderr, "Unable to open output file %s\n",
|
||||
NETHACK_PACKED_TILEFILE);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
#endif
|
||||
|
||||
tilecount = 0;
|
||||
xoffset = yoffset = 0;
|
||||
initflag = 0;
|
||||
filenum = 0;
|
||||
fp = fopen(bmpname,"wb");
|
||||
if (!fp) {
|
||||
printf("Error creating tile file %s, aborting.\n",bmpname);
|
||||
exit(1);
|
||||
}
|
||||
fclose(fp);
|
||||
tilecount = 0;
|
||||
xoffset = yoffset = 0;
|
||||
initflag = 0;
|
||||
filenum = 0;
|
||||
fp = fopen(bmpname, "wb");
|
||||
if (!fp) {
|
||||
printf("Error creating tile file %s, aborting.\n", bmpname);
|
||||
exit(1);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
Bild_daten=(unsigned int **)malloc(MAX_Y*sizeof(unsigned int *));
|
||||
for(i=0;i<MAX_Y;i++)
|
||||
Bild_daten[i]=(unsigned int *)malloc(MAX_X*sizeof(unsigned int));
|
||||
Bild_daten = (unsigned int **) malloc(MAX_Y * sizeof(unsigned int *));
|
||||
for (i = 0; i < MAX_Y; i++)
|
||||
Bild_daten[i] = (unsigned int *) malloc(MAX_X * sizeof(unsigned int));
|
||||
|
||||
while (filenum < 3) {
|
||||
if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
|
||||
Fprintf(stderr,
|
||||
"usage: tile2img (from the util directory)\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
num_colors = colorsinmap;
|
||||
if (num_colors > 62) {
|
||||
Fprintf(stderr, "too many colors (%d)\n", num_colors);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while (read_text_tile(tilepixels)) {
|
||||
build_ximgtile(tilepixels);
|
||||
tilecount++;
|
||||
xoffset += TILE_X;
|
||||
if (xoffset >= MAX_X) {
|
||||
yoffset += TILE_Y;
|
||||
xoffset = 0;
|
||||
}
|
||||
}
|
||||
(void) fclose_text_file();
|
||||
++filenum;
|
||||
}
|
||||
Fprintf(stderr, "Total of %d tiles in memory.\n",tilecount);
|
||||
while (filenum < 3) {
|
||||
if (!fopen_text_file(tilefiles[filenum], RDTMODE)) {
|
||||
Fprintf(stderr, "usage: tile2img (from the util directory)\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
num_colors = colorsinmap;
|
||||
if (num_colors > 62) {
|
||||
Fprintf(stderr, "too many colors (%d)\n", num_colors);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
while (read_text_tile(tilepixels)) {
|
||||
build_ximgtile(tilepixels);
|
||||
tilecount++;
|
||||
xoffset += TILE_X;
|
||||
if (xoffset >= MAX_X) {
|
||||
yoffset += TILE_Y;
|
||||
xoffset = 0;
|
||||
}
|
||||
}
|
||||
(void) fclose_text_file();
|
||||
++filenum;
|
||||
}
|
||||
Fprintf(stderr, "Total of %d tiles in memory.\n", tilecount);
|
||||
|
||||
bitmap_to_file(XIMG, MAX_X, (tilecount/20+1)*16, 372, 372, 4, 16, bmpname, get_color, get_pixel ) ;
|
||||
bitmap_to_file(XIMG, MAX_X, (tilecount / 20 + 1) * 16, 372, 372, 4, 16,
|
||||
bmpname, get_color, get_pixel);
|
||||
|
||||
Fprintf(stderr, "Total of %d tiles written to %s.\n",tilecount, bmpname);
|
||||
Fprintf(stderr, "Total of %d tiles written to %s.\n", tilecount, bmpname);
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
}
|
||||
|
||||
void get_color(unsigned int colind, struct RGB *rgb){
|
||||
rgb->r=(1000L*(long)ColorMap[CM_RED][colind])/0xFF;
|
||||
rgb->g=(1000L*(long)ColorMap[CM_GREEN][colind])/0xFF;
|
||||
rgb->b=(1000L*(long)ColorMap[CM_BLUE][colind])/0xFF;
|
||||
void
|
||||
get_color(unsigned int colind, struct RGB *rgb)
|
||||
{
|
||||
rgb->r = (1000L * (long) ColorMap[CM_RED][colind]) / 0xFF;
|
||||
rgb->g = (1000L * (long) ColorMap[CM_GREEN][colind]) / 0xFF;
|
||||
rgb->b = (1000L * (long) ColorMap[CM_BLUE][colind]) / 0xFF;
|
||||
}
|
||||
|
||||
void get_pixel(int x, int y, unsigned int *colind){
|
||||
*colind=Bild_daten[y][x];
|
||||
void
|
||||
get_pixel(int x, int y, unsigned int *colind)
|
||||
{
|
||||
*colind = Bild_daten[y][x];
|
||||
}
|
||||
|
||||
static void
|
||||
build_ximgtile(pixels)
|
||||
pixel (*pixels)[TILE_X];
|
||||
{
|
||||
int cur_x, cur_y, cur_color;
|
||||
int x,y;
|
||||
int cur_x, cur_y, cur_color;
|
||||
int x, y;
|
||||
|
||||
for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
|
||||
for (cur_x = 0; cur_x < TILE_X; cur_x++) {
|
||||
for (cur_color = 0; cur_color < num_colors; cur_color++) {
|
||||
if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r &&
|
||||
ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g &&
|
||||
ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
|
||||
break;
|
||||
}
|
||||
if (cur_color >= num_colors)
|
||||
Fprintf(stderr, "color not in colormap!\n");
|
||||
y = cur_y + yoffset;
|
||||
x = cur_x + xoffset;
|
||||
Bild_daten[y][x] =cur_color;
|
||||
}
|
||||
}
|
||||
for (cur_y = 0; cur_y < TILE_Y; cur_y++) {
|
||||
for (cur_x = 0; cur_x < TILE_X; cur_x++) {
|
||||
for (cur_color = 0; cur_color < num_colors; cur_color++) {
|
||||
if (ColorMap[CM_RED][cur_color] == pixels[cur_y][cur_x].r
|
||||
&& ColorMap[CM_GREEN][cur_color] == pixels[cur_y][cur_x].g
|
||||
&& ColorMap[CM_BLUE][cur_color] == pixels[cur_y][cur_x].b)
|
||||
break;
|
||||
}
|
||||
if (cur_color >= num_colors)
|
||||
Fprintf(stderr, "color not in colormap!\n");
|
||||
y = cur_y + yoffset;
|
||||
x = cur_x + xoffset;
|
||||
Bild_daten[y][x] = cur_color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+831
-832
File diff suppressed because it is too large
Load Diff
+2495
-2200
File diff suppressed because it is too large
Load Diff
+145
-125
@@ -1,4 +1,4 @@
|
||||
/* NetHack 3.6 xpm2img.c $NHDT-Date$ $NHDT-Branch$:$NHDT-Revision$ */
|
||||
/* NetHack 3.6 xpm2img.c $NHDT-Date: 1431192775 2015/05/09 17:32:55 $ $NHDT-Branch: master $:$NHDT-Revision: 1.6 $ */
|
||||
/* NetHack 3.6 xpm2img.c $Date: 2009/05/06 10:56:48 $ $Revision: 1.3 $ */
|
||||
/* SCCS Id: @(#)xpm2img.c 3.5 2002/03/17 */
|
||||
/* Copyright (c) Christian Bressler 2002 */
|
||||
@@ -16,13 +16,13 @@ char *xpmgetline();
|
||||
unsigned int **Bild_daten;
|
||||
/* translation table from xpm characters to RGB and colormap slots */
|
||||
struct Ttable {
|
||||
char flag;
|
||||
struct RGB col;
|
||||
int slot; /* output colortable index */
|
||||
}ttable[256];
|
||||
char flag;
|
||||
struct RGB col;
|
||||
int slot; /* output colortable index */
|
||||
} ttable[256];
|
||||
struct RGB *ColorMap;
|
||||
int num_colors = 0;
|
||||
int width=0, height=0;
|
||||
int width = 0, height = 0;
|
||||
int initflag;
|
||||
FILE *fp;
|
||||
int
|
||||
@@ -30,66 +30,73 @@ main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i;
|
||||
int row, col, planeno;
|
||||
int farben, planes;
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "usage: tile2img infile.xpm outfile.img\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
initflag = 0;
|
||||
fp = fopen(argv[2],"wb");
|
||||
if (!fp) {
|
||||
printf("Error creating IMG-file %s, aborting.\n",argv[2]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fclose(fp);
|
||||
if(fopen_xpm_file(argv[1],"r")!=TRUE){
|
||||
printf("Error reading xpm-file %s, aborting.\n",argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
Bild_daten=(unsigned int **)malloc((long)height*sizeof(unsigned int *));
|
||||
for(i=0;i<height;i++)
|
||||
Bild_daten[i]=(unsigned int *)malloc((long)width*sizeof(unsigned int));
|
||||
for(row = 0;row<height;row++){
|
||||
char *xb = xpmgetline();
|
||||
int plane_offset;
|
||||
if(xb==0){
|
||||
printf("Error to few lines in xpm-file %s, aborting.\n",argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
for(col = 0;col<width;col++){
|
||||
int color = xb[col];
|
||||
if(!ttable[color].flag)
|
||||
fprintf(stderr, "Bad image data\n");
|
||||
Bild_daten[row][col]= ttable[color].slot;
|
||||
}
|
||||
}
|
||||
if(num_colors>256){
|
||||
fprintf(stderr,"ERROR: zuviele Farben\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}else if(num_colors>16){
|
||||
farben=256;
|
||||
planes=8;
|
||||
}else if(num_colors>2){
|
||||
farben=16;
|
||||
planes=4;
|
||||
}else{
|
||||
farben=2;
|
||||
planes=1;
|
||||
}
|
||||
bitmap_to_file(XIMG, width, height, 372, 372, planes, farben, argv[2], get_color, get_pixel );
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
int i;
|
||||
int row, col, planeno;
|
||||
int farben, planes;
|
||||
if (argc != 3) {
|
||||
fprintf(stderr, "usage: tile2img infile.xpm outfile.img\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
initflag = 0;
|
||||
fp = fopen(argv[2], "wb");
|
||||
if (!fp) {
|
||||
printf("Error creating IMG-file %s, aborting.\n", argv[2]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
fclose(fp);
|
||||
if (fopen_xpm_file(argv[1], "r") != TRUE) {
|
||||
printf("Error reading xpm-file %s, aborting.\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
Bild_daten =
|
||||
(unsigned int **) malloc((long) height * sizeof(unsigned int *));
|
||||
for (i = 0; i < height; i++)
|
||||
Bild_daten[i] =
|
||||
(unsigned int *) malloc((long) width * sizeof(unsigned int));
|
||||
for (row = 0; row < height; row++) {
|
||||
char *xb = xpmgetline();
|
||||
int plane_offset;
|
||||
if (xb == 0) {
|
||||
printf("Error to few lines in xpm-file %s, aborting.\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
for (col = 0; col < width; col++) {
|
||||
int color = xb[col];
|
||||
if (!ttable[color].flag)
|
||||
fprintf(stderr, "Bad image data\n");
|
||||
Bild_daten[row][col] = ttable[color].slot;
|
||||
}
|
||||
}
|
||||
if (num_colors > 256) {
|
||||
fprintf(stderr, "ERROR: zuviele Farben\n");
|
||||
exit(EXIT_FAILURE);
|
||||
} else if (num_colors > 16) {
|
||||
farben = 256;
|
||||
planes = 8;
|
||||
} else if (num_colors > 2) {
|
||||
farben = 16;
|
||||
planes = 4;
|
||||
} else {
|
||||
farben = 2;
|
||||
planes = 1;
|
||||
}
|
||||
bitmap_to_file(XIMG, width, height, 372, 372, planes, farben, argv[2],
|
||||
get_color, get_pixel);
|
||||
exit(EXIT_SUCCESS);
|
||||
/*NOTREACHED*/
|
||||
return 0;
|
||||
}
|
||||
void get_color(unsigned int colind, struct RGB *rgb){
|
||||
rgb->r=(1000L*(long)ColorMap[colind].r)/0xFF;
|
||||
rgb->g=(1000L*(long)ColorMap[colind].g)/0xFF;
|
||||
rgb->b=(1000L*(long)ColorMap[colind].b)/0xFF;
|
||||
void
|
||||
get_color(unsigned int colind, struct RGB *rgb)
|
||||
{
|
||||
rgb->r = (1000L * (long) ColorMap[colind].r) / 0xFF;
|
||||
rgb->g = (1000L * (long) ColorMap[colind].g) / 0xFF;
|
||||
rgb->b = (1000L * (long) ColorMap[colind].b) / 0xFF;
|
||||
}
|
||||
void get_pixel(int x, int y, unsigned int *colind){
|
||||
*colind=Bild_daten[y][x];
|
||||
void
|
||||
get_pixel(int x, int y, unsigned int *colind)
|
||||
{
|
||||
*colind = Bild_daten[y][x];
|
||||
}
|
||||
FILE *xpmfh = 0;
|
||||
char initbuf[200];
|
||||
@@ -97,70 +104,83 @@ char *xpmbuf = initbuf;
|
||||
/* version 1. Reads the raw xpm file, NOT the compiled version. This is
|
||||
* not a particularly good idea but I don't have time to do the right thing
|
||||
* at this point, even if I was absolutely sure what that was. */
|
||||
fopen_xpm_file(const char *fn, const char *mode){
|
||||
int temp;
|
||||
char *xb;
|
||||
if(strcmp(mode, "r"))return FALSE; /* no choice now */
|
||||
if(xpmfh)return FALSE; /* one file at a time */
|
||||
xpmfh = fopen(fn, mode);
|
||||
if(!xpmfh)return FALSE; /* I'm hard to please */
|
||||
/* read the header */
|
||||
xb = xpmgetline();
|
||||
if(xb == 0)return FALSE;
|
||||
if(4 != sscanf(xb,"%d %d %d %d",
|
||||
&width, &height,&num_colors, &temp))
|
||||
return FALSE; /* bad header */
|
||||
/* replace the original buffer with one big enough for
|
||||
* the real data
|
||||
*/
|
||||
/* XXX */
|
||||
xpmbuf = malloc(width * 2);
|
||||
if(!xpmbuf){
|
||||
fprintf(stderr,"ERROR: Can't allocate line buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
if(temp != 1)return FALSE; /* limitation of this code */
|
||||
{
|
||||
/* read the colormap and translation table */
|
||||
int ccount = -1;
|
||||
ColorMap = (struct RGB *)malloc((long)num_colors*sizeof(struct RGB));
|
||||
while(ccount++ < (num_colors-1)){
|
||||
char index;
|
||||
int r, g, b;
|
||||
xb = xpmgetline();
|
||||
if(xb==0)return FALSE;
|
||||
if(4 != sscanf(xb,"%c c #%2x%2x%2x",&index,&r,&g,&b)){
|
||||
fprintf(stderr,"Bad color entry: %s\n",xb);
|
||||
return FALSE;
|
||||
}
|
||||
ttable[index].flag = 1; /* this color is valid */
|
||||
ttable[index].col.r = r;
|
||||
ttable[index].col.g = g;
|
||||
ttable[index].col.b = b;
|
||||
ttable[index].slot = ccount;
|
||||
ColorMap[ccount].r=r;
|
||||
ColorMap[ccount].g=g;
|
||||
ColorMap[ccount].b=b;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
fopen_xpm_file(const char *fn, const char *mode)
|
||||
{
|
||||
int temp;
|
||||
char *xb;
|
||||
if (strcmp(mode, "r"))
|
||||
return FALSE; /* no choice now */
|
||||
if (xpmfh)
|
||||
return FALSE; /* one file at a time */
|
||||
xpmfh = fopen(fn, mode);
|
||||
if (!xpmfh)
|
||||
return FALSE; /* I'm hard to please */
|
||||
/* read the header */
|
||||
xb = xpmgetline();
|
||||
if (xb == 0)
|
||||
return FALSE;
|
||||
if (4 != sscanf(xb, "%d %d %d %d", &width, &height, &num_colors, &temp))
|
||||
return FALSE; /* bad header */
|
||||
/* replace the original buffer with one big enough for
|
||||
* the real data
|
||||
*/
|
||||
/* XXX */
|
||||
xpmbuf = malloc(width * 2);
|
||||
if (!xpmbuf) {
|
||||
fprintf(stderr, "ERROR: Can't allocate line buffer\n");
|
||||
exit(1);
|
||||
}
|
||||
if (temp != 1)
|
||||
return FALSE; /* limitation of this code */
|
||||
{
|
||||
/* read the colormap and translation table */
|
||||
int ccount = -1;
|
||||
ColorMap =
|
||||
(struct RGB *) malloc((long) num_colors * sizeof(struct RGB));
|
||||
while (ccount++ < (num_colors - 1)) {
|
||||
char index;
|
||||
int r, g, b;
|
||||
xb = xpmgetline();
|
||||
if (xb == 0)
|
||||
return FALSE;
|
||||
if (4 != sscanf(xb, "%c c #%2x%2x%2x", &index, &r, &g, &b)) {
|
||||
fprintf(stderr, "Bad color entry: %s\n", xb);
|
||||
return FALSE;
|
||||
}
|
||||
ttable[index].flag = 1; /* this color is valid */
|
||||
ttable[index].col.r = r;
|
||||
ttable[index].col.g = g;
|
||||
ttable[index].col.b = b;
|
||||
ttable[index].slot = ccount;
|
||||
ColorMap[ccount].r = r;
|
||||
ColorMap[ccount].g = g;
|
||||
ColorMap[ccount].b = b;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
/* This deserves better. Don't read it too closely - you'll get ill. */
|
||||
#define bufsz 2048
|
||||
char buf[bufsz];
|
||||
char *
|
||||
xpmgetline(){
|
||||
char *bp;
|
||||
do {
|
||||
if(fgets(buf, bufsz, xpmfh) == 0)return 0;
|
||||
} while(buf[0] != '"');
|
||||
/* strip off the trailing <",> if any */
|
||||
for(bp = buf;*bp;bp++);
|
||||
bp--;
|
||||
while(isspace(*bp))bp--;
|
||||
if(*bp==',')bp--;
|
||||
if(*bp=='"')bp--;
|
||||
bp++;
|
||||
*bp = '\0';
|
||||
return &buf[1];
|
||||
xpmgetline()
|
||||
{
|
||||
char *bp;
|
||||
do {
|
||||
if (fgets(buf, bufsz, xpmfh) == 0)
|
||||
return 0;
|
||||
} while (buf[0] != '"');
|
||||
/* strip off the trailing <",> if any */
|
||||
for (bp = buf; *bp; bp++)
|
||||
;
|
||||
bp--;
|
||||
while (isspace(*bp))
|
||||
bp--;
|
||||
if (*bp == ',')
|
||||
bp--;
|
||||
if (*bp == '"')
|
||||
bp--;
|
||||
bp++;
|
||||
*bp = '\0';
|
||||
return &buf[1];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user