[PR]

水無瀬の部屋 > Programming > sample > goddess > g24a2bmp.cpp
最終更新日: 2007/03/17

   1: //*********************************************************
   2: // プロジェクト: ああっ壁神さまっ
   3: //   ファイル名: g24a2bmp.cpp
   4: //*********************************************************
   5: #include "g24a2bmp.h"
   6: #include <filefmt/bmpfile.h>
   7: 
   8: 
   9: bool fread2( BYTE *buf, int bufsize, const BYTE *src, size_t srcsize/*, FILE *fr*/ )
  10: {
  11: 	BYTE rgb[6];
  12: 	BYTE window[0x0FFF+1];
  13: 	memzero( window, sizeof(window) );
  14: 	memzero( rgb, sizeof(rgb) );
  15: 
  16: 	DWORD pos = 0;
  17: 	DWORD count = 3;
  18: 	while( 0 < srcsize )
  19: 	{
  20: 		const DWORD flag = *src++; srcsize--;
  21: 		for( DWORD i = 0; i < 8; i++ )
  22: 		{
  23: 			if ( srcsize <= 0 )
  24: 				return 0 == bufsize;
  25: 
  26: 			if ( 0 != (flag & (1 << i)) )
  27: 			{
  28: 				const DWORD c = *src++; srcsize--;
  29: 				window[ pos++ ] = (BYTE)c;
  30: 				pos = (pos & (sizeof(window)-1));
  31: 				rgb[count++] = (BYTE)c;
  32: 				if ( sizeof(rgb) <= count )
  33: 				{
  34: 					if ( bufsize < 3 )
  35: 						return false;
  36: 
  37: 					rgb[0] = (BYTE)(rgb[0] + rgb[3]);
  38: 					rgb[1] = (BYTE)(rgb[1] + rgb[4]);
  39: 					rgb[2] = (BYTE)(rgb[2] + rgb[5]);
  40: 					memmove( buf, rgb, 3 ); buf += 3; bufsize -= 3;
  41: 					count = 3;
  42: 				}
  43: 			}
  44: 			else
  45: 			{
  46: 				const DWORD l = *src++; srcsize--;
  47: 				const DWORD h = *src++; srcsize--;
  48: 				const DWORD length =  3 +   (h & 0x000F);
  49: 				const DWORD offset = 18 + (((h & 0xF0) << 4) | l) & (sizeof(window)-1);
  50: 
  51: 				for( DWORD j = 0; j < length; j++ )
  52: 				{
  53: 					const BYTE c = window[ (offset + j) & (sizeof(window)-1) ];
  54: 					window[ pos++ ] = (BYTE)c;
  55: 					pos = (pos & (sizeof(window)-1));
  56: 					rgb[count++] = (BYTE)c;
  57: 					if ( sizeof(rgb) <= count )
  58: 					{
  59: 						if ( bufsize < 3 )
  60: 							return false;
  61: 
  62: 						rgb[0] = (BYTE)(rgb[0] + rgb[3]);
  63: 						rgb[1] = (BYTE)(rgb[1] + rgb[4]);
  64: 						rgb[2] = (BYTE)(rgb[2] + rgb[5]);
  65: 						memmove( buf, rgb, 3 ); buf += 3; bufsize -= 3;
  66: 						count = 3;
  67: 					}
  68: 				}
  69: 			}
  70: 		}
  71: 	}
  72: 	return true;
  73: }
  74: 
  75: //*********************************************************
  76: // g24a2bmp
  77: //*********************************************************
  78: BYTE *g24a2bmp( FILE *fr, BITMAPINFOHEADER *bih )
  79: {
  80: 	// g24a
  81: 	BYTE head[1024];
  82: 	if ( 4 != fread( head, 1, 4, fr ) )
  83: 		return NULL;
  84: 	if ( 0 != memcmp( head, "g24a", 4 ) )
  85: 		return NULL;
  86: 	// BITMAPINFOHEADER
  87: 	if ( sizeof(BITMAPINFOHEADER) != fread( bih, 1, sizeof(BITMAPINFOHEADER), fr ) )
  88: 		return NULL;
  89: 
  90: 	// image
  91: 	const int size = CalcBitmapImageSize( bih );
  92: 	BYTE *img = (BYTE *)malloc( size );
  93: 	if ( !img ) return NULL;
  94: 	memzero( img, size );
  95: 
  96: 	ASSERT( 24 == bih->biBitCount );
  97: 	fread( img, 1, 8, fr );
  98: 	ASSERT( size == (int)((DWORD *)img)[1] );
  99: 	BYTE *src = (BYTE *)malloc( size ); // 
 100: 	const size_t readsize = fread( src, 1, size, fr );
 101: 	VERIFY( fread2( img, size, src, readsize ) );
 102: 	free( src );
 103: 	return img;
 104: }//g24a2bmp
 105: 
 106: 
 107: //** end **

参照:


Google
ご意見・ご感想をお聞かせ下さい。匿名で送信できます。

 * 返信が必要な場合には postmaster@katsura-kotonoha.sakura.ne.jp へ直接メールしてください。

水無瀬の部屋 > sample > goddess > g24a2bmp.cpp

このページは cpp2web が出力しました。
水無瀬 優 postmaster@katsura-kotonoha.sakura.ne.jp
http://katsura-kotonoha.sakura.ne.jp/prog/code/goddess/g24a2bmp_cpp.shtml
『新妻LOVELY×CATION』を応援しています!