{"id":3791,"date":"2018-02-25T00:31:14","date_gmt":"2018-02-24T16:31:14","guid":{"rendered":"http:\/\/www.bookcard.net\/wordpress\/?p=3791"},"modified":"2018-10-14T21:26:01","modified_gmt":"2018-10-14T13:26:01","slug":"opengl_read_bitmap_file","status":"publish","type":"post","link":"https:\/\/www.bookcard.net\/wordpress\/opengl_read_bitmap_file\/","title":{"rendered":"OpenGL\u4e4b\u8b80\u53d6Bitmap\u5716\u6a94"},"content":{"rendered":"<figure id=\"attachment_3792\" aria-describedby=\"caption-attachment-3792\" style=\"width: 1024px\" class=\"wp-caption alignnone\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/02\/OpenGL_Read_Bitmap_file.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-3792\" src=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/02\/OpenGL_Read_Bitmap_file.jpg\" alt=\"\" width=\"1024\" height=\"768\" srcset=\"https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/02\/OpenGL_Read_Bitmap_file.jpg 1024w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/02\/OpenGL_Read_Bitmap_file-300x225.jpg 300w, https:\/\/www.bookcard.net\/wordpress\/wp-content\/uploads\/2018\/02\/OpenGL_Read_Bitmap_file-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption id=\"caption-attachment-3792\" class=\"wp-caption-text\">OpenGL\u4e4b\u8b80\u53d6Bitmap\u5716\u6a94<\/figcaption><\/figure>\n<p>\u300eBitmap\u300f\u5716\u6a94\u4e4b\u526f\u6a94\u540d\u4f7f\u7528\u300e.bmp\u300f\u5b83\u975e\u5e38\u7c21\u55ae\u6613\u8b80,\u8a18\u5f97\u57282005\u5e74\u5b78DirextX\u6642\u5beb\u5716\u6a94\u5206\u6790\u5668\u5c31\u662f\u5b83.\u7f3a\u9ede\u4e0d\u652f\u6301\u58d3\u7e2e.8Bit(256\u8272)\u652f\u6301RLF\u58d3\u7e2e\u4f46\u53ea\u6709\u8272\u5f69\u55ae\u8abf\u6642\u624d\u6709\u6548\u679c\u5426\u5247\u6587\u6a94\u66f4\u5927. \u4e0d\u8981\u4ee5\u70ba256\u8272\u5df2\u7d93\u6dd8\u6c70,\u901a\u904e\u66f4\u63db\u8abf\u8272\u677f\u7684\u984f\u8272\u53ef\u4ee5\u5feb\u901f\u66f4\u63db\u984f\u8272\u4f9d\u7136\u5927\u6709\u7528\u8655.\u6e32\u67d3\u6f14\u793a\u7a0b\u5f0f<a href=\"https:\/\/www.bookcard.net\/wordpress\/opengl_image\/\">\u4e0b\u8f09<\/a>:<\/p>\n<p>BMP\u6587\u6a94\u7531\u56db\u90e8\u5206\u7d44\u6210:<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"277\">\u300eBitmap\u300f\u6587\u6a94\u7d50\u69cb<\/td>\n<td width=\"277\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">FILE_HEADER\u00a0\u00a0\u00a0 file;<\/td>\n<td width=\"277\">\u5716\u6a94\u7684\u982d\u90e8<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">INFO_HEADER\u00a0\u00a0 info;<\/td>\n<td width=\"277\">\u5716\u6a94\u7684\u4fe1\u606f<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">PALETTEENTRY\u00a0 palette[256];<\/td>\n<td width=\"277\">\u8abf\u8272\u677f\u53ea\u7528\u65bc256\u8272.<\/p>\n<p>16Bit\u300124Bit\u300132Bit\u5747\u7121\u8abf\u8272\u677f<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">PBYTE\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 buffer;<\/td>\n<td width=\"277\">\u5716\u50cf\u6578\u64da<\/p>\n<p>\u8981\u5728OpenGL\u4e2d\u6e32\u67d3\u50cf\u7d20\u300ePixel\u300f\u8981\u5012\u8f49\u6392\u6210RGB\/RGBA\u9806\u5e8f<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"277\">FILE_HEADER\u6587\u6a94\u7d50\u69cb<\/td>\n<td width=\"277\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">WORD\u00a0 type;<\/td>\n<td width=\"277\">&#8216;MB&#8217; 0x4d42 BMP\u6587\u6a94\u6a19\u8a18<\/p>\n<p>\u7528\u65bc\u5224\u65b7\u662f\u5426BMP\u6587\u6a94<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">DWORD size;<\/td>\n<td width=\"277\">\u6587\u6a94\u5927\u5c0f,\u5224\u65b7\u6587\u6a94\u662f\u5426\u5b8c\u6574<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">WORD\u00a0 reserved1;<\/td>\n<td width=\"277\">\u4fdd\u7559<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">WORD\u00a0 reserved2;<\/td>\n<td width=\"277\">\u4fdd\u7559<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">DWORD OffBits;<\/td>\n<td width=\"277\">\u5716\u50cf\u6578\u64da\u7684\u504f\u79fb\u91cf(\u6587\u6a94\u7684\u982d\u90e8)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"277\">INFO_HEADER\u5716\u6a94\u4fe1\u606f\u982d\u90e8<\/td>\n<td width=\"277\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">DWORD size;<\/td>\n<td width=\"277\">\u5716\u6a94\u4fe1\u606f\u982d\u90e8\u7684\u5927\u5c0f<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">LONG\u00a0 width;<\/td>\n<td width=\"277\">\u5716\u6a94\u5bec\u5ea6\u50cf\u7d20\u300ePixel\u300f<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">LONG\u00a0 height;<\/td>\n<td width=\"277\">\u5716\u6a94\u9ad8\u5ea6\u50cf\u7d20\u300ePixel\u300f<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">WORD\u00a0 planes;<\/td>\n<td width=\"277\">\u5e73\u9762\u91cf,\u7e3d\u70ba1<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">WORD\u00a0 bitCount;<\/td>\n<td width=\"277\">\u4f4d\u5716\u50cf\u7d20\u5c3a\u5bf8:<\/p>\n<p>8Bit(256\u8272)\u652f\u6301RLF\u58d3\u7e2e<\/p>\n<p>16BIT(\u5206\u70baRGB555\u8207RGB565), 24BIT, 32BIT<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">DWORD compression;<\/td>\n<td width=\"277\">\u58d3\u7e2e\u985e\u578b:<\/p>\n<p>0 = RGB<\/p>\n<p>0 = RGB555 0x0RRRRRGGGGGBBBBB<\/p>\n<p>3 = RGB565 0xRRRRRGGGGGGBBBBB<\/p>\n<p>1 = RLE8 (run length encoding)\u58d3\u7e2e<\/p>\n<p>2 = RLE4<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">DWORD sizeImage;<\/td>\n<td width=\"277\">\u5716\u6a94\u6578\u64da\u6240\u5360\u7a7a\u9593,\u82e5\u4f7f\u7528RLE\u58d3\u7e2e\u70ba\u58d3\u7e2e\u5f8c\u7684\u5927\u7d30<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">LONG\u00a0 XPelsPerMeter;<\/td>\n<td width=\"277\">X\u8ef8\u6bcf\u7c73\u50cf\u7d20<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">LONG\u00a0 YPelsPerMeter;<\/td>\n<td width=\"277\">Y\u8ef8\u6bcf\u7c73\u50cf\u7d20<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">DWORD ClrUsed;<\/td>\n<td width=\"277\">\u5716\u50cf\u984f\u8272\u91cf<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">DWORD ClrImportant;<\/td>\n<td width=\"277\">\u5716\u50cf\u91cd\u8981\u984f\u8272\u91cf<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<table>\n<tbody>\n<tr>\n<td width=\"277\">PALETTEENTRY\u8abf\u8272\u677f<\/td>\n<td width=\"277\">\u7c21\u4ecb<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">BYTE red;<\/td>\n<td width=\"277\">\u7d05\u8272<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">BYTE green;<\/td>\n<td width=\"277\">\u7da0\u8272<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">BYTE blue;<\/td>\n<td width=\"277\">\u85cd\u8272<\/td>\n<\/tr>\n<tr>\n<td width=\"277\">BYTE flags<\/td>\n<td width=\"277\">\u53ea\u7528\u65bcDirectDraw<\/p>\n<p>PC_EXPLICIT:\u6620\u5c04\u5230\u786c\u4ef6<\/p>\n<p>PC_NOCOLLAPSE:\u4e0d\u8981\u6620\u5c04<\/p>\n<p>PC_RESERVED:\u4fdd\u7559<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>\u8f09\u5165BMP\u4f4d\u5716C\u4ee3\u78bc<\/p>\n<p>bool Load_Bitmap(BITMAP_FILE_PTR bitmap,PBYTE data,int size)<\/p>\n<p>{<\/p>\n<p>int index;<\/p>\n<p>int line_size;\/\/ \u5716\u50cf\u6bcf\u884c\u6240\u5360\u7684\u5b57\u7bc0\u6578<\/p>\n<p>int pixel_size ;\/\/ \u50cf\u7d20\u5927\u5c0f<\/p>\n<p>PBYTE image;<\/p>\n<p>int width ;\/\/ \u5716\u5bec<\/p>\n<p>int height;\/\/ \u5716\u9ad8<\/p>\n<p>\/\/ \u8b80\u53d6\u982d\u90e8\u6578\u64da<\/p>\n<p>memcpy(&amp;bitmap-&gt;header, data, sizeof(BITMAP_FILE_HEADER));<\/p>\n<p>\/\/ \u5224\u65b7\u662f\u5426\u662f\u4f4d\u5716\u6587\u4ef6<\/p>\n<p>if (bitmap-&gt;header.type != BITMAP_ID)<\/p>\n<p>return false;\/\/\u51fa\u932f\u8fd4\u56de<\/p>\n<p>\/\/ \u8b80\u53d6\u4f4d\u5716\u4fe1\u606f\u7684\u982d\u90e8<\/p>\n<p>memcpy(&amp;bitmap-&gt;info, data + sizeof(BITMAP_FILE_HEADER), sizeof(BITMAP_INFO_HEADER));<\/p>\n<p>if (bitmap-&gt;info.sizeImage == 0)<\/p>\n<p>{<\/p>\n<p>bitmap-&gt;info.sizeImage = size &#8211; sizeof(BITMAP_FILE_HEADER) &#8211; sizeof(BITMAP_INFO_HEADER);<\/p>\n<p>if (bitmap-&gt;info.bitCount == 8)<\/p>\n<p>bitmap-&gt;info.sizeImage = bitmap-&gt;info.sizeImage &#8211; MAX_COLORS_PALETTE * sizeof(BITMAP_PALETTEENTRY);<\/p>\n<p>}<\/p>\n<p>\/\/\u5b9a\u4f4d\u5716\u50cf\u6578\u64da<\/p>\n<p>image = data + size &#8211; (int)bitmap-&gt;info.sizeImage;\/\/ \u76f8\u5c0d\u65bc\u6587\u4ef6\u5c3e<\/p>\n<p>line_size = bitmap-&gt;info.sizeImage \/ bitmap-&gt;info.height;\/\/ \u5716\u50cf\u6bcf\u884c\u6240\u5360\u7684\u5b57\u7bc0\u6578<\/p>\n<p>pixel_size = bitmap-&gt;info.bitCount \/ 8;\/\/ \u50cf\u7d20\u5927\u5c0f<\/p>\n<p>width = bitmap-&gt;info.width;\/\/ \u5716\u5bec<\/p>\n<p>height = abs(bitmap-&gt;info.height);\/\/ \u5716\u9ad8<\/p>\n<p>\/\/ \u8b80\u53d6\u4f4d\u57168\u621616,32\u4f4d\u5716<\/p>\n<p>if (bitmap-&gt;info.bitCount == 8)<\/p>\n<p>{\u00a0\u00a0 \/\/ \u8b80\u53d6\u4f4d\u5716\u7684\u8abf\u8272\u677f<\/p>\n<p>PBYTE palette = data + sizeof(BITMAP_FILE_HEADER) + sizeof(BITMAP_INFO_HEADER);<\/p>\n<p>\/\/ RGBQUAD\u7d50\u69cb\u8207PALETTEENTRY\u7d50\u69cb\u7684\u9806\u5e8f\u8abf\u8f49\u4e86<\/p>\n<p>for (index = 0; index &lt; MAX_COLORS_PALETTE; index++)<\/p>\n<p>{\/\/\u6389\u8f49\u7d05\u8272\u548c\u7da0\u8272<\/p>\n<p>bitmap-&gt;palette[index].red\u00a0\u00a0 = palette[index * 4 + 2];<\/p>\n<p>bitmap-&gt;palette[index].green = palette[index * 4 + 1];<\/p>\n<p>bitmap-&gt;palette[index].blue\u00a0 = palette[index * 4 + 0];<\/p>\n<p>bitmap-&gt;palette[index].flags = PC_NOCOLLAPSE;<\/p>\n<p>}<\/p>\n<p>\/\/\u6839\u64da\u4f4d\u5716\u5f71\u50cf\u7684\u5927\u5c0f\u751f\u8acb\u7a7a\u9593<\/p>\n<p>bitmap-&gt;buffer = (UCHAR *)malloc(abs(bitmap-&gt;info.width * bitmap-&gt;info.height * 3));<\/p>\n<p>if (bitmap-&gt;buffer == NULL)<\/p>\n<p>return false;\/\/\u51fa\u932f\u8fd4\u56de<\/p>\n<p>PBYTE buffer = NULL;<\/p>\n<p>if (bitmap-&gt;info.compression == BITMAP_COMPRESSION_RLE8)<\/p>\n<p>{<\/p>\n<p>buffer = (PBYTE)malloc(abs(bitmap-&gt;info.width * bitmap-&gt;info.height));<\/p>\n<p><a href=\"https:\/\/www.bookcard.net\/wordpress\/opengl_read_bitmap_file_rle\/\">Load_RLE8_Bitmap<\/a>(buffer, image, bitmap-&gt;info.sizeImage, bitmap-&gt;info.width);\/\/ RLE\u89e3\u78bc<\/p>\n<p>image = buffer;<\/p>\n<p>}<\/p>\n<p>\/\/ \u73fe\u5728\u5c07\u7d22\u5f15\u503c\u503c\u8f49\u70ba24BIT<\/p>\n<p>for (int y = 0; y &lt; height; ++y)<\/p>\n<p>{<\/p>\n<p>for (int x = 0; x &lt; width; ++x)<\/p>\n<p>{<\/p>\n<p>index = y * width + x;<\/p>\n<p>int color = image[index];<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 0] = bitmap-&gt;palette[color].red;<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 1] = bitmap-&gt;palette[color].green;<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 2] = bitmap-&gt;palette[color].blue;<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>if (bitmap-&gt;info.compression == BITMAP_COMPRESSION_RLE8)<\/p>\n<p>free(buffer);<\/p>\n<p>\/\/\u6700\u5f8c\u5c07\u4f4d\u5716\u4f4d\u6578\u8b8a\u70ba24\u4f4d<\/p>\n<p>bitmap-&gt;info.bitCount = 24;<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>if (bitmap-&gt;info.bitCount == 16)\/\/ \u8b80\u53d616\u4f4d\u5716<\/p>\n<p>{\u00a0 \/\/ \u4ee524BIT\u5206\u914d\u8a18\u61b6\u9ad4\u7a7a\u9593<\/p>\n<p>bitmap-&gt;buffer = (UCHAR *)malloc(abs(bitmap-&gt;info.width * bitmap-&gt;info.height * 3));<\/p>\n<p>if (bitmap-&gt;buffer == NULL)<\/p>\n<p>return false;\/\/\u51fa\u932f\u8fd4\u56de<\/p>\n<p>if (bitmap-&gt;info.compression == 3)<\/p>\n<p>{\/\/ RGB565<\/p>\n<p>for (int y = 0; y &lt; height; ++y)<\/p>\n<p>{<\/p>\n<p>for (int x = 0; x &lt; width; ++x)<\/p>\n<p>{\/\/ \u73fe\u5728\u5c07\u5404\u500b16\u4f4dRGB\u503c\u8f49\u70ba32\u4f4d\u503c<\/p>\n<p>index = y * line_size + x * 2;<\/p>\n<p>WORD color = (image[index + 1] &lt;&lt; 8) | image[index + 0];<\/p>\n<p>UCHAR red = ((color &gt;&gt; 11) &amp; 0x1f);<\/p>\n<p>UCHAR green = ((color &gt;&gt; 5) &amp; 0x3f);<\/p>\n<p>UCHAR blue = (color &amp; 0x1f);<\/p>\n<p>index = y * width + x;<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 0] = (red &lt;&lt; 3);<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 1] = (green &lt;&lt; 2);<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 2] = (blue &lt;&lt; 3);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{\/\/ RGB555<\/p>\n<p>for (int y = 0; y &lt; height; ++y)<\/p>\n<p>{<\/p>\n<p>for (int x = 0; x &lt; width; ++x)<\/p>\n<p>{<\/p>\n<p>index = y * line_size + x * 2;<\/p>\n<p>WORD color = (image[index + 1] &lt;&lt; 8) | image[index + 0];<\/p>\n<p>UCHAR red = (((color) &gt;&gt; 10) &amp; 0x1f);<\/p>\n<p>UCHAR green = (((color) &gt;&gt; 5) &amp; 0x1f);<\/p>\n<p>UCHAR blue = ((color) &amp; 0x1f);<\/p>\n<p>index = y * width + x;<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 0] = (red &lt;&lt; 3);<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 1] = (green &lt;&lt; 3);<\/p>\n<p>bitmap-&gt;buffer[index * 3 + 2] = (blue &lt;&lt; 3);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/\/\u6700\u5f8c\u5c07\u4f4d16BIT\u8b8a\u70ba24BIT<\/p>\n<p>bitmap-&gt;info.bitCount = 24;<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>if (bitmap-&gt;info.bitCount == 24)\/\/ \u8b80\u53d624BIT\u5716\u6a94<\/p>\n<p>{\u00a0\u00a0 \/\/ \u6839\u64da\u4f4d\u5716\u5f71\u50cf\u7684\u5927\u5c0f\u7533\u8acb\u7a7a\u9593<\/p>\n<p>bitmap-&gt;buffer = (UCHAR *)malloc(bitmap-&gt;info.sizeImage);<\/p>\n<p>if (bitmap-&gt;buffer == NULL)\/\/ \u7533\u8acb\u5167\u5b58\u7a7a\u9593\u5931\u6557<\/p>\n<p>return false;\/\/\u51fa\u932f\u8fd4\u56de<\/p>\n<p>\/\/ \u8b80\u53d6\u5716\u50cf<\/p>\n<p>for (int y = 0; y &lt; height; ++y)<\/p>\n<p>{<\/p>\n<p>for (int x = 0; x &lt; width; ++x)<\/p>\n<p>{\/\/ \u8f49\u63dbGL_RGB\u6a21\u5f0f<\/p>\n<p>index = y * line_size + x * 3;<\/p>\n<p>bitmap-&gt;buffer[index + 0] = image[index + 2];\/\/\u9010\u500b\u50cf\u7d20\u5730\u62f7\u8c9d<\/p>\n<p>bitmap-&gt;buffer[index + 1] = image[index + 1];<\/p>\n<p>bitmap-&gt;buffer[index + 2] = image[index + 0];<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>if (bitmap-&gt;info.bitCount == 32)\/\/ \u8655\u740632BIT\u5716\u6a94<\/p>\n<p>{ \u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ \u6839\u64da\u4f4d\u5716\u5f71\u50cf\u7684\u5927\u5c0f\u7533\u8acb\u7a7a\u9593<\/p>\n<p>bitmap-&gt;buffer = (UCHAR *)malloc(bitmap-&gt;info.sizeImage);<\/p>\n<p>if (bitmap-&gt;buffer == NULL)\/\/\u82e5\u4e0d\u80fd\u7533\u8acb\u7a7a\u9593<\/p>\n<p>return false;\/\/\u51fa\u932f\u9000\u51fa<\/p>\n<p>\/\/ \u50cf\u7d20\u8f49\u70baBGRA 32Bit\u80af\u5b9a\u662f4\u5b57\u7bc0\u5c0d\u9f4a<\/p>\n<p>for (index = 0; index &lt; (int)bitmap-&gt;info.sizeImage-4; index=index+4)<\/p>\n<p>{<\/p>\n<p>bitmap-&gt;buffer[index + 0] = image[index + 2];\/\/\u9010\u500b\u50cf\u7d20\u5730\u62f7\u8c9d<\/p>\n<p>bitmap-&gt;buffer[index + 1] = image[index + 1];<\/p>\n<p>bitmap-&gt;buffer[index + 2] = image[index + 0];<\/p>\n<p>bitmap-&gt;buffer[index + 3] = image[index + 3];<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>else<\/p>\n<p>{<\/p>\n<p>return false;\/\/\u56b4\u91cd\u6587\u63d0<\/p>\n<p>}<\/p>\n<p>if (bitmap-&gt;info.height &lt; 0)\/\/ height\u70ba\u8ca0\u6642\u8868\u793a\u5716\u7247\u985b\u5012<\/p>\n<p>Flip_Bitmap(bitmap-&gt;buffer, bitmap-&gt;info.width*(bitmap-&gt;info.bitCount \/ 8), bitmap-&gt;info.height);<\/p>\n<p>bitmap-&gt;info.height = abs(bitmap-&gt;info.height);<\/p>\n<p>return true;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>\u5c07\u985b\u5012\u7684BMP\u6587\u4ef6\u7ffb\u8f49\u904e\u4f86<\/p>\n<p>bool Flip_Bitmap(UCHAR *image, int bytes_per_line, int height)<\/p>\n<p>{<\/p>\n<p>UCHAR *buffer; \/\/\u7528\u65bc\u81e8\u6642\u4fdd\u5b58\u4f4d\u5716\u6578\u64da.<\/p>\n<p>int index;\u00a0\u00a0\u00a0\u00a0 \/\/\u5faa\u74b0\u8a08\u6578<\/p>\n<p>\/\/\u5206\u914d\u55ae\u884c\u7a7a\u9593<\/p>\n<p>buffer = (UCHAR <em>)malloc(bytes_per_line<\/em>height);<\/p>\n<p>if (buffer == NULL)<\/p>\n<p>return false;<\/p>\n<p>\/\/ \u55ae\u884c\u62f7\u8c9d<\/p>\n<p>memcpy(buffer, image, bytes_per_line*height);<\/p>\n<p>\/\/ \u5782\u76f4\u985b\u5012\u5716\u7247<\/p>\n<p>for (index = 0; index &lt; height; index++)<\/p>\n<p>memcpy(&amp;image[((height &#8211; 1) &#8211; index)<em>bytes_per_line], &amp;buffer[index<\/em>bytes_per_line], bytes_per_line);<\/p>\n<p>\/\/\u91cb\u653e\u7a7a\u9593<\/p>\n<p>free(buffer);<\/p>\n<p>return true;\/\/\u8fd4\u56de<\/p>\n<p>}<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u300eBitmap\u300f\u5716\u6a94\u4e4b\u526f\u6a94\u540d\u4f7f\u7528\u300e.bmp\u300f\u5b83\u975e\u5e38\u7c21\u55ae\u6613\u8b80,\u8a18\u5f97\u57282005\u5e74\u5b78DirextX\u6642\u5beb\u5716\u6a94\u5206\u6790\u5668\u5c31\u662f &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.bookcard.net\/wordpress\/opengl_read_bitmap_file\/\" class=\"more-link\">\u7e7c\u7e8c\u95b1\u8b80 <span class=\"screen-reader-text\">OpenGL\u4e4b\u8b80\u53d6Bitmap\u5716\u6a94<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[62],"tags":[50],"class_list":["post-3791","post","type-post","status-publish","format-standard","hentry","category-opengl","tag-opengl","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/comments?post=3791"}],"version-history":[{"count":8,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3791\/revisions"}],"predecessor-version":[{"id":4666,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/posts\/3791\/revisions\/4666"}],"wp:attachment":[{"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/media?parent=3791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/categories?post=3791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bookcard.net\/wordpress\/wp-json\/wp\/v2\/tags?post=3791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}