Ticket #38: GrafX2_deluxe_paint_ST_iff.patch
File GrafX2_deluxe_paint_ST_iff.patch, 13.0 KB (added by , 7 years ago) |
---|
-
fileformats.c
231 231 word X_org; // Inutile 232 232 word Y_org; // Inutile 233 233 byte BitPlanes; 234 byte Mask; 235 byte Compression; 236 byte Pad1; // Inutile237 word Transp_col; 234 byte Mask; // 0=none, 1=mask, 2=transp color, 3=Lasso 235 byte Compression; // 0=none, 1=packbits, 2=vertical RLE 236 byte Pad1; // Inutile 237 word Transp_col; // transparent color for masking mode 2 238 238 byte X_aspect; // Inutile 239 239 byte Y_aspect; // Inutile 240 240 word X_screen; … … 438 438 } 439 439 440 440 // ------------------------- Attendre une section ------------------------- 441 byte IFF_Wait_for( byte* expected_section)441 byte IFF_Wait_for(const char * expected_section) 442 442 { 443 443 // Valeur retournée: 1=Section trouvée, 0=Section non trouvée (erreur) 444 444 byte section_read[4]; … … 584 584 short y_pos; 585 585 short counter; 586 586 short line_size; // Taille d'une ligne en octets 587 short plane_line_size; // Size of line in bytes for 1 plane 587 588 short real_line_size; // Taille d'une ligne en pixels 588 589 byte color; 589 590 long file_size; 590 591 dword dummy; 591 592 byte is_anim=0; 592 593 int iff_format; 594 int plane; 593 595 594 596 Get_full_filename(filename, context->File_name, context->File_directory); 595 597 … … 617 619 else 618 620 iff_format = FORMAT_PBM; 619 621 620 if (!IFF_Wait_for( (byte *)"BMHD"))622 if (!IFF_Wait_for("BMHD")) 621 623 File_error=1; 622 624 Read_dword_be(IFF_file,&dummy); 623 625 … … 637 639 && (Read_word_be(IFF_file,&header.Y_screen)) 638 640 && header.Width && header.Height) 639 641 { 640 if ( (header.BitPlanes) && (IFF_Wait_for( (byte *)"CMAP")) )642 if ( (header.BitPlanes) && (IFF_Wait_for("CMAP")) ) 641 643 { 642 644 Read_dword_be(IFF_file,&nb_colors); 643 645 nb_colors/=3; … … 662 664 663 665 if ( (!File_error) && (nb_colors>=2) && (nb_colors<=256) ) 664 666 { 667 byte real_bit_planes = header.BitPlanes; 668 665 669 if (header.Mask==1) 666 670 header.BitPlanes++; 667 671 … … 769 773 if (!memcmp(format,"ILBM",4)) // "ILBM": InterLeaved BitMap 770 774 { 771 775 // Calcul de la taille d'une ligne ILBM (pour les images ayant des dimensions exotiques) 772 if (context->Width & 15) 776 real_line_size = (context->Width+15) & ~15; 777 plane_line_size = real_line_size >> 3; // 8bits per byte 778 line_size = plane_line_size * header.BitPlanes; 779 780 switch(header.Compression) 773 781 { 774 real_line_size=( (context->Width+16) >> 4 ) << 4; 775 line_size=( (context->Width+16) >> 4 )*(header.BitPlanes<<1); 776 } 777 else 778 { 779 real_line_size=context->Width; 780 line_size=(context->Width>>3)*header.BitPlanes; 781 } 782 case 0: // non compressé 783 IFF_buffer=(byte *)malloc(line_size); 784 for (y_pos=0; ((y_pos<context->Height) && (!File_error)); y_pos++) 785 { 786 if (Read_bytes(IFF_file,IFF_buffer,line_size)) 787 Draw_IFF_line(context, y_pos,real_line_size, header.BitPlanes); 788 else 789 File_error=21; 790 } 791 free(IFF_buffer); 792 IFF_buffer = NULL; 793 break; 794 case 1: // compressé packbits (Amiga) 795 /*Init_lecture();*/ 782 796 783 if (!header.Compression) 784 { // non compressé 785 IFF_buffer=(byte *)malloc(line_size); 786 for (y_pos=0; ((y_pos<context->Height) && (!File_error)); y_pos++) 787 { 788 if (Read_bytes(IFF_file,IFF_buffer,line_size)) 789 Draw_IFF_line(context, y_pos,real_line_size, header.BitPlanes); 790 else 791 File_error=21; 792 } 793 free(IFF_buffer); 794 IFF_buffer = NULL; 795 } 796 else 797 { // compressé 798 /*Init_lecture();*/ 797 IFF_buffer=(byte *)malloc(line_size); 799 798 800 IFF_buffer=(byte *)malloc(line_size); 799 for (y_pos=0; ((y_pos<context->Height) && (!File_error)); y_pos++) 800 { 801 for (x_pos=0; ((x_pos<line_size) && (!File_error)); ) 802 { 803 if(Read_byte(IFF_file, &temp_byte)!=1) 804 { 805 File_error=22; 806 break; 807 } 808 // Si temp_byte > 127 alors il faut répéter 256-'temp_byte' fois la couleur de l'octet suivant 809 // Si temp_byte <= 127 alors il faut afficher directement les 'temp_byte' octets suivants 810 if (temp_byte>127) 811 { 812 if(Read_byte(IFF_file, &color)!=1) 813 { 814 File_error=23; 815 break; 816 } 817 b256=(short)(256-temp_byte); 818 for (counter=0; counter<=b256; counter++) 819 if (x_pos<line_size) 820 IFF_buffer[x_pos++]=color; 821 else 822 File_error=24; 823 } 824 else 825 for (counter=0; counter<=(short)(temp_byte); counter++) 826 if (x_pos>=line_size || Read_byte(IFF_file, &(IFF_buffer[x_pos++]))!=1) 827 File_error=25; 828 } 829 if (!File_error) 830 Draw_IFF_line(context, y_pos,real_line_size,header.BitPlanes); 831 } 801 832 802 for (y_pos=0; ((y_pos<context->Height) && (!File_error)); y_pos++) 803 { 804 for (x_pos=0; ((x_pos<line_size) && (!File_error)); ) 833 free(IFF_buffer); 834 IFF_buffer = NULL; 835 /*Close_lecture();*/ 836 break; 837 case 2: // compressé vertical RLE (Atari ST) 838 IFF_buffer=(byte *)malloc(line_size*context->Height); 839 plane_line_size = real_line_size >> 3; 840 for (plane = 0; plane < header.BitPlanes && !File_error; plane++) 805 841 { 806 if(Read_byte(IFF_file, &temp_byte)!=1) 842 word cmd_count; 843 word cmd; 844 signed char * commands; 845 word count; 846 847 y_pos = 0; x_pos = 0; 848 if (!IFF_Wait_for("VDAT")) 807 849 { 808 File_error =22;850 File_error = 30; 809 851 break; 810 852 } 811 // Si temp_byte > 127 alors il faut répéter 256-'temp_byte' fois la couleur de l'octet suivant 812 // Si temp_byte <= 127 alors il faut afficher directement les 'temp_byte' octets suivants 813 if (temp_byte>127) 853 Read_dword_be(IFF_file,§ion_size); 854 Read_word_be(IFF_file,&cmd_count); 855 cmd_count -= 2; 856 commands = (signed char *)malloc(cmd_count); 857 if (!Read_bytes(IFF_file,commands,cmd_count)) 814 858 { 815 if(Read_byte(IFF_file, &color)!=1) 816 { 817 File_error=23; 818 break; 859 File_error = 31; 860 break; 861 } 862 for (cmd = 0; cmd < cmd_count && x_pos < plane_line_size; cmd++) 863 { 864 if (commands[cmd] <= 0) 865 { // cmd=0 : load count from data, COPY 866 // cmd < 0 : count = -cmd, COPY 867 if (commands[cmd] == 0) 868 Read_word_be(IFF_file,&count); 869 else 870 count = -commands[cmd]; 871 while (count-- > 0 && x_pos < plane_line_size) 872 { 873 Read_bytes(IFF_file,IFF_buffer+x_pos+y_pos*line_size+plane*plane_line_size,2); 874 if(++y_pos >= context->Height) 875 { 876 y_pos = 0; 877 x_pos += 2; 878 } 879 } 819 880 } 820 b256=(short)(256-temp_byte); 821 for (counter=0; counter<=b256; counter++) 822 if (x_pos<line_size) 823 IFF_buffer[x_pos++]=color; 881 else if (commands[cmd] >= 1) 882 { // cmd=1 : load count from data, RLE 883 // cmd >1 : count = cmd, RLE 884 byte data[2]; 885 if (commands[cmd] == 1) 886 Read_word_be(IFF_file,&count); 824 887 else 825 File_error=24; 888 count = (word)commands[cmd]; 889 Read_bytes(IFF_file,data,2); 890 while (count-- > 0 && x_pos < plane_line_size) 891 { 892 memcpy(IFF_buffer+x_pos+y_pos*line_size+plane*plane_line_size,data,2); 893 if (++y_pos >= context->Height) 894 { 895 y_pos = 0; 896 x_pos += 2; 897 } 898 } 899 } 826 900 } 827 else 828 for (counter=0; counter<=(short)(temp_byte); counter++) 829 if (x_pos>=line_size || Read_byte(IFF_file, &(IFF_buffer[x_pos++]))!=1) 830 File_error=25; 901 free(commands); 831 902 } 832 903 if (!File_error) 833 Draw_IFF_line(context, y_pos,real_line_size,header.BitPlanes); 834 } 835 836 free(IFF_buffer); 837 IFF_buffer = NULL; 838 /*Close_lecture();*/ 904 { 905 byte * save_IFF_buffer = IFF_buffer; 906 for (y_pos = 0; y_pos < context->Height; y_pos++) 907 { 908 Draw_IFF_line(context,y_pos,real_line_size,real_bit_planes); 909 IFF_buffer += line_size; 910 } 911 IFF_buffer = save_IFF_buffer; 912 } 913 free(IFF_buffer); 914 IFF_buffer = NULL; 915 break; 916 default: // compression non reconnue 917 File_error = 32; 839 918 } 840 919 } 841 920 else // "PBM ": Planar(?) BitMap … … 909 988 910 989 // ILBM, hopefully 911 990 Read_bytes(IFF_file,format,4); 912 if (!IFF_Wait_for( (byte *)"DLTA"))991 if (!IFF_Wait_for("DLTA")) 913 992 { 914 993 File_error=1; 915 994 break; … … 1142 1221 if (context->Format == FORMAT_LBM) 1143 1222 { 1144 1223 short line_size; // Size of line in bytes 1224 short plane_line_size; // Size of line in bytes for 1 plane 1145 1225 short real_line_size; // Size of line in pixels 1146 1226 1147 1227 // Calcul de la taille d'une ligne ILBM (pour les images ayant des dimensions exotiques) 1148 if (context->Width & 15) 1149 { 1150 real_line_size=( (context->Width+16) >> 4 ) << 4; 1151 line_size=( (context->Width+16) >> 4 )*(header.BitPlanes<<1); 1152 } 1153 else 1154 { 1155 real_line_size=context->Width; 1156 line_size=(context->Width>>3)*header.BitPlanes; 1157 } 1228 real_line_size = (context->Width+15) & ~15; 1229 plane_line_size = real_line_size >> 3; // 8bits per byte 1230 line_size = plane_line_size * header.BitPlanes; 1158 1231 IFF_buffer=(byte *)malloc(line_size); 1159 1232 1160 1233 // Start encoding