fix narrowing conversion

This commit is contained in:
Chris Cromer 2019-05-01 17:54:43 -04:00
parent 0426daffe5
commit f5f3ee3155
Signed by: cromer
GPG Key ID: 39CC813FF3C8708A
2 changed files with 61 additions and 61 deletions

View File

@ -1,7 +1,7 @@
/* /*
* QT AGI Studio :: Copyright (C) 2000 Helen Zommer * QT AGI Studio :: Copyright (C) 2000 Helen Zommer
* *
* Almost all of the picture processing code is taken from showpic.c * Almost all of the picture processing code is taken from showpic.c
* by Lance Ewing <lance.e@ihug.co.nz> * by Lance Ewing <lance.e@ihug.co.nz>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -38,7 +38,7 @@
BPicture *ppicture; BPicture *ppicture;
//******************************************** //********************************************
//"bytemap" picture for preview - it is not going to be edited, //"bytemap" picture for preview - it is not going to be edited,
//so there is no need for the linked list and other things from the Picture class //so there is no need for the linked list and other things from the Picture class
BPicture::BPicture() BPicture::BPicture()
@ -414,8 +414,8 @@ void BPicture::absoluteLine(byte **data)
** on the pattern code. ** on the pattern code.
**************************************************************************/ **************************************************************************/
void BPicture::plotPattern(byte x, byte y) void BPicture::plotPattern(byte x, byte y)
{ {
static char circles[][15] = { /* agi circle bitmaps */ static unsigned char circles[][15] = { /* agi circle bitmaps */
{0x80}, {0x80},
{0xfc}, {0xfc},
{0x5f, 0xf4}, {0x5f, 0xf4},
@ -476,7 +476,7 @@ void BPicture::plotPattern(byte x, byte y)
} }
} }
} }
/************************************************************************** /**************************************************************************
@ -518,7 +518,7 @@ void BPicture::show(byte *picdata,int picsize)
priDrawEnabled = false; priDrawEnabled = false;
picColour = priColour = 0; picColour = priColour = 0;
do { do {
action = *(data++); action = *(data++);
switch (action) { switch (action) {
case 0xFF: stillDrawing = 0; break; case 0xFF: stillDrawing = 0; break;
@ -539,7 +539,7 @@ void BPicture::show(byte *picdata,int picsize)
case 0xFA: plotBrush(&data); break; case 0xFA: plotBrush(&data); break;
default: printf("Unknown picture code : %X\n", action); break; default: printf("Unknown picture code : %X\n", action); break;
} }
}while((data < (data + picsize)) && stillDrawing); }while((data < (data + picsize)) && stillDrawing);
} }
//**************************************************** //****************************************************

View File

@ -72,7 +72,7 @@ char *Picture::showPos(int *code,int *val)
int Picture::setBufPos(int inputValue) int Picture::setBufPos(int inputValue)
//set current picture buffer position to inputValue //set current picture buffer position to inputValue
{ {
if ((inputValue < 0) || (inputValue > bufLen)) return 1; if ((inputValue < 0) || (inputValue > bufLen)) return 1;
if (inputValue == bufLen) { if (inputValue == bufLen) {
@ -94,7 +94,7 @@ int Picture::setBufPos(int inputValue)
bufPos++; bufPos++;
} }
} }
/* Find current action position */ /* Find current action position */
while (picPos->node < 0xF0) { while (picPos->node < 0xF0) {
picPos = picPos->prior; picPos = picPos->prior;
@ -494,8 +494,8 @@ void Picture::absoluteLine(struct picCodeNode **temp)
** on the pattern code. ** on the pattern code.
**************************************************************************/ **************************************************************************/
void Picture::plotPattern(byte x, byte y) void Picture::plotPattern(byte x, byte y)
{ {
static char circles[][15] = { /* agi circle bitmaps */ static unsigned char circles[][15] = { /* agi circle bitmaps */
{0x80}, {0x80},
{0xfc}, {0xfc},
{0x5f, 0xf4}, {0x5f, 0xf4},
@ -556,7 +556,7 @@ void Picture::plotPattern(byte x, byte y)
} }
} }
} }
/************************************************************************** /**************************************************************************
@ -588,12 +588,12 @@ void Picture::load(byte *picdata,int picsize)
byte nodeData; byte nodeData;
struct picCodeNode *temp=NULL; struct picCodeNode *temp=NULL;
bool stillLoading=true; bool stillLoading=true;
//init link list //init link list
picPos = picStart = picLast = NULL; picPos = picStart = picLast = NULL;
addMode = INS_MODE; addMode = INS_MODE;
bufPos = bufLen = 0; bufPos = bufLen = 0;
do { do {
nodeData = *picdata++; nodeData = *picdata++;
picsize--; picsize--;
@ -627,19 +627,19 @@ int Picture::open(char *filename)
{ {
FILE *fptr = fopen(filename,"rb"); FILE *fptr = fopen(filename,"rb");
if(fptr==NULL){ if(fptr==NULL){
menu->errmes("Can't open file %s ! ",filename); menu->errmes("Can't open file %s ! ",filename);
return 1; return 1;
} }
struct stat buf; struct stat buf;
fstat(fileno(fptr),&buf); fstat(fileno(fptr),&buf);
ResourceData.Size=buf.st_size; ResourceData.Size=buf.st_size;
fread(ResourceData.Data,ResourceData.Size,1,fptr); fread(ResourceData.Data,ResourceData.Size,1,fptr);
fclose(fptr); fclose(fptr);
load(ResourceData.Data,ResourceData.Size); load(ResourceData.Data,ResourceData.Size);
refill_pic = refill_pri = false; refill_pic = refill_pri = false;
draw(); draw();
init(); init();
@ -653,7 +653,7 @@ int Picture::open(int ResNum)
int err = game->ReadResource(PICTURE,ResNum); int err = game->ReadResource(PICTURE,ResNum);
if(!err){ if(!err){
load(ResourceData.Data,ResourceData.Size); load(ResourceData.Data,ResourceData.Size);
refill_pic = refill_pri = false; refill_pic = refill_pri = false;
draw(); draw();
init(); init();
@ -672,9 +672,9 @@ int Picture::save(int ResNum)
//************************************************* //*************************************************
int Picture::save(char *filename) int Picture::save(char *filename)
{ {
FILE *fptr = fopen(filename,"wb"); FILE *fptr = fopen(filename,"wb");
if(fptr==NULL){ if(fptr==NULL){
menu->errmes("Can't open file %s ! ",filename); menu->errmes("Can't open file %s ! ",filename);
return 1; return 1;
@ -691,21 +691,21 @@ void Picture::save()
{ {
byte *ptr=ResourceData.Data; byte *ptr=ResourceData.Data;
struct picCodeNode *temp; struct picCodeNode *temp;
if (picStart == NULL) { /* Black picture */ if (picStart == NULL) { /* Black picture */
*ptr = 0xFF; /* End of picture marker */ *ptr = 0xFF; /* End of picture marker */
ResourceData.Size=1; ResourceData.Size=1;
return ; return ;
} }
temp = picStart; temp = picStart;
*ptr++ = temp->node; *ptr++ = temp->node;
do { do {
temp = temp->next; temp = temp->next;
*ptr++ = temp->node; *ptr++ = temp->node;
} while (temp->next != NULL); } while (temp->next != NULL);
*ptr++ = 0xFF; /* End of picture marker */ *ptr++ = 0xFF; /* End of picture marker */
ResourceData.Size = (int)(ptr-ResourceData.Data); ResourceData.Size = (int)(ptr-ResourceData.Data);
@ -794,9 +794,9 @@ void Picture::refill( struct picCodeNode *temp_fill_start, struct picCodeNode *t
else{//!picDrawEnabled_orig else{//!picDrawEnabled_orig
if(col_pic!=15){ if(col_pic!=15){
addCode(0xf0); addCode(0xf0);
addCode(col_pic); addCode(col_pic);
} }
} }
} }
if((refmode|2) && priDrawEnabled0){ if((refmode|2) && priDrawEnabled0){
@ -826,9 +826,9 @@ void Picture::refill( struct picCodeNode *temp_fill_start, struct picCodeNode *t
else{//!priDrawEnabled_orig else{//!priDrawEnabled_orig
if(col_pri!=4){ if(col_pri!=4){
addCode(0xf2); addCode(0xf2);
addCode(col_pri); addCode(col_pri);
} }
} }
} }
@ -859,10 +859,10 @@ void Picture::refill( struct picCodeNode *temp_fill_start, struct picCodeNode *t
if(col_pri_new==-1)draw_pri_new=true; if(col_pri_new==-1)draw_pri_new=true;
} }
break; break;
} }
temp = temp->next; temp = temp->next;
}while(temp && (col_pic_orig==-1 || col_pri_orig==-1)); }while(temp && (col_pic_orig==-1 || col_pri_orig==-1));
picPos = temp_fill_end; picPos = temp_fill_end;
if((refmode|1) && picDrawEnabled0){ if((refmode|1) && picDrawEnabled0){
@ -870,7 +870,7 @@ void Picture::refill( struct picCodeNode *temp_fill_start, struct picCodeNode *t
if(draw_pic_new){ if(draw_pic_new){
if(picDrawEnabled_orig){ if(picDrawEnabled_orig){
addCode(0xf0); addCode(0xf0);
addCode(col_pic_orig); addCode(col_pic_orig);
} }
else{ else{
if(col_pic!=0x15){ if(col_pic!=0x15){
@ -880,13 +880,13 @@ void Picture::refill( struct picCodeNode *temp_fill_start, struct picCodeNode *t
} }
} }
} }
if((refmode|2) && priDrawEnabled0){ if((refmode|2) && priDrawEnabled0){
if(col_pri != col_pri_orig){ if(col_pri != col_pri_orig){
if(draw_pri_new){ if(draw_pri_new){
if(priDrawEnabled_orig){ if(priDrawEnabled_orig){
addCode(0xf2); addCode(0xf2);
addCode(col_pri_orig); addCode(col_pri_orig);
} }
else{ else{
if(col_pri!=0x4){ if(col_pri!=0x4){
@ -896,7 +896,7 @@ void Picture::refill( struct picCodeNode *temp_fill_start, struct picCodeNode *t
} }
} }
} }
} }
picPos = picPos0; picPos = picPos0;
draw(); draw();
@ -908,7 +908,7 @@ void Picture::draw()
byte action; byte action;
struct picCodeNode *temp,*temp_fill_start,*temp_fill_end; struct picCodeNode *temp,*temp_fill_start,*temp_fill_end;
int refmode; int refmode;
bool finishedPic=false; bool finishedPic=false;
int pC, pN; int pC, pN;
memset(picture, 15, MAX_W*MAX_H); /* Visual screen default, white */ memset(picture, 15, MAX_W*MAX_H); /* Visual screen default, white */
@ -945,11 +945,11 @@ void Picture::draw()
case 0xF5: tool=T_STEP; xCorner(&temp); break; case 0xF5: tool=T_STEP; xCorner(&temp); break;
case 0xF6: tool=T_LINE; absoluteLine(&temp); break; case 0xF6: tool=T_LINE; absoluteLine(&temp); break;
case 0xF7: tool=T_PEN; relativeDraw(&temp); break; case 0xF7: tool=T_PEN; relativeDraw(&temp); break;
case 0xF8: tool=T_FILL; case 0xF8: tool=T_FILL;
temp_fill_start = temp->prior; temp_fill_start = temp->prior;
fill(&temp); fill(&temp);
temp_fill_end = temp; temp_fill_end = temp;
if(refill_pic || refill_pri){ if(refill_pic || refill_pri){
//find which FILL filled the selected area //find which FILL filled the selected area
refmode=0; refmode=0;
if(refill_pic && picGetPixel(refill_x,refill_y)!=15){ if(refill_pic && picGetPixel(refill_x,refill_y)!=15){
@ -980,20 +980,20 @@ void Picture::draw()
patCode = pC; patCode = pC;
patNum = pN; patNum = pN;
} }
} }
//************************************************** //**************************************************
void Picture::init() void Picture::init()
{ {
clear_tools(); clear_tools();
priDrawEnabled = picDrawEnabled = false; priDrawEnabled = picDrawEnabled = false;
addMode = INS_MODE; addMode = INS_MODE;
curp = &points0; curp = &points0;
points0.n=points1.n=0; points0.n=points1.n=0;
newp=&points; newp=&points;
add_pic=add_pri=false; add_pic=add_pri=false;
} }
//************************************************** //**************************************************
@ -1019,7 +1019,7 @@ void Picture::addCode(byte code) /* To the list */
dlstore(temp); dlstore(temp);
} }
//************************************************** //**************************************************
void Picture::replaceCode(byte code) void Picture::replaceCode(byte code)
{ {
struct picCodeNode *temp; struct picCodeNode *temp;
@ -1121,7 +1121,7 @@ void Picture::wipe_proc()
} }
//************************************************** //**************************************************
void Picture::tool_proc(int k) void Picture::tool_proc(int k)
{ {
tool=k; tool=k;
numClicks=0; numClicks=0;
stepClicks=0; stepClicks=0;
@ -1142,7 +1142,7 @@ void Picture::set_brush(int mode,int val)
brushTexture = val; brushTexture = val;
break; break;
} }
numClicks=0; numClicks=0;
} }
//************************************************** //**************************************************
@ -1188,13 +1188,13 @@ void Picture::choose_color(int button,int color)
//************************************************** //**************************************************
int Picture::move_action(int newX, int newY) int Picture::move_action(int newX, int newY)
{ {
int ret=0; //1 - draw "temporary" line on screen int ret=0; //1 - draw "temporary" line on screen
switch(tool){ switch(tool){
case T_LINE: case T_LINE:
if(numClicks==0)break; if(numClicks==0)break;
normline2(clickX>>1, clickY, newX>>1, newY); normline2(clickX>>1, clickY, newX>>1, newY);
ret=1; ret=1;
break; break;
case T_PEN: case T_PEN:
if(numClicks==0)break; if(numClicks==0)break;
@ -1202,7 +1202,7 @@ int Picture::move_action(int newX, int newY)
dY = ((newY) - (clickY)); dY = ((newY) - (clickY));
adjustDisp(&dX, &dY); adjustDisp(&dX, &dY);
normline2(clickX>>1, clickY,(clickX>>1)+dX, clickY+dY); normline2(clickX>>1, clickY,(clickX>>1)+dX, clickY+dY);
ret=1; ret=1;
break; break;
case T_STEP: case T_STEP:
if(stepClicks==0)break; if(stepClicks==0)break;
@ -1215,7 +1215,7 @@ int Picture::move_action(int newX, int newY)
normline2(clickX>>1, clickY, (clickX>>1)+dX, clickY+dY); normline2(clickX>>1, clickY, (clickX>>1)+dX, clickY+dY);
ret=1; ret=1;
break; break;
default: default:
dX = ((newX>>1) - (clickX>>1)); dX = ((newX>>1) - (clickX>>1));
dY = ((newY) - (clickY)); dY = ((newY) - (clickY));
@ -1255,7 +1255,7 @@ int Picture::button_action(int newX, int newY)
} }
switch(tool){ switch(tool){
case T_LINE: case T_LINE:
switch (numClicks++) { switch (numClicks++) {
case 0: break; case 0: break;
case 1: case 1:
@ -1271,7 +1271,7 @@ int Picture::button_action(int newX, int newY)
break; break;
} }
clickX = newX; clickX = newX;
clickY = newY; clickY = newY;
curp = &points0; curp = &points0;
points0.n=points1.n=0; points0.n=points1.n=0;
break; break;
@ -1300,7 +1300,7 @@ int Picture::button_action(int newX, int newY)
clickX = clickX + (dX<<1); clickX = clickX + (dX<<1);
clickY = clickY + dY; clickY = clickY + dY;
break; break;
} }
curp = &points0; curp = &points0;
points0.n=points1.n=0; points0.n=points1.n=0;
break; break;
@ -1357,10 +1357,10 @@ int Picture::button_action(int newX, int newY)
stepClicks++; stepClicks++;
curp = &points0; curp = &points0;
points0.n=points1.n=0; points0.n=points1.n=0;
break; break;
case T_FILL: case T_FILL:
if(!(okToFill(newX>>1, newY))){ if(!(okToFill(newX>>1, newY))){
status(0); status(0);
refill_x = newX>>1; refill_x = newX>>1;
refill_y = newY; refill_y = newY;
refill_pic = refill_pri = true; refill_pic = refill_pri = true;
@ -1389,7 +1389,7 @@ int Picture::button_action(int newX, int newY)
addCode(0xFA); addCode(0xFA);
} }
numClicks++; numClicks++;
patCode = brushSize; patCode = brushSize;
if (brushShape == SQUARE) patCode |= 0x10; if (brushShape == SQUARE) patCode |= 0x10;
if (brushTexture == SPRAY) patCode |= 0x20; if (brushTexture == SPRAY) patCode |= 0x20;
@ -1456,7 +1456,7 @@ void Picture::putpix2(int x,int y)
} }
x>>=1; x>>=1;
} }
else{ //save the pixels else{ //save the pixels
curp->p[curp->n].x=x; curp->p[curp->n].x=x;
curp->p[curp->n].y=y; curp->p[curp->n].y=y;
curp->p[curp->n].c=pptr[y*MAX_W+(x<<1)]; curp->p[curp->n].c=pptr[y*MAX_W+(x<<1)];
@ -1489,7 +1489,7 @@ void Picture::normline2(int x1, int y1, int x2, int y2)
for (x=x1; x!=x2; x+=addX) { for (x=x1; x!=x2; x+=addX) {
putpix2(round(x, addX), round(y, addY)); putpix2(round(x, addX), round(y, addY));
y+=addY; y+=addY;
} }
putpix2(x2,y2); putpix2(x2,y2);
} }
else { else {
@ -1520,12 +1520,12 @@ void Picture::viewData(TStringList *data)
data->add("ff"); data->add("ff");
return ; return ;
} }
temp = picStart; temp = picStart;
tmp[0]=0; tmp[0]=0;
for(temp=picStart;temp!=NULL;temp=temp->next){ for(temp=picStart;temp!=NULL;temp=temp->next){
c = temp->node; c = temp->node;
if(c>=0xf0 && tmp[0]){ if(c>=0xf0 && tmp[0]){
data->add(tmp); data->add(tmp);
sprintf(tmp,"%02x ",c); sprintf(tmp,"%02x ",c);
} }
@ -1539,7 +1539,7 @@ void Picture::viewData(TStringList *data)
data->add(tmp); data->add(tmp);
} }
data->add("ff"); data->add("ff");
} }
//*************************************************** //***************************************************