256 colorless compression BMP file format

xiaoxiao2021-03-06  39

The 256-color BMP file is divided into BMP file header, BMP information head, color table, and bitmap information matrix 4.

BMP file head structure;

Struct bitmapfileHeader_ {short type; // --------- File type, must be 'bm' int bfsize; // --------- File size, byte unit Short RE1, RE2; // ------ reserved bit int offs; // -------- bit map matrix offset is the offset, byte unit} with respect to the beginning of the file;

Next is BMP information head

Struct BitmapInfo_ {long size; // -------------- bitmap size, not necessarily effective. Long width, height; // ----- bitmap width and bitmap height, pixel unit Short Planes, Bitcount; // --- Plan number, must be 1; color depth, can be 1, 4 8, 16, indicating monochrome, 16 colors, 256 colors and 16-bit color. Long Comp, sizeImg; // ------- Compressed mode, 0 means no compression, 1 means RLE compression, 2 represents RLE compression of each pixel 4 bit. Long Xpels, Ypels; // -------- Horizontal resolution and vertical resolution, pixels / meter represents long buy, important; // ---- The color table in the color table actually used Not necessarily effective; the number of important colors is not necessarily effective}; the structure of the colorful entry is Struct Color_ {unsigned char blue; // -------- Blue brightness unsigned char Green; // - ----- Green brightness unsigned char red; // --------- Red brightness unsigned char RE; / / ---------- reservation}

RLL is compressed by RUN LENGTH ENCODED running

There are only 256 colorless compressed BMP files here.

Below is the BCB read the BMP file and displayed in the canvas.

#include #pragma hdrstop # include #include "unit1.h" #include "file1.h"

#pragma pack (1) struct bitmapfileheader_ {short type; int bfsize; short re1, re2; int offbits;

Struct BitmapInfo_ {Long Size; Long Width, Height; Short Planes, Bitcount; Long Comp, SizeImg; Long Xpels, Ypels; Long Used, Important;

// ------------ Correct the data of the BMP color table to BCB TColor. Void SwitchColor (long & c) {long blue = C & 0x000000FF; long green = C & 0x0000FF00; Long Red = C & 0x00FF0000; C = (Blue << 16) | Green | (Red >> 16);} void xxx () {file * f = fopen ("f: //fx3.bmp", "rb"); if (f == null) / * determine if the file is opened success * / {showMessage ("file open error"); return;} fseek (f, 0, 0); // move to the beginning

// ---------- Read BMP file head BitmapFileHeader_ * bmph = new bitmapfileHeader_ (); if (FREAD ((Char *) BMPH, SIZEOF (BitmapFileHeader_), 1, f) == null) {showMessage ("File Read Error"); RETURN;}

// ----------- Read BMP information head bitmapinfo_ * bmpi = new bitmapinfo_ (); if (FREAD ((char *) BMPI, SIZEOF (BitmapInfo_), 1, f) == null) { ShowMessage ("File Read Error2"); Return;}

// -------------- Read Color Table Long * C = New Long [BMPH-> Offbits-Sizeof (BitmapFileHeader_) - Sizeof (BitmapInfo_)]; FREAD ((char *) C, BMPH-> Offbits-Sizeof (BitmapfileHeader_) - Sizeof (BitmapInfo_), 1, F);

// ------------ Show graphics unsigned char * p = new unsigned char [4]; int i = 0, j = 0, k = 0, wc = 0; tcolor * tc; if (BMPI-> width% 4 == 0) // ----------- Because BMP images 4 byte align wc = bmpi-> width / 4; Else Wc = BMPI-> Width / 4 1;

转载请注明原文地址:https://www.9cbs.com/read-76688.html

New Post(0)