home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / grfxrexx.zip / LitBMP.Cmd < prev    next >
OS/2 REXX Batch file  |  1995-09-23  |  3KB  |  83 lines

  1. /*********************************************************************
  2.  LitBMP - Raphaël Vanney, 09/95
  3.  
  4.  The purpose of this REXX program is to get information from a BMP file.
  5.  There's of course no waranty of any kind associated to it. Use freely.
  6. **********************************************************************/
  7.  
  8. Debug=1
  9. Parse Arg NomF
  10. Say GetBMPDesc(NomF)
  11. Drop NomF BMP.
  12. Exit
  13.  
  14. GetBMPDesc:
  15. /* Get description for a BMP file ; if first character of returned
  16.    string is a "(", an error occured and the returned string is a
  17.    description of the error rather than of the file.
  18.    Normally returns "width x height (color info)".
  19.    Extra info is available in BMP. if no error occured :
  20.    (Note that the extra info is unaccurate for non-Windows BMP:s ; this
  21.    is because I don't have a documentation for OS/2's BMP).
  22.  
  23.      BMP.fsize           file size
  24.      BMP.offbits         ?
  25.      BMP.isize           ?
  26.      BMP.width           image width
  27.      BMP.height          image height
  28.      BMP.planes          number of planes
  29.      BMP.bits            bits per pixel (per plane)
  30.      BMP.comp            compression type
  31.      BMP.imgsize         ?
  32. */
  33.  
  34. Parse Arg FName
  35. Drop BMP.
  36.  
  37. If FName="" Then Return "(must supply a filename)"
  38.  
  39. /* read file header */
  40.  
  41. Hdr=C2D(Reverse(CharIn(FName, 1, 2)))             /* type */
  42. BMP.fsize=C2D(Reverse(CharIn(FName, , 4)))        /* which size ? */
  43. BMP.rsv=C2D(Reverse(CharIn(FName, , 4)))          /* should be 0 */
  44.  
  45. If (Hdr<>19778) | (BMP.rsv<>0) Then
  46. Do
  47.      Drop Hdr BMP.
  48.      rc=CharOut(FName)
  49.      Return "(not a BMP file)"
  50. End
  51.  
  52. BMP.offbits=C2D(Reverse(CharIn(FName, , 4)))
  53. BMP.isize=C2D(Reverse(CharIn(FName, , 4)))
  54. BMP.width=C2D(Reverse(CharIn(FName, , 4)))        /* bitmap width */
  55. BMP.height=C2D(Reverse(CharIn(FName, , 4)))       /* bitmap height */
  56. BMP.planes=C2D(Reverse(CharIn(FName, , 2)))       /* # of planes */
  57. BMP.bits=C2D(Reverse(CharIn(FName, , 2)))         /* bits per pel */
  58. BMP.comp=C2D(Reverse(CharIn(FName, , 4)))         /* comp */
  59. BMP.imgsize=C2D(Reverse(CharIn(FName, , 4)))      /* img size in bytes */
  60.  
  61. Bits=BMP.planes*BMP.bits
  62. If Bits>=15 Then BMP.colors=Bits||"-bit true color"
  63.             Else BMP.colors=2**Bits||" colors"
  64. Drop Bits
  65.  
  66. If Debug Then
  67. Do
  68.      Say "Type           "Hdr
  69.      Say "File size      "BMP.fsize
  70.      Say "bfOffBits      "BMP.offbits
  71.      Say "biSize         "BMP.isize
  72.      Say "Image size     "BMP.width"x"BMP.height
  73.      Say "# of planes    "BMP.planes
  74.      Say "Bits/pixel     "BMP.bits
  75.      Say "Compression    "BMP.comp
  76.      Say "Size in bytes  "BMP.imgsize
  77. End
  78.  
  79. rc=CharOut(FName)
  80.  
  81. Return BMP.width||" x "||BMP.height||" ("||BMP.colors||")"
  82.  
  83.