From 2e46820b83951c2b41930cbb4459c553b96ca6a8 Mon Sep 17 00:00:00 2001 From: Yves Rizoud Date: Sat, 5 Sep 2009 19:49:18 +0000 Subject: [PATCH] Fixed tabulations to 2spaces (the most common in this file). Tiny bit of error-check on saving. Implemented preview scaling to display c64 widepixel pictures properly. Not done yet: Auto-set wide or wide2 pixels after loading a picture with wide pixels. git-svn-id: svn://pulkomandy.tk/GrafX2/trunk@1016 416bcca6-2ee7-4201-b75f-2eb2f807beb1 --- loadsave.c | 857 ++++++++++++++++++++++++++++------------------------- 1 file changed, 447 insertions(+), 410 deletions(-) diff --git a/loadsave.c b/loadsave.c index 06ad33fe..c09294d6 100644 --- a/loadsave.c +++ b/loadsave.c @@ -121,7 +121,7 @@ void Load_PNG(void); void Save_PNG(void); #endif -void Init_preview(short width,short height,long size,int format); +void Init_preview(short width,short height,long size,int format,enum PIXEL_RATIO ratio); T_Format File_formats[NB_KNOWN_FORMATS] = { {"pkm", Test_PKM, Load_PKM, Save_PKM, 1, 1}, @@ -177,10 +177,35 @@ byte HBPm1; // header.BitPlanes-1 void Pixel_load_in_preview(word x_pos,word y_pos,byte color) { if (((x_pos % Preview_factor_X)==0) && ((y_pos % Preview_factor_Y)==0)) - if ((x_pos 127 alors il faut répéter 256-'temp_byte' fois la couleur de l'octet suivant // Si temp_byte <= 127 alors il faut afficher directement les 'temp_byte' octets suivants if (temp_byte>127) { - if(Read_byte(LBM_file, &color)!=1) - { - File_error=2; - break; - } + if(Read_byte(LBM_file, &color)!=1) + { + File_error=2; + break; + } b256=(short)(256-temp_byte); for (counter=0; counter<=b256; counter++) if (x_pos=line_size || Read_byte(LBM_file, &(LBM_buffer[x_pos++]))!=1) - File_error=2; + File_error=2; } if (!File_error) Draw_ILBM_line(y_pos,real_line_size); @@ -1967,17 +2001,17 @@ void Load_LBM(void) for (x_pos=0; ((x_pos127) { if(Read_byte(LBM_file, &color)!=1) - { - File_error=2; - break; - } + { + File_error=2; + break; + } b256=256-temp_byte; for (counter=0; counter<=b256; counter++) Pixel_load_function(x_pos++,y_pos,color); @@ -1987,10 +2021,10 @@ void Load_LBM(void) { byte byte_read=0; if(Read_byte(LBM_file, &byte_read)!=1) - { - File_error=2; - break; - } + { + File_error=2; + break; + } Pixel_load_function(x_pos++,y_pos,byte_read); } } @@ -2407,7 +2441,7 @@ void Load_BMP(void) if (!File_error) { - Init_preview(header.Width,header.Height,file_size,FORMAT_BMP); + Init_preview(header.Width,header.Height,file_size,FORMAT_BMP,PIXEL_SIMPLE); if (File_error==0) { if (Read_bytes(file,local_palette,nb_colors<<2)) @@ -2470,7 +2504,7 @@ void Load_BMP(void) /*Init_lecture();*/ if(Read_byte(file, &a)!=1 || Read_byte(file, &b)!=1) - File_error=2; + File_error=2; while (!File_error) { if (a) // Encoded mode @@ -2486,8 +2520,8 @@ void Load_BMP(void) case 1 : // End of bitmap break; case 2 : // Delta - if(Read_byte(file, &a)!=1 || Read_byte(file, &b)!=1) - File_error=2; + if(Read_byte(file, &a)!=1 || Read_byte(file, &b)!=1) + File_error=2; x_pos+=a; y_pos-=b; break; @@ -2495,7 +2529,7 @@ void Load_BMP(void) while (b) { if(Read_byte(file, &a)!=1) - File_error=2; + File_error=2; //Read_one_byte(file, &c); Pixel_load_function(x_pos++,y_pos,a); //if (--c) @@ -2510,9 +2544,9 @@ void Load_BMP(void) if (a==0 && b==1) break; if(Read_byte(file, &a) !=1 || Read_byte(file, &b)!=1) - { - File_error=2; - } + { + File_error=2; + } } /*Close_lecture();*/ break; @@ -2523,7 +2557,7 @@ void Load_BMP(void) /*Init_lecture();*/ if(Read_byte(file, &a)!=1 || Read_byte(file, &b) != 1) - File_error =2; + File_error =2; while ( (!File_error) && ((a)||(b!=1)) ) { if (a) // Encoded mode (A fois les 1/2 pixels de B) @@ -2546,7 +2580,7 @@ void Load_BMP(void) break; case 2 : // Delta if(Read_byte(file, &a)!=1 || Read_byte(file, &b)!=1) - File_error=2; + File_error=2; x_pos+=a; y_pos-=b; break; @@ -2892,10 +2926,10 @@ void Test_GIF(void) if (GIF_remainder_byte==0) // Lire l'octet nous donnant la taille du bloc de Raster Data suivant if(Read_byte(GIF_file, &GIF_remainder_byte)!=1) - File_error=2; + File_error=2; - if(Read_byte(GIF_file,&GIF_last_byte)!=1) - File_error = 2; + if(Read_byte(GIF_file,&GIF_last_byte)!=1) + File_error = 2; GIF_remainder_byte--; GIF_remainder_bits=8; } @@ -3131,7 +3165,7 @@ void Load_GIF(void) Main_image_width=IDB.Image_width; Main_image_height=IDB.Image_height; - Init_preview(IDB.Image_width,IDB.Image_height,file_size,FORMAT_GIF); + Init_preview(IDB.Image_width,IDB.Image_height,file_size,FORMAT_GIF,PIXEL_SIMPLE); // Palette locale dispo = (IDB.Indicator and $80) // Image entrelacée = (IDB.Indicator and $40) @@ -3803,7 +3837,7 @@ void Load_PCX(void) if (PCX_header.Plane!=3) { - Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_PCX); + Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_PCX,PIXEL_SIMPLE); if (File_error==0) { // On prépare la palette à accueillir les valeurs du fichier PCX @@ -4300,7 +4334,7 @@ void Load_CEL(void) Main_image_height=header1.Height; Original_screen_X=Main_image_width; Original_screen_Y=Main_image_height; - Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_CEL); + Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_CEL,PIXEL_SIMPLE); if (File_error==0) { // Chargement de l'image @@ -4330,7 +4364,7 @@ void Load_CEL(void) Main_image_height=header2.Height+header2.Y_offset; Original_screen_X=Main_image_width; Original_screen_Y=Main_image_height; - Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_CEL); + Init_preview(Main_image_width,Main_image_height,file_size,FORMAT_CEL,PIXEL_SIMPLE); if (File_error==0) { // Chargement de l'image @@ -4823,7 +4857,7 @@ void Load_SCx(void) if ((Read_bytes(file,&SCx_header,sizeof(T_SCx_Header)))) { - Init_preview(SCx_header.Width,SCx_header.Height,file_size,FORMAT_SCx); + Init_preview(SCx_header.Width,SCx_header.Height,file_size,FORMAT_SCx,PIXEL_SIMPLE); if (File_error==0) { if (!SCx_header.Planes) @@ -5121,7 +5155,7 @@ void Load_PI1(void) if (Read_bytes(file,buffer,32034)) { // Initialisation de la preview - Init_preview(320,200,File_length_file(file),FORMAT_PI1); + Init_preview(320,200,File_length_file(file),FORMAT_PI1,PIXEL_SIMPLE); if (File_error==0) { // Initialisation de la palette @@ -5455,7 +5489,7 @@ void Load_PC1(void) if (Read_bytes(file,buffercomp,size)) { // Initialisation de la preview - Init_preview(320,200,File_length_file(file),FORMAT_PC1); + Init_preview(320,200,File_length_file(file),FORMAT_PC1,PIXEL_SIMPLE); if (File_error==0) { // Initialisation de la palette @@ -5690,12 +5724,12 @@ void Test_NEO(void) size=File_length_file(file); if ((size==32128)) { - // Flag word : toujours 0 - if (Read_word_le(file,&resolution)) - { - if (resolution == 0) - File_error = 0; - } + // Flag word : toujours 0 + if (Read_word_le(file,&resolution)) + { + if (resolution == 0) + File_error = 0; + } // Lecture et vérification de la résolution if (Read_word_le(file,&resolution)) @@ -5732,13 +5766,13 @@ void Load_NEO(void) if (Read_bytes(file,buffer,32128)) { // Initialisation de la preview - Init_preview(320,200,File_length_file(file),FORMAT_NEO); + Init_preview(320,200,File_length_file(file),FORMAT_NEO,PIXEL_SIMPLE); if (File_error==0) { // Initialisation de la palette if (Config.Clear_palette) memset(Main_palette,0,sizeof(T_Palette)); - // on saute la résolution et le flag, chacun 2 bits + // on saute la résolution et le flag, chacun 2 bits PI1_decode_palette(buffer+4,(byte *)Main_palette); Set_palette(Main_palette); Remap_fileselector(); @@ -5843,379 +5877,380 @@ void Save_NEO(void) ///////////////////////////////////////////////////////////////////////////// void Test_C64(void) { - FILE* file; - char filename[MAX_PATH_CHARACTERS]; - long file_size; + FILE* file; + char filename[MAX_PATH_CHARACTERS]; + long file_size; - Get_full_filename(filename,0); + Get_full_filename(filename,0); - file = fopen(filename,"rb"); + file = fopen(filename,"rb"); - if (file) - { - file_size = File_length_file(file); - switch (file_size) - { - case 8000: // raw bitmap - case 8002: // raw bitmap with loadaddr - case 9000: // bitmap + screen - case 9002: // bitmap + screen + loadaddr - case 10001: // multicolor - case 10003: // multicolor + loadaddr - File_error = 0; - break; - default: // then we don't know for now. - File_error = 1; - - } - fclose (file); - } - else - { - File_error = 1; - } + if (file) + { + file_size = File_length_file(file); + switch (file_size) + { + case 8000: // raw bitmap + case 8002: // raw bitmap with loadaddr + case 9000: // bitmap + screen + case 9002: // bitmap + screen + loadaddr + case 10001: // multicolor + case 10003: // multicolor + loadaddr + File_error = 0; + break; + default: // then we don't know for now. + File_error = 1; + } + fclose (file); + } + else + { + File_error = 1; + } } void Load_C64_hires(byte *bitmap, byte *colors) -{ - int cx,cy,x,y,c[4],pixel,color; - - for(cy=0; cy<25; cy++) +{ + int cx,cy,x,y,c[4],pixel,color; + + for(cy=0; cy<25; cy++) + { + for(cx=0; cx<40; cx++) { - for(cx=0; cx<40; cx++) - { - c[1]=colors[cy*40+cx]&15; - c[0]=colors[cy*40+cx]>>4; - for(y=0; y<8; y++) - { - pixel=bitmap[cy*320+cx*8+y]; - for(x=0; x<8; x++) - { - color=c[pixel&(1<<(7-x))?1:0]; - Pixel_load_function(cx*8+x,cy*8+y,color); - } - } - } + c[1]=colors[cy*40+cx]&15; + c[0]=colors[cy*40+cx]>>4; + for(y=0; y<8; y++) + { + pixel=bitmap[cy*320+cx*8+y]; + for(x=0; x<8; x++) + { + color=c[pixel&(1<<(7-x))?1:0]; + Pixel_load_function(cx*8+x,cy*8+y,color); + } + } } + } } void Load_C64_multi(byte *bitmap, byte *colors, byte *nybble, byte background) { - int cx,cy,x,y,c[4],pixel,color; - c[0]=background; - for(cy=0; cy<25; cy++) + int cx,cy,x,y,c[4],pixel,color; + c[0]=background; + for(cy=0; cy<25; cy++) + { + for(cx=0; cx<40; cx++) { - for(cx=0; cx<40; cx++) - { - c[1]=colors[cy*40+cx]>>4; - c[2]=colors[cy*40+cx]&15; - c[3]=nybble[cy*40+cx]; - - for(y=0; y<8; y++) - { - pixel=bitmap[cy*320+cx*8+y]; - for(x=0; x<4; x++) - { - - color=c[(pixel&3)]; - pixel>>=2; - Pixel_load_function(cx*4+(3-x),cy*8+y,color); - } - } - } + c[1]=colors[cy*40+cx]>>4; + c[2]=colors[cy*40+cx]&15; + c[3]=nybble[cy*40+cx]; + + for(y=0; y<8; y++) + { + pixel=bitmap[cy*320+cx*8+y]; + for(x=0; x<4; x++) + { + color=c[(pixel&3)]; + pixel>>=2; + Pixel_load_function(cx*4+(3-x),cy*8+y,color); + } + } } + } } void Load_C64(void) { - FILE* file; - char filename[MAX_PATH_CHARACTERS]; - long file_size; - int newPixel_ratio; - byte background; - - // Palette from http://www.pepto.de/projects/colorvic/ - byte pal[48]={ - 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, - 0x68, 0x37, 0x2B, - 0x70, 0xA4, 0xB2, - 0x6F, 0x3D, 0x86, - 0x58, 0x8D, 0x43, - 0x35, 0x28, 0x79, - 0xB8, 0xC7, 0x6F, - 0x6F, 0x4F, 0x25, - 0x43, 0x39, 0x00, - 0x9A, 0x67, 0x59, - 0x44, 0x44, 0x44, - 0x6C, 0x6C, 0x6C, - 0x9A, 0xD2, 0x84, - 0x6C, 0x5E, 0xB5, - 0x95, 0x95, 0x95}; + FILE* file; + char filename[MAX_PATH_CHARACTERS]; + long file_size; + byte background; + + // Palette from http://www.pepto.de/projects/colorvic/ + byte pal[48]={ + 0x00, 0x00, 0x00, + 0xFF, 0xFF, 0xFF, + 0x68, 0x37, 0x2B, + 0x70, 0xA4, 0xB2, + 0x6F, 0x3D, 0x86, + 0x58, 0x8D, 0x43, + 0x35, 0x28, 0x79, + 0xB8, 0xC7, 0x6F, + 0x6F, 0x4F, 0x25, + 0x43, 0x39, 0x00, + 0x9A, 0x67, 0x59, + 0x44, 0x44, 0x44, + 0x6C, 0x6C, 0x6C, + 0x9A, 0xD2, 0x84, + 0x6C, 0x5E, 0xB5, + 0x95, 0x95, 0x95}; - byte bitmap[8000],colors[1000],nybble[1000]; - word width=320, height=200; + byte bitmap[8000],colors[1000],nybble[1000]; + word width=320, height=200; + + Get_full_filename(filename,0); + file = fopen(filename,"rb"); + + if(file) + { - Get_full_filename(filename,0); - file = fopen(filename,"rb"); - - if(file) + memcpy(Main_palette,pal,48); // this set the software palette for grafx2 + Set_palette(Main_palette); // this set the hardware palette for SDL + Remap_fileselector(); // Always call it if you change the palette + + file_size = File_length_file(file); + + if(file_size>9002) { - - memcpy(Main_palette,pal,48); // this set the software palette for grafx2 - Set_palette(Main_palette); // this set the hardware palette for SDL - Remap_fileselector(); // Always call it if you change the palette - - file_size = File_length_file(file); - - if(file_size>9002)width=160; - - Init_preview(width, height, file_size, FORMAT_C64); // Do this as soon as you can - - Main_image_width = width ; - Main_image_height = height; - - Read_bytes(file,bitmap,8000); - if(file_size>8002)Read_bytes(file,colors,1000); - - if(width==160) - { - Read_bytes(file,nybble,1000); - Read_byte(file,&background); - Load_C64_multi(bitmap,colors,nybble,background); - newPixel_ratio = PIXEL_WIDE; - } - else - { - Load_C64_hires(bitmap,colors); - newPixel_ratio = PIXEL_SIMPLE; - } - - //Pixel_ratio = newPixel_ratio; - - File_error = 0; - fclose(file); + width=160; + Ratio_of_loaded_image = PIXEL_WIDE; } else + { + Ratio_of_loaded_image = PIXEL_SIMPLE; + } + + Init_preview(width, height, file_size, FORMAT_C64, Ratio_of_loaded_image); // Do this as soon as you can + + Main_image_width = width ; + Main_image_height = height; + + Read_bytes(file,bitmap,8000); + if(file_size>8002) + Read_bytes(file,colors,1000); + + if(width==160) + { + Read_bytes(file,nybble,1000); + Read_byte(file,&background); + Load_C64_multi(bitmap,colors,nybble,background); + } + else + { + Load_C64_hires(bitmap,colors); + } + + File_error = 0; + fclose(file); + } + else File_error = 1; } int Save_C64_hires(char *filename) { - int cx,cy,x,y,c1,c2,i,pixel,bits,pos=0; - word numcolors; - dword cusage[256]; - byte colors[1000],bitmap[8000]; - FILE *file; - - for(x=0;x<1000;x++)colors[x]=1; // init colormem to black/white - - for(cy=0; cy<25; cy++) // Character line, 25 lines - { - for(cx=0; cx<40; cx++) // Character column, 40 columns - { - for(i=0;i<256;i++) cusage[i]=0; - - numcolors=Count_used_colors_area(cusage,cx*8,cy*8,8,8); - if (numcolors>2) - { - Warning_message("More than 2 colors in 8x8 pixels"); - // TODO here we should hilite the offending block - printf("\nerror at %dx%d (%d colors)\n",cx*8,cy*8,numcolors); - return 1; - } - for(i=0;i<16;i++) - { - if(cusage[i]) - { - c2=i; - break; - } - } - c1=c2; - for(i=c2+1;i<16;i++) - { - if(cusage[i]) - { - c1=i; - } - } - colors[cx+cy*40]=(c2<<4)|c1; + int cx,cy,x,y,c1,c2,i,pixel,bits,pos=0; + word numcolors; + dword cusage[256]; + byte colors[1000],bitmap[8000]; + FILE *file; + + for(x=0;x<1000;x++)colors[x]=1; // init colormem to black/white + + for(cy=0; cy<25; cy++) // Character line, 25 lines + { + for(cx=0; cx<40; cx++) // Character column, 40 columns + { + for(i=0;i<256;i++) cusage[i]=0; + + numcolors=Count_used_colors_area(cusage,cx*8,cy*8,8,8); + if (numcolors>2) + { + Warning_message("More than 2 colors in 8x8 pixels"); + // TODO here we should hilite the offending block + printf("\nerror at %dx%d (%d colors)\n",cx*8,cy*8,numcolors); + return 1; + } + for(i=0;i<16;i++) + { + if(cusage[i]) + { + c2=i; + break; + } + } + c1=c2; + for(i=c2+1;i<16;i++) + { + if(cusage[i]) + { + c1=i; + } + } + colors[cx+cy*40]=(c2<<4)|c1; - for(y=0; y<8; y++) - { - bits=0; - for(x=0; x<8; x++) - { - pixel=Read_pixel_function(x+cx*8,y+cy*8); - if(pixel>15) - { - Warning_message("Color above 15 used"); - // TODO hilite offending block here too? - // or make it smarter with color allocation? - // However, the palette is fixed to the 16 first colors - return 1; - } - bits=bits<<1; - if (pixel==c1) bits|=1; - } - bitmap[pos++]=bits; - //Write_byte(file,bits&255); - } - } - } - - file = fopen(filename,"wb"); - - if(!file) - { - Warning_message("File open failed"); - File_error = 1; - return 1; - } - - Write_bytes(file,bitmap,8000); - Write_bytes(file,colors,1000); - - fclose(file); - return 0; + for(y=0; y<8; y++) + { + bits=0; + for(x=0; x<8; x++) + { + pixel=Read_pixel_function(x+cx*8,y+cy*8); + if(pixel>15) + { + Warning_message("Color above 15 used"); + // TODO hilite offending block here too? + // or make it smarter with color allocation? + // However, the palette is fixed to the 16 first colors + return 1; + } + bits=bits<<1; + if (pixel==c1) bits|=1; + } + bitmap[pos++]=bits; + //Write_byte(file,bits&255); + } + } + } + + file = fopen(filename,"wb"); + + if(!file) + { + Warning_message("File open failed"); + File_error = 1; + return 1; + } + + if (!Write_bytes(file,bitmap,8000) || + !Write_bytes(file,colors,1000)) + File_error = 1; + + fclose(file); + return 0; } int Save_C64_multi(char *filename) { /* -BITS COLOR INFORMATION COMES FROM -00 Background color #0 (screen color) -01 Upper 4 bits of screen memory -10 Lower 4 bits of screen memory -11 Color nybble (nybble = 1/2 byte = 4 bits) +BITS COLOR INFORMATION COMES FROM +00 Background color #0 (screen color) +01 Upper 4 bits of screen memory +10 Lower 4 bits of screen memory +11 Color nybble (nybble = 1/2 byte = 4 bits) */ - int cx,cy,x,y,c[4]={0,0,0,0},color,lut[16],bits,pixel,pos=0; - byte bitmap[8000],screen[1000],nybble[1000]; - word numcolors,count; - dword cusage[256]; - byte i,background=0; - FILE *file; - - numcolors=Count_used_colors(cusage); - - count=0; - for(x=0;x<16;x++) - { - //printf("color %d, pixels %d\n",x,cusage[x]); - if(cusage[x]>count) - { - count=cusage[x]; - background=x; - - } - } - - for(cy=0; cy<25; cy++) - { - //printf("\ny:%2d ",cy); - for(cx=0; cx<40; cx++) - { - numcolors=Count_used_colors_area(cusage,cx*4,cy*8,4,8); - if(numcolors>4) - { - Warning_message("More than 4 colors in 4x8"); - // TODO hilite offending block - return 1; - } - color=1; - c[0]=background; - for(i=0; i<16; i++) - { - lut[i]=0; - if(cusage[i]) - { - if(i!=background) - { - lut[i]=color; - c[color]=i; - color++; - } - else - { - lut[i]=0; - } - } - } - // add to screen and nybble - screen[cx+cy*40]=c[1]<<4|c[2]; - nybble[cx+cy*40]=c[3]; - //printf("%x%x%x ",c[1],c[2],c[3]); - for(y=0;y<8;y++) - { - bits=0; - for(x=0;x<4;x++) - { - pixel=Read_pixel_function(cx*4+x,cy*8+y); - if(pixel>15) - { - Warning_message("Color above 15 used"); - // TODO hilite as in hires, you should stay to - // the fixed 16 color palette - return 1; - } - bits=bits<<2; - bits|=lut[pixel]; + int cx,cy,x,y,c[4]={0,0,0,0},color,lut[16],bits,pixel,pos=0; + byte bitmap[8000],screen[1000],nybble[1000]; + word numcolors,count; + dword cusage[256]; + byte i,background=0; + FILE *file; + + numcolors=Count_used_colors(cusage); + + count=0; + for(x=0;x<16;x++) + { + //printf("color %d, pixels %d\n",x,cusage[x]); + if(cusage[x]>count) + { + count=cusage[x]; + background=x; + } + } + + for(cy=0; cy<25; cy++) + { + //printf("\ny:%2d ",cy); + for(cx=0; cx<40; cx++) + { + numcolors=Count_used_colors_area(cusage,cx*4,cy*8,4,8); + if(numcolors>4) + { + Warning_message("More than 4 colors in 4x8"); + // TODO hilite offending block + return 1; + } + color=1; + c[0]=background; + for(i=0; i<16; i++) + { + lut[i]=0; + if(cusage[i]) + { + if(i!=background) + { + lut[i]=color; + c[color]=i; + color++; + } + else + { + lut[i]=0; + } + } + } + // add to screen and nybble + screen[cx+cy*40]=c[1]<<4|c[2]; + nybble[cx+cy*40]=c[3]; + //printf("%x%x%x ",c[1],c[2],c[3]); + for(y=0;y<8;y++) + { + bits=0; + for(x=0;x<4;x++) + { + pixel=Read_pixel_function(cx*4+x,cy*8+y); + if(pixel>15) + { + Warning_message("Color above 15 used"); + // TODO hilite as in hires, you should stay to + // the fixed 16 color palette + return 1; + } + bits=bits<<2; + bits|=lut[pixel]; - } - //Write_byte(file,bits&255); - bitmap[pos++]=bits; - } - } - } - - file = fopen(filename,"wb"); - - if(!file) - { - Warning_message("File open failed"); - File_error = 1; - return 1; - } - Write_bytes(file,bitmap,8000); - Write_bytes(file,screen,1000); - Write_bytes(file,nybble,1000); - Write_byte(file,background); - - fclose(file); - //printf("\nbg:%d\n",background); - return 0; + } + //Write_byte(file,bits&255); + bitmap[pos++]=bits; + } + } + } + + file = fopen(filename,"wb"); + + if(!file) + { + Warning_message("File open failed"); + File_error = 1; + return 1; + } + if (!Write_bytes(file,bitmap,8000) || + !Write_bytes(file,screen,1000) || + !Write_bytes(file,nybble,1000) || + !Write_byte(file,background)) + File_error = 1; + + fclose(file); + //printf("\nbg:%d\n",background); + return 0; } void Save_C64(void) { - char filename[MAX_PATH_CHARACTERS]; - dword numcolors,cusage[256]; - numcolors=Count_used_colors(cusage); + char filename[MAX_PATH_CHARACTERS]; + dword numcolors, cusage[256]; + numcolors=Count_used_colors(cusage); - Get_full_filename(filename,0); + Get_full_filename(filename,0); - if (numcolors>16) - { - Warning_message("Error: Max 16 colors"); - File_error = 1; - return; - } - if (((Main_image_width!=320) && (Main_image_width!=160)) || Main_image_height!=200) - { - Warning_message("must be 320x200 or 160x200"); - File_error = 1; - return; - } - - if (Main_image_width==320) - File_error = Save_C64_hires(filename); - else - File_error = Save_C64_multi(filename); - - //fclose(file); - + if (numcolors>16) + { + Warning_message("Error: Max 16 colors"); + File_error = 1; + return; + } + if (((Main_image_width!=320) && (Main_image_width!=160)) || Main_image_height!=200) + { + Warning_message("must be 320x200 or 160x200"); + File_error = 1; + return; + } + + if (Main_image_width==320) + File_error = Save_C64_hires(filename); + else + File_error = Save_C64_multi(filename); + } ///////////////////////////////////////////////////////////////////////////// @@ -6351,7 +6386,7 @@ void Load_PNG(void) if (color_type == PNG_COLOR_TYPE_RGB || color_type == PNG_COLOR_TYPE_RGB_ALPHA) Init_preview_24b(info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG); else - Init_preview(info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG); + Init_preview(info_ptr->width,info_ptr->height,File_length_file(file),FORMAT_PNG,Ratio_of_loaded_image); if (File_error==0) { @@ -6567,9 +6602,11 @@ void Save_PNG(void) switch(Pixel_ratio) { case PIXEL_WIDE: + case PIXEL_WIDE2: png_set_pHYs(png_ptr, info_ptr, 3000, 6000, PNG_RESOLUTION_METER); break; case PIXEL_TALL: + case PIXEL_TALL2: png_set_pHYs(png_ptr, info_ptr, 6000, 3000, PNG_RESOLUTION_METER); break; default: