Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Retrouver la palette d'un Device Independant Bitmap

1 réponse
Avatar
Michel
Rebonjour,
ma question est contenue dans le titre.

J'ai regard=E9 l'aide msdn, mais elle utilise un DDB ce qui lui permet
d'utiliser la fonction GetDIBits.

http://msdn.microsoft.com/en-us/library/dd145119%28v=3DVS.85%29.aspx :
"The following example code defines a function that initializes the
remaining structures, retrieves the array of palette indices, opens
the file, copies the data, and closes the file.

void CreateBMPFile(HWND hwnd, LPTSTR pszFile, PBITMAPINFO pbi,
HBITMAP hBMP, HDC hDC)
{
[...]
// Retrieve the color table (RGBQUAD array) and the bits
// (array of palette indices) from the DIB.
if (!GetDIBits(hDC, hBMP, 0, (WORD) pbih->biHeight, lpBits, pbi,
DIB_RGB_COLORS))
{
errhandler("GetDIBits", hwnd);
}
[...]
}"

Merci d'avance

1 réponse

Avatar
Jean-Christophe
On Jul 14, 7:00 pm, Michel

ma question est contenue dans le titre.



Dans l'ordre, un fichier au format DIB contient:
- un header BITMAPFILEHEADER
- un header BITMAPINFO
- la séquence des données pixel

La palette est incluse dans BITMAPINFO et se trouve à l'offset:
offset = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER)

Je te donne ci-dessous les détails des headers.
j'espère avoir répondu à ta question.


-------------------------------------------------
typedef struct tagBITMAPFILEHEADER { // bmfh
WORD bfType;
DWORD bfSize;
WORD bfReserved1;
WORD bfReserved2;
DWORD bfOffBits;
} BITMAPFILEHEADER;

-------------------------------------------------
typedef struct tagBITMAPINFO { // bmi
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO;

-------------------------------------------------
typedef struct tagBITMAPINFOHEADER{ // bmih
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER;


-------------------------------------------------
BITMAPINFO

The BITMAPINFO structure defines the dimensions and color information
for a Win32 device-independent bitmap (DIB).

typedef struct tagBITMAPINFO { // bmi
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO;
Members
bmiHeader
Specifies a bitmap information header structure that contains
information about the dimensions of color format. The bitmap
information header structure is version related.
Windows NT 3.51 and earlier: Use the BITMAPINFOHEADER structure.

Windows NT 4.0 and Windows 95: Use the BITMAPV4HEADER structure.

Windows 98, Windows NT 5.0 and later: Use BITMAPV5HEADER structure.

bmiColors
The bmiColors member contains one of the following:
An array of RGBQUAD. The elements of the array make up the color
table.
An array of 16-bit unsigned integers that specifies indexes into the
currently realized logical palette. This use of bmiColors is allowed
for functions that use DIBs. When bmiColors elements contain indexes
to a realized logical palette, they must also call the following
bitmap functions: CreateDIBitmap, CreateDIBPatternBrush, and
CreateDIBSection. The iUsage parameter of CreateDIBSection must be set
to DIB_PAL_COLORS.
Platform differences are listed in the following table. Operating
System Description
Windows NT 3.51 and earlier The number of entries in the array depends
on the values of the biBitCount and biClrUsed members of the
BITMAPINFOHEADER structure.
Windows NT 4.0 and Windows 95 The number of entries in the array
depends on the values of the bV4BitCount and bV4ClrUsed members of the
BITMAPV4HEADER structure.
Windows NT 5.0 and Windows 98 The number of entries in the array
depends on the values of the bV5BitCount and bV5ClrUsed members of the
BITMAPV5HEADER structure.

The colors in the bmiColors table appear in order of importance. For
more information, see the following Remarks section.

Remarks
A device-independent bitmap consists of two distinct parts: a
BITMAPINFO structure describing the dimensions and colors of the
bitmap, and an array of bytes defining the pixels of the bitmap. The
bits in the array are packed together, but each scan line must be
padded with zeroes to end on a LONG data-type boundary. If the height
of the bitmap is positive, the bitmap is a bottom-up DIB and its
origin is the lower-left corner. If the height is negative, the bitmap
is a top-down DIB and its origin is the upper left corner.

A bitmap is packed when the bitmap array immediately follows the
BITMAPINFO header. Packed bitmaps are referenced by a single pointer.
For packed bitmaps, the ClrUsed member must be set to an even number
when using the DIB_PAL_COLORS mode so the DIB bitmap array starts on a
DWORD boundary.

Note The bmiColors member should not contain palette indexes if the
bitmap is to be stored in a file or transferred to another
application.

Unless the application has exclusive use and control of the bitmap,
the bitmap color table should contain explicit RGB values.

QuickInfo
Windows NT: Requires version 3.1 or later.
Windows: Requires Windows 95 or later.
Windows CE: Requires version 1.0 or later.
Header: Declared in wingdi.h.
-------------------------------------------------