Friday, December 07, 2012

TCanvas

剛剛在 C++ Builder 的 Developer's Guide 看到一段話, 解了一個很久以來的疑問!

"Canvases are available only at runtime, so you do all your work with canvases by writing code"

這也解釋了為什麼這個 Image 物件中的小物件沒有出現在 Object Inspector 的 Properties 之中, 而 Picture 卻有出現在 Image 中的 Properties 之中。


Thursday, May 03, 2012

BITMAPINFOHEADER structure

BITMAPINFOHEADER structure 結構資料型態主要是用來描述 DIB (Device Independent Bitmap) 物件的相關屬性。
The BITMAPINFOHEADER structure contains information about the dimensions and color format of a DIB.

Windows 95, Windows NT 4.0: Applications can use the BITMAPV4HEADER structure for added functionality.

Windows 98/Me, Windows 2000/XP: Applications can use the BITMAPV5HEADER structure for added functionality. However, these are used only in the CreateDIBitmap function.

typedef struct tagBITMAPINFOHEADER{
DWORD biSize;
LONG biWidth;
LONG biHeight;
WORD biPlanes;
WORD biBitCount;
DWORD biCompression;
DWORD biSizeImage;
LONG biXPelsPerMeter;
LONG biYPelsPerMeter;
DWORD biClrUsed;
DWORD biClrImportant;
} BITMAPINFOHEADER, *PBITMAPINFOHEADER;

Members

biSize

Specifies the number of bytes required by the structure.

biWidth

Specifies the width of the bitmap, in pixels.

Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, the biWidth member specifies the width of the decompressed JPEG or PNG image file, respectively.

biHeight

Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap is a bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is a top-down DIB and its origin is the upper-left corner.

If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or BI_BITFIELDS. Top-down DIBs cannot be compressed.

Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, the biHeight member specifies the height of the decompressed JPEG or PNG image file, respectively.

biPlanes

Specifies the number of planes for the target device. This value must be set to 1.

biBitCount

Specifies the number of bits-per-pixel. The biBitCount member of the BITMAPINFOHEADER structure determines the number of bits that define each pixel and the maximum number of colors in the bitmap. This member must be one of the following values.

0 Windows 98/Me, Windows 2000/XP: The number of bits-per-pixel is specified or is implied by the JPEG or PNG format.

1 The bitmap is monochrome, and the bmiColors member of BITMAPINFO contains two entries. Each bit in the bitmap array represents a pixel. If the bit is clear, the pixel is displayed with the color of the first entry in the bmiColors table; if the bit is set, the pixel has the color of the second entry in the table.

4 The bitmap has a maximum of 16 colors, and the bmiColors member of BITMAPINFO contains up to 16 entries. Each pixel in the bitmap is represented by a 4-bit index into the color table. For example, if the first byte in the bitmap is 0x1F, the byte represents two pixels. The first pixel contains the color in the second table entry, and the second pixel contains the color in the sixteenth table entry.

8 The bitmap has a maximum of 256 colors, and the bmiColors member of BITMAPINFO contains up to 256 entries. In this case, each byte in the array represents a single pixel.

16 The bitmap has a maximum of 2^16 colors. If the biCompression member of the BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. Each WORD in the bitmap array represents a single pixel. The relative intensities of red, green, and blue are represented with five bits for each color component. The value for blue is in the least significant five bits, followed by five bits each for green and red. The most significant bit is not used. The bmiColors color table is used for optimizing colors used on palette-based devices, and must contain the number of entries specified by the biClrUsed member of the BITMAPINFOHEADER.
If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the bmiColors member contains three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. Each WORD in the bitmap array represents a single pixel.

Windows NT/Windows 2000/XP: When the biCompression member is BI_BITFIELDS, bits set in each DWORD mask must be contiguous and should not overlap the bits of another mask. All the bits in the pixel do not have to be used.

Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system supports only the following 16bpp color masks: A 5-5-5 16-bit image, where the blue mask is 0x001F, the green mask is 0x03E0, and the red mask is 0x7C00; and a 5-6-5 16-bit image, where the blue mask is 0x001F, the green mask is 0x07E0, and the red mask is 0xF800.

