home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / bmag / bmpstuff.txt < prev    next >
Encoding:
Text File  |  1994-04-15  |  7.8 KB  |  199 lines

  1.  
  2. ─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
  3.   Msg#: 434                                          Date: 13 Apr 94  23:27:15
  4.   From: MIKE AUDLEMAN                                Read: Yes    Replied: No 
  5.     To: GREG FROMMER                                 Mark:                     
  6.   Subj: BMP'S AND THERE WORKINGS
  7. ──────────────────────────────────────────────────────────────────────────────
  8. Subspace Message:
  9. FR: Greg Frommer
  10. TO: Mike Audleman
  11. Coded Subject: BMP'S AND THERE WORKINGS
  12.  
  13.  GF> Yes I would very much like to persue this.. If you have any coad I
  14.  GF> would very  much like to see some.. thank you
  15.  GF> greg f
  16.  
  17. Here is a real hack job I did a while back to seperate a bunch of BMP
  18. images into seperate color and B&W directories.  It is called from a
  19. batch file using a "for %%x in (*.BMP)" type line.  The code reads the
  20. header of the BMP and picks out the B&W ones and the color ones and then
  21. moves them to their directories.  This file contains the TYPE statement
  22. for a BMP file header which is probably the thing that you should
  23. seperate from this file and save for your use.  I use this same header
  24. TYPE statement in all my programs dealing with BMPs, both QB45 and VB.
  25.  
  26. -------------->8--------------------------------------------------
  27. DEFINT A-Z
  28. TYPE BitMapFileHeader               '14 Bytes
  29.     bfType AS STRING * 2            '&H4D42 or "BM"
  30.     bfSize AS LONG                  'Size of the file
  31.     bfReserved1 AS INTEGER          'Not Used |Think these are used in
  32.     bfReserved2 AS INTEGER          '"   "    |OS\2 BMPs but not sure
  33.     bfOffBits AS LONG               'addr of start of actual data
  34.     biSize AS LONG                  '40 (The Size of the BI header)
  35.     biWidth AS LONG                 'Image Width
  36.     biHeight AS LONG                'Image Height
  37.     biPlanes AS INTEGER             '# of planes, DIBs have only 1
  38.     biBitCount AS INTEGER           'bits per pixel (8 for 256 colors)
  39.     biCompression AS LONG           'Compression type :BI_RGB = none
  40.     biSizeImage AS LONG             'Image size (0 if Compression=BI_RGB
  41.     biXPelsPerMeter AS LONG         '0
  42.     biYPelsPerMeter AS LONG         '0
  43.     biClrUsed AS LONG               'Number of colors actually used (Leave at
  44. 256)
  45.     biClrImportant AS LONG          'Number of important colors (0 =  all)
  46.     biColorTable AS STRING * 64     'Color Table. Size changes
  47. END TYPE
  48.  
  49. DIM SHARED Text AS STRING * 256, Byte  AS STRING * 1, BMPHeader AS
  50. BitMapFileHeader
  51.  
  52. 'Process the command line into file and path
  53. File$ = LTRIM$(COMMAND$)
  54. File$ = RTRIM$(File$)
  55. Spac% = INSTR(File$, " ")
  56. IF Spac% = 0 THEN
  57.         File1$ = File$
  58. ELSE
  59.         File1$ = MID$(File$, Spac% + 1)
  60.         File$ = LEFT$(File$, Spac% - 1)
  61. END IF
  62. Backs = INSTR(File1$, "\")
  63. Colon = INSTR(File1$, ":")
  64. Path$ = ".\"
  65. IF Backs > 0 THEN
  66.         FOR X = LEN(File1$) TO Backs STEP -1
  67.                 IF MID$(File1$, X, 1) = "\" THEN Where = X: EXIT FOR
  68.         NEXT X
  69.         Path$ = LEFT$(File1$, Where)
  70.         File1$ = Path$ + MID$(File1$, Where + 1, 8)
  71. ELSEIF Colon > 0 THEN
  72.         Path$ = LEFT$(File1$, Colon)
  73.         File1$ = Path$ + MID$(File1$, Colon + 1, 8)
  74. ELSE
  75.         File1$ = LEFT$(File1$, 8)
  76. END IF
  77.  
  78. IF INSTR(File1$, ".") > 0 THEN File1$ = LEFT$(File1$, INSTR(File1$, ".") - 1)
  79.  
  80. 'Ok, here we go with the main loop:
  81. OPEN File$ FOR BINARY AS 1 LEN = 8192 'Len 8192 makes it faster, not needed
  82. IF LOF(1) = 0 THEN CLOSE : PRINT "File Length=0": KILL File$: END
  83. GET 1, , BMPHeader 'Load the header of the file
  84.  
  85. 'check for valid BMP file
  86. IF BMPHeader.bfType <> "BM" OR BMPHeader.bfReserved1 <> 0 OR
  87. BMPHeader.bfReserved2 <> 0 THEN
  88.         CLOSE
  89.         PRINT File$; " is not a recognized BMP type"
  90.         END
  91. END IF
  92. CLOSE
  93.  
  94. 'BitCount will be 1 for B&W
  95. SELECT CASE BMPHeader.biBitCount
  96. CASE 1
  97.         SHELL "Move " + File$ + " " + Path$ + "b&w"
  98. CASE ELSE
  99.         SHELL "Move " + File$ + " " + Path$ + "color"
  100. END SELECT
  101.  
  102. END
  103.  
  104. FUNCTION GetByte%
  105. 'This simple function gets a single byte from file and converts to integer
  106.         GET 1, , Byte$
  107.         GetByte% = ASC(Byte$)
  108. END FUNCTION
  109.  
  110. -------------->8--------------------------------------------------
  111. This section may be a bit long winded but it is vital you understand the
  112. entries in the file and image headers.  The file header is distinguished
  113. by the variables starting with "bf" and the image header variables start
  114. with "bi".  Print this out and use a hex file viewer and peek at some
  115. BMPs and compare values you find.  That is how I learned what is in
  116. them and what they do.
  117.  
  118. ---File Header area (Disk File oriented data)
  119. This is always "BM" for BMP and DIB files
  120.     bfType AS STRING * 2            '&H4D42 or "BM"
  121.  
  122. This should be set to the total file size including this header
  123.     bfSize AS LONG                  'Size of the file
  124.  
  125. Set to 0 in every BMP I have.
  126.     bfReserved1 AS INTEGER          'Not Used |Think these are used in
  127.     bfReserved2 AS INTEGER          '"   "    |OS\2 BMPs but not sure
  128.  
  129. This is the start address relitive to the start of the file where the
  130. actual image data starts
  131.     bfOffBits AS LONG               'addr of start of actual data
  132.  
  133. ----Image Header area  (Image oriented data)
  134. This is the size of the image header, always 40
  135.     biSize AS LONG                  '40 (The Size of the BI header)
  136.  
  137. This is the size of the image (ex, 1024 & 768)
  138.     biWidth AS LONG                 'Image Width
  139.     biHeight AS LONG                'Image Height
  140.  
  141. Number of bit planes.  BMP and DIB only have 1
  142.     biPlanes AS INTEGER             '# of planes, DIBs have only 1
  143.  
  144. This is the number of bits needed to represent each pixel.  This
  145. directly equates to the number of possible colors.
  146.         1 B&W (2 color)
  147.         4 for 16 colors
  148.         8 for 256 colors
  149.         24 for 24 bit true color
  150.     biBitCount AS INTEGER           'bits per pixel (8 for 256 colors)
  151.  
  152. This marks the file compression type.
  153.   0 for No compression (the most common)
  154.   1 for RLE8 (Run Length Encoding, 8 Bit)
  155.   2 for RLE4 (""    ""     ""      4 bit)
  156.     biCompression AS LONG           'Compression type :BI_RGB = none
  157.  
  158. This is the data size.  If Compression is 0 then this can be 0 too
  159.     biSizeImage AS LONG             'Image size (0 if Compression=BI_RGB
  160.  
  161. These specify the the pixels per meter that the BMP/DIB was designed for
  162.  or the resolution if you will.
  163.     biXPelsPerMeter AS LONG         '0
  164.     biYPelsPerMeter AS LONG         '0
  165.  
  166. This is the number of colors that are actually used in the color table.
  167. For example, you have a 256 color BMP that actually has only 12 colors
  168. then this value would be 12.  This is mainly used by windows for palate
  169. managemet along with the next entry. Set to 0 to specify all colors.
  170.     biClrUsed AS LONG               'Number of colors actually used (Leave at
  171. 256)
  172.  
  173. This is the number of colors that are important in the color table.
  174. For example, you have a 256 color BMP that actually has only 12 colors
  175. and 5 of them were important to the image and the remaining were shading
  176. or whatever, then this value would be 5.  This is mainly used by windows
  177. for palate managemet along with the previous entry. Set to 0 to specify
  178. all colors.
  179.     biClrImportant AS LONG          'Number of important colors (0 =  all)
  180.  
  181. This is the color table or palate for the image.  The size will vary
  182. with the number of colors specified by the biBitCount entry.
  183. Number of Colors:      Size of Color table:
  184.         2                       8
  185.         16                      64
  186.         256                     1024
  187.         2^24                    0 (Not used for 24 bit true color)
  188.     biColorTable AS STRING * 64     'Color Table. Size changes
  189.  
  190. Later ... Mike Audleman
  191.  
  192. ... Well I've confirmed it - cats can't swim.
  193. ___ Blue Wave/QWK v2.12
  194.  
  195.  
  196. -!-
  197.  ! Origin: Exec-PC BBS > World's Largest BBS < (1:154/280)
  198.  
  199.