bmp2ico

 Взялся за старую задачу, просидел пару дней. Получил результат, но полученный файл немного отличался от значка, преобразованного оригинальной программой. Плюнул, переписал код - файлы совпадают.

;bmp2ico Version 1.01 - December 16, 2004
;Copyright 2004 Michael Kohn - http://www.mikekohn.net/

out.l=0
in.l=1
CreateFile(out,"ii.ico")
  num_icons=1;argc-2;
  WriteWord(out,0)
  WriteWord(out,1)
  WriteWord(out,num_icons)
  
  c.l=0
  While c<num_icons
    WriteLong(out,0)
    WriteLong(out,0)
    WriteLong(out,0)
    WriteLong(out,0)
    c+1
  Wend
  
  c=0
  While c<num_icons
    ReadFile(in,"sq34.bmp")
    marker=Loc(out)
    FileSeek(in,18)
    x.l=ReadLong(in)
    y.l=ReadLong(in)
    ReadWord(in)
    bits.w=ReadWord(in)
; printf("bits=%d\n",bits);
    If bits>=8
      bits=0;
    EndIf
    If x<>y Or (x<>16 And x<>32 And x<>64)
      MessageRequester("bmp2ico","BMP's must be 16x16, 32x32, or 64x64")
      End
    EndIf
;     /* write Icon Directory */
    FileSeek(out,6+c*16)
    WriteAsciiCharacter(out,x)
    WriteAsciiCharacter(out,y)
    If bits=0
    WriteAsciiCharacter(out,0)
      Else
        WriteAsciiCharacter(out,1<<bits)
      EndIf
    WriteAsciiCharacter(out,0)
    WriteWord(out,0)
    WriteWord(out,0)
    WriteLong(out,0)
    WriteLong(out,marker)
    FileSeek(out,marker)
    
; printf("Wrote Icon Directory\n");
;     /* write BMP */
    FileSeek(in,14)
    t.l=ReadLong(in)
    WriteLong(out,t);/* biSize */
    t.l=ReadLong(in)
   WriteLong(out,t);/* biWidth */
    t.l=ReadLong(in)
    WriteLong(out,t*2);/* biHeight */
    t.l=ReadWord(in)
    WriteWord(out,t);/* biPlanes */
    bits=ReadWord(in)
    WriteWord(out,bits);/* biPlanes */
    t.l=ReadLong(in)
    WriteLong(out,t);/* biCompression */
    
    If t;<>0
      MessageRequester("bmp2ico","BMP's cannot be compressed")
      End
    EndIf
; printf("Wrote most of BMP header\n");
    WriteLong(out,0)
    WriteLong(out,0)
    WriteLong(out,0)
    WriteLong(out,0)
    WriteLong(out,0)
    ReadLong(in)
    ReadLong(in)
    ReadLong(in)
    ReadLong(in)
    ReadLong(in)
    If bits<16
; printf("bits is less than 16...  palette is %d\n",t);
      r=0
      While r<t
        WriteLong(out,ReadLong(in));
        r+1
      Wend
; printf("padding\n");
      k=1<<bits;
      r=t
      While r<k
        WriteLong(out,0)
      r+1
    Wend
  EndIf
; printf("wrote palette\n");
    While Not Eof(in)
      WriteAsciiCharacter(out,ReadAsciiCharacter(in))
    Wend
; printf("Adding padding\n");
    k=(x/4)+(x%4);
    While k%4<>0
      k+1
Wend
    t=y*k;
    
    r=0
    While r<t
      WriteAsciiCharacter(out,0)
      r+1
    Wend
    r=Loc(out)-marker
    marker=Loc(out)
; printf("writing size to: %d   size=%d\n",6+(c*16)+8,r);
    FileSeek(out,6+c*16+8)
    WriteLong(out,r)
    FileSeek(out,marker)
    CloseFile(in)
    c+1
  Wend
  CloseFile(out)
; IDE Options = PureBasic 5.30 (Windows - x86)
; EnableXP
; Watchlist = t

файлы тут.


Комментарии