24 The bitmap has a maximum of 2^24 colors, and the bmiColors member of BITMAPINFO is NULL. Each 3-byte triplet in the bitmap array represents the relative intensities of blue, green, and red, respectively, for a pixel. The bmiColors color table is used for optimizing colors used on palette-based devices, and must contain the number of entries specified by the biClrUsed member of the BITMAPINFOHEADER.

32 The bitmap has a maximum of 2^32 colors. If the biCompression member of the BITMAPINFOHEADER is BI_RGB, the bmiColors member of BITMAPINFO is NULL. Each DWORD in the bitmap array represents the relative intensities of blue, green, and red, respectively, for a pixel. The high byte in each DWORD is not used. The bmiColors color table is used for optimizing colors used on palette-based devices, and must contain the number of entries specified by the biClrUsed member of the BITMAPINFOHEADER.
If the biCompression member of the BITMAPINFOHEADER is BI_BITFIELDS, the bmiColors member contains three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. Each DWORD in the bitmap array represents a single pixel.

Windows NT/ 2000: When the biCompression member is BI_BITFIELDS, bits set in each DWORD mask must be contiguous and should not overlap the bits of another mask. All the bits in the pixel do not need to be used.

Windows 95/98/Me: When the biCompression member is BI_BITFIELDS, the system supports only the following 32-bpp color mask: The blue mask is 0x000000FF, the green mask is 0x0000FF00, and the red mask is 0x00FF0000.

biCompression
Specifies the type of compression for a compressed bottom-up bitmap (top-down DIBs cannot be compressed). This member can be one of the following values.

BI_RGB An uncompressed format.
BI_RLE8 A run-length encoded (RLE) format for bitmaps with 8 bpp. The compression format is a 2-byte format consisting of a count byte followed by a byte containing a color index. For more information, see Bitmap Compression.
BI_RLE4 An RLE format for bitmaps with 4 bpp. The compression format is a 2-byte format consisting of a count byte followed by two word-length color indexes. For more information, see Bitmap Compression.
BI_BITFIELDS Specifies that the bitmap is not compressed and that the color table consists of three DWORD color masks that specify the red, green, and blue components, respectively, of each pixel. This is valid when used with 16- and 32-bpp bitmaps.
BI_JPEG Windows 98/Me, Windows 2000/XP: Indicates that the image is a JPEG image.
BI_PNG Windows 98/Me, Windows 2000/XP: Indicates that the image is a PNG image.

biSizeImage

Specifies the size, in bytes, of the image. This may be set to zero for BI_RGB bitmaps.
Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, biSizeImage indicates the size of the JPEG or PNG image buffer, respectively.

biXPelsPerMeter

Specifies the horizontal resolution, in pixels-per-meter, of the target device for the bitmap. An application can use this value to select a bitmap from a resource group that best matches the characteristics of the current device.

biYPelsPerMeter

Specifies the vertical resolution, in pixels-per-meter, of the target device for the bitmap.

biClrUsed

Specifies the number of color indexes in the color table that are actually used by the bitmap. If this value is zero, the bitmap uses the maximum number of colors corresponding to the value of the biBitCount member for the compression mode specified by biCompression.

If biClrUsed is nonzero and the biBitCount member is less than 16, the biClrUsed member specifies the actual number of colors the graphics engine or device driver accesses. If biBitCount is 16 or greater, the biClrUsed member specifies the size of the color table used to optimize performance of the system color palettes. If biBitCount equals 16 or 32, the optimal color palette starts immediately following the three DWORD masks.

When the bitmap array immediately follows the BITMAPINFO structure, it is a packed bitmap. Packed bitmaps are referenced by a single pointer. Packed bitmaps require that the biClrUsed member must be either zero or the actual size of the color table.

biClrImportant

Specifies the number of color indexes that are required for displaying the bitmap. If this value is zero, all colors are required.
Remarks
The BITMAPINFO structure combines the BITMAPINFOHEADER structure and a color table to provide a complete definition of the dimensions and colors of a DIB. For more information about DIBs, see Device-Independent Bitmaps and BITMAPINFO.

An application should use the information stored in the biSize member to locate the color table in a BITMAPINFO structure, as follows:

pColor = ((LPSTR)pBitmapInfo + (WORD)(pBitmapInfo->bmiHeader.biSize));

Windows 98/Me, Windows 2000/XP: The BITMAPINFOHEADER structure is extended to allow a JPEG or PNG image to be passed as the source image to StretchDIBits.

Wednesday, May 02, 2012

BITMAPINFO structure

結構型資料型態中含有結構型資料型態的組成成員(member)是高階程式設計中非常常見的。BITMAPINFO structure 的組成成員只有 2 個, 其中 bmiHeader 就是同樣屬於結構型資料型態 BITMAPINFOHEADER structure 的成員, 主要是用來描述 DIB (Device Independent Bitmap) 物件的相關屬性。
The BITMAPINFO structure defines the dimensions and color information for a DIB.

typedef struct tagBITMAPINFO {
BITMAPINFOHEADER bmiHeader;
RGBQUAD bmiColors[1];
} BITMAPINFO, *PBITMAPINFO;

Members

bmiHeader

Specifies a BITMAPINFOHEADER structure that contains information about the dimensions of color format.

bmiColors

The bmiColors member contains one of the following:
(1) An array of RGBQUAD. The elements of the array that make up the color table.
(2) 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

CreateDIBSection

The iUsage parameter of CreateDIBSection must be set to DIB_PAL_COLORS.

The number of entries in the array depends on the values of the biBitCount and biClrUsed members of the BITMAPINFOHEADER structure.

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

Remarks

A DIB 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 biClrUsed member must be set to an even number when using the DIB_PAL_COLORS mode so that 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.

capGetVideoFormat macro

透過 VFW 所提供的 capGetVideoFormat 函式, 可以取得視訊畫面資料的寬、高、一個像素(pixel)由幾個位元組成及視訊畫面資料是否經過壓縮... 等等。如果想要修改視訊擷取視窗中的畫面內容, 這些資料就變成相當重要。
The capGetVideoFormat macro retrieves a copy of the video format in use. You can use this macro or explicitly call the WM_CAP_GET_VIDEOFORMAT message.

DWORD capGetVideoFormat(
hwnd,
psVideoFormat,
wSize
);

Parameters

hwnd

Handle to a capture window.

psVideoFormat

Pointer to a BITMAPINFO structure. You can also specify NULL to retrieve the number of bytes needed by BITMAPINFO.

wSize

Size, in bytes, of the structure referenced by s.

Return Values

Returns the size, in bytes, of the video format or zero if the capture window is not connected to a capture driver. For video formats that require a palette, the current palette is also returned.

Remarks

Because compressed video formats vary in size requirements applications must first retrieve the size, then allocate memory, and finally request the video format data.

Tuesday, April 24, 2012

capCaptureStop macro

結束連續視訊串流擷取。
The capCaptureStop macro stops the capture operation. You can use this macro or explicitly send the WM_CAP_STOP message.

In step frame capture, the image data that was collected before this message was sent is retained in the capture file. An equivalent duration of audio data is also retained in the capture file if audio capture was enabled.

BOOL capCaptureStop(
hwnd
);
Parameters

hwnd

Handle to a capture window.

Return Values

Returns TRUE if successful or FALSE otherwise.

Remarks

The capture operation must yield to use this message. Use the capCaptureAbort macro to abandon the current capture operation.

capCaptureAbort macro

中止錄影動作。
The capCaptureAbort macro stops the capture operation. You can use this macro or explictly send the WM_CAP_ABORT message.

BOOL capCaptureAbort(
hwnd
);

Parameters

hwnd

Handle to a capture window.

Return Values

Returns TRUE if successful or FALSE otherwise.

Remarks

The capture operation must yield to use this macro.

In the case of step capture, the image data collected up to the point of the capCaptureAbort macro will be retained in the capture file, but audio will not be captured.

Use the capCaptureStop macro to halt step capture at the current position, and then capture audio.

Monday, April 23, 2012

capFileAlloc macro

預先從硬碟配置固定大小的空間存放錄影檔案。
The capFileAlloc macro creates (preallocates) a capture file of a specified size. You can use this macro or explicitly send the WM_CAP_FILE_ALLOCATE message.

BOOL capFileAlloc(
hwnd,
dwSize
);

Parameters

hwnd

Handle to a capture window.

dwSize

Size, in bytes, to create the capture file.

Return Values

Returns TRUE if successful or FALSE otherwise.

If an error occurs and an error callback function is set using the capSetCallbackOnError macro, the error callback function is called.

Remarks

You can improve streaming capture performance significantly by preallocating a capture file large enough to store an entire video clip and by defragmenting the capture file before capturing the clip.

capFileSetCaptureFile macro

若要將視訊擷取視窗的視訊、音訊內容儲存成檔案, 可以先使用 capFileSetCaptureFile macro 設定所要儲存的檔案名稱。若沒有預先設定, 檔案名稱則內定為 C:\CAPTURE.AVI。
The capFileSetCaptureFile macro names the file used for video capture. You can use this macro or explicitly call the WM_CAP_FILE_SET_CAPTURE_FILE message.

BOOL capFileSetCaptureFile(
hwnd,
szName
);

Parameters

hwnd

Handle to a capture window.

szName

Pointer to the null-terminated string that contains the name of the capture file to use.

Return Values

Returns TRUE if successful or FALSE if the filename is invalid or if streaming or single-frame capture is in progress.

Remarks

This message stores the filename in an internal structure. It does not create, allocate, or open the specified file. The default capture filename is C:\CAPTURE.AVI.

capFileGetCaptureFile macro

透過 capFileGetCaptureFile macro, 可以得知所錄影的視訊內容, 將會被儲存的檔案名稱。如果使用者沒有透過 capFileSetCaptureFile macro 重新設定過, 內定的名稱為 C:\CAPTURE.AVI。
The capFileGetCaptureFile macro returns the name of the current capture file. You can use this macro or explicitly call the WM_CAP_FILE_GET_CAPTURE_FILE message.

BOOL capFileGetCaptureFile(
hwnd,
szName,
wSize
);

Parameters

hwnd

Handle to a capture window.

szName

Pointer to an application-defined buffer used to return the name of the capture file as a null-terminated string.

wSize

Size, in bytes, of the application-defined buffer referenced by szName.

Return Values

Returns TRUE if successful or FALSE otherwise.

Remarks

The default capture filename is C:\CAPTURE.AVI.

Tuesday, April 17, 2012

capCaptureSequence macro

使用 capCaptureSequence macro 可以將視訊擷取視窗中的視訊與音訊內容儲存成一個 AVI 檔案, 檔案名稱則可以是透過 capFileSetCaptureFile macro 事先設定, 若沒有設定檔案名稱, 則內定為 C:\CAPTURE.AVI。
The capCaptureSequence macro initiates streaming video and audio capture to a file. You can use this macro or explicitly send the WM_CAP_SEQUENCE message.

BOOL capCaptureSequence(
hwnd
);


Parameters

hwnd

Handle of a capture window.

Return Values

Returns TRUE if successful or FALSE otherwise.
If an error occurs and an error callback function is set using the capSetCallbackOnError macro, the error callback function is called.

Remarks

If you want to alter the parameters controlling streaming capture, use the capCaptureSetSetup macro prior to starting the capture.
By default, the capture window does not allow other applications to continue running during capture. To override this, either set the fYield member of the CAPTUREPARMS structure to TRUE, or install a yield callback function.
During streaming capture, the capture window can optionally issue notifications to your application of specific types of conditions. To install callback procedures for these notifications, use the following macros:

capSetCallbackOnError
capSetCallbackOnStatus
capSetCallbackOnVideoStream
capSetCallbackOnWaveStream
capSetCallbackOnYield

Wednesday, April 04, 2012

openGL 的範例程式

C++ Builder 提供了一個關於如何使用 openGL 的範例程式, 在媒體櫃文件目錄中的

RAD Studio\9.0\Sample\CPP\VCL\OpenGL\Drawing\

內有 glskeleton.cppproj 及其相關檔案。

至於 openGL 的標頭檔則是放置於

Embarcadero\RAD Studio\9.0\include\windows\sdk\gl\

內有 gl.h, glaux.h, glu.h 等三個檔案。