IMAGE* ReadOneFrame(const char *fname, int nFrame, unsigned int W, unsigned H) { /*defining local variables*/ FILE *file; unsigned int x, y; unsigned char ch; IMAGE* image ; /*checking error*/ assert(fname); assert(nFrame >= 0); image = CreateImage(W, H) ; assert(image) ; /*opening file stream*/ file = fopen(fname, "r"); assert(file) ; /*find desired frame*/ fseek(file, 1.5 * nFrame * W * H, SEEK_SET); for(y = 0; y < H; y ++){ for(x = 0; x < W; x ++){ ch = fgetc(file); SetPixelY(image, x, y, ch); }/*rof*/ } for(y = 0; y < H ; y += 2){ for(x = 0; x < W ; x += 2){ ch = fgetc(file); SetPixelU(image, x, y, ch); SetPixelU(image, x + 1, y, ch); SetPixelU(image, x, y + 1, ch); SetPixelU(image, x + 1, y + 1, ch); } } for(y = 0; y < H ; y += 2){ for(x = 0; x < W ; x += 2){ ch = fgetc(file); SetPixelV(image, x, y, ch); SetPixelV(image, x + 1, y, ch); SetPixelV(image, x, y + 1, ch); SetPixelV(image, x + 1, y + 1, ch); } } /*checking for error*/ assert(ferror(file) == 0) ; /*closing stream and terminating*/ fclose(file); file = NULL; return image; }
static HCURSOR CreateCompatibleCursor(FTexture *cursorpic) { int picwidth = cursorpic->GetWidth(); int picheight = cursorpic->GetHeight(); // Create bitmap masks for the cursor from the texture. HDC dc = GetDC(NULL); if (dc == NULL) { return false; } HDC and_mask_dc = CreateCompatibleDC(dc); HDC xor_mask_dc = CreateCompatibleDC(dc); HBITMAP and_mask = CreateCompatibleBitmap(dc, 32, 32); HBITMAP xor_mask = CreateCompatibleBitmap(dc, 32, 32); ReleaseDC(NULL, dc); SelectObject(and_mask_dc, and_mask); SelectObject(xor_mask_dc, xor_mask); // Initialize with an invisible cursor. SelectObject(and_mask_dc, GetStockObject(WHITE_PEN)); SelectObject(and_mask_dc, GetStockObject(WHITE_BRUSH)); Rectangle(and_mask_dc, 0, 0, 32, 32); SelectObject(xor_mask_dc, GetStockObject(BLACK_PEN)); SelectObject(xor_mask_dc, GetStockObject(BLACK_BRUSH)); Rectangle(xor_mask_dc, 0, 0, 32, 32); FBitmap bmp; const BYTE *pixels; bmp.Create(picwidth, picheight); cursorpic->CopyTrueColorPixels(&bmp, 0, 0); pixels = bmp.GetPixels(); // Copy color data from the source texture to the cursor bitmaps. for (int y = 0; y < picheight; ++y) { for (int x = 0; x < picwidth; ++x) { const BYTE *bgra = &pixels[x*4 + y*bmp.GetPitch()]; if (bgra[3] != 0) { SetPixelV(and_mask_dc, x, y, RGB(0,0,0)); SetPixelV(xor_mask_dc, x, y, RGB(bgra[2], bgra[1], bgra[0])); } } } DeleteDC(and_mask_dc); DeleteDC(xor_mask_dc); // Create the cursor from the bitmaps. return CreateBitmapCursor(cursorpic->LeftOffset, cursorpic->TopOffset, and_mask, xor_mask); }
BOOL SPRITE::SetColorKey( LONG Colors ){ if ( Colors == CLR_INVALID )return TRUE; // マスクを不可視領域に作成 // DirectDrawは、カラーキーセッティング if ( CompatibleDC ){ for ( int j = 0 ; j < Size.cy ; j++ ){ for ( int i = 0 ; i < Size.cx ; i++ ){ LONG src = GetPixel( CompatibleDC , i , j ); // 画面上半分は元画像(カラーキーにしたい色は黒へ、それ以外はcontinue) if ( src == Colors ) SetPixelV( CompatibleDC , i , j , 0x0 ); // 画面下半分はマスク分の画像 SetPixelV( CompatibleDC , i , Size.cy + j , ( src == Colors ? 0xFFFFFF : 0x0 ) ); } } }else if ( DDrawSurf ){ HDC hDC ;SURFACEDESC ddsd; COLORREF PrevClr ; DWORD PhysicalClr; // GDIで、まずは点を打つ DDrawSurf->GetDC( &hDC ); PrevClr = GetPixel( hDC , 0 , 0 ); SetPixelV( hDC , 0 , 0 , Colors ); DDrawSurf->ReleaseDC( hDC ); // Lockを行い、直接アクセス。物理色の取得 ZeroMemory( &ddsd , sizeof(ddsd) );ddsd.dwSize = sizeof( ddsd ); while ( DDrawSurf->Lock( NULL, &ddsd, 0, NULL) == DDERR_WASSTILLDRAWING ); PhysicalClr = *( DWORD * )ddsd.lpSurface; // 取得 // Mask if ( ddsd.ddpfPixelFormat.dwRGBBitCount < 32 ) PhysicalClr &= (1 << ddsd.ddpfPixelFormat.dwRGBBitCount) - 1; DDrawSurf->Unlock( NULL ); // 元の色をリストア DDrawSurf->GetDC( &hDC ); SetPixelV( hDC , 0 , 0 , PrevClr ); DDrawSurf->ReleaseDC ( hDC ); DDCOLORKEY ddck = { PhysicalClr , PhysicalClr }; DDrawSurf->SetColorKey( DDCKEY_SRCBLT , &ddck ); } CLRKey = Colors; return TRUE; }
static PetscErrorCode PetscDrawPoint_Win32(PetscDraw draw,PetscReal x,PetscReal y,int color) { PetscDraw_Win32 *windraw = (PetscDraw_Win32*)draw->data; HBRUSH hbrush; HRGN hrgn; int radius; int x1,yone; HDC hdc; PetscFunctionBegin; TranslateColor_Win32(draw,color); x1 = XTRANS(draw,windraw,x); yone = YTRANS(draw,windraw,y); hbrush = CreateSolidBrush(windraw->currentcolor); if(windraw->node->DoubleBuffered) { hdc = windraw->node->DoubleBuffer; } else { hdc = windraw->node->Buffer; } /* desired size is one logical pixel so just turn it on */ if (windraw->pointdiameter == 1) { SetPixelV(hdc,x1,yone,windraw->currentcolor); } else { /* draw point around position determined */ radius = windraw->pointdiameter/2; /* integer division */ hrgn = CreateEllipticRgn(x1-radius,yone-radius,x1+radius,yone+radius); FillRgn(hdc,hrgn,hbrush); } /* Forces a WM_PAINT and erases background */ InvalidateRect(windraw->hWnd,NULL,TRUE); UpdateWindow(windraw->hWnd); PetscFunctionReturn(0); }
void ShowBMP(HDC myDc) const { HBITMAP hbmp; HDC hBfr; hbmp = CreateCompatibleBitmap( myDc, m_iWid, m_iHgh ); hBfr = CreateCompatibleDC( myDc ); SelectObject( hBfr, hbmp ); for (int i=0; i<m_iSize; i+=4) { int pos = i / 4; int x = pos % m_iWid; int y = pos / m_iWid; BYTE* ptr = &(byte[i]); //BYTE white = 255; //BYTE Red = AlphaBlend(ptr[0], white, alpha); //BYTE Green = AlphaBlend(ptr[1], white, alpha); //BYTE Blue = AlphaBlend(ptr[2], 0, alpha); //SetPixelV( hBfr, x, y, RGB( Red, Green, Blue) ); SetPixelV( hBfr, x, y, RGB( ptr[0], ptr[1], ptr[2]) ); } //显示 也可以缩放 StretchBlt( myDc, 0, 0, m_iWid, m_iHgh, hBfr, 0, 0, m_iWid, m_iHgh, SRCCOPY ); }
/* Load a file into a GDI surface. */ HBITMAP LoadWin32Surface( CString fn ) { CString error; RageSurface *s = RageSurfaceUtils::LoadFile( fn, error ); if( s == NULL ) return NULL; RageSurfaceUtils::ConvertSurface( s, s->w, s->h, 32, 0xFF000000, 0x00FF0000, 0x0000FF00, 0 ); HBITMAP bitmap = CreateCompatibleBitmap( GetDC(NULL), s->w, s->h ); ASSERT( bitmap ); HDC BitmapDC = CreateCompatibleDC( GetDC(NULL) ); SelectObject( BitmapDC, bitmap ); /* This is silly, but simple. We only do this once, on a small image. */ for( int y = 0; y < s->h; ++y ) { unsigned const char *line = ((unsigned char *) s->pixels) + (y * s->pitch); for( int x = 0; x < s->w; ++x ) { unsigned const char *data = line + (x*s->format->BytesPerPixel); SetPixelV( BitmapDC, x, y, RGB( data[3], data[2], data[1] ) ); } } SelectObject( BitmapDC, NULL ); DeleteObject( BitmapDC ); delete s; return bitmap; }
int MPE_Draw_points(MPE_XGraph &graph, MPE_Point *points, int num_points) { for (int i=0; i<num_points; i++) graph.map[points[i].x + points[i].y*graph.width] = points[i].c; if (graph.bVisible) { WaitForSingleObject(g_hHDCMutex, INFINITE); for (int i=0; i<num_points; i++) SetPixelV(g_hDC, points[i].x, points[i].y, points[i].c); ReleaseMutex(g_hHDCMutex); InvalidateRect(graph.hWnd, 0, TRUE); } return 0; }
static void w32_drawpixel(int x, int y, GrxColor color) { HDC hDC; COLORREF c; GRX_ENTER(); drawpixel(x, y, color); c = GetPixel ( hDCMem, x, y ); hDC = GetDC ( hGRXWnd ); SetPixelV ( hDC, x, y, c ); ReleaseDC ( hGRXWnd, hDC ); GRX_LEAVE(); }
// This function plots a pixel in the specified color at point (x,y) // void putpixel( int x, int y, int color ) { HDC hDC; WindowData* pWndData = BGI__GetWindowDataPtr( ); color = converttorgb( color ); // The call to SetPixelV might fail, but I don't know what to do if it does. hDC = BGI__GetWinbgiDC( ); SetPixelV( hDC, x, y, color ); BGI__ReleaseWinbgiDC( ); // The update rectangle does not contain the right or bottom edge. Thus // add 1 so the entire region is included. RECT rect = { x, y, x+1, y+1 }; RefreshWindow( &rect ); }
void iupDrawLine(IdrawCanvas* dc, int x1, int y1, int x2, int y2, unsigned char r, unsigned char g, unsigned char b, int style) { POINT line_poly[2]; HPEN hPen = CreatePen(style==IUP_DRAW_STROKE_DASH? PS_DASH: PS_SOLID, 1, RGB(r, g, b)); HPEN hPenOld = SelectObject(dc->hBitmapDC, hPen); line_poly[0].x = x1; line_poly[0].y = y1; line_poly[1].x = x2; line_poly[1].y = y2; Polyline(dc->hBitmapDC, line_poly, 2); SetPixelV(dc->hBitmapDC, x2, y2, RGB(r, g, b)); SelectObject(dc->hBitmapDC, hPenOld); DeleteObject(hPen); }
Pixmap WinXCreateBitmapFromData(Display * dpy, Drawable d, char *data, unsigned int width, unsigned int height, int color) { HBITMAP hbm; int i; int j; WORD *e; BITMAP bm = { 0, // LONG bmType; 16, // LONG bmWidth; 16, // LONG bmHeight; 4, // LONG bmWidthBytes; 1, // WORD bmPlanes; 1, // WORD bmBitsPixel; NULL // LPVOID bmBits; }; RECT rect = { 0, 0, 16, 16 }; HDC hDC = GetDC(xid[d].hwnd.hWnd); HDC hDCb = CreateCompatibleDC(hDC); hbm = CreateCompatibleBitmap(hDC, width, height); SelectObject(hDCb, hbm); SelectPalette(hDCb, myPal, FALSE); RealizePalette(hDCb); FillRect(hDCb, &rect, GetStockObject(BLACK_BRUSH)); if (!hbm) error("Can't create item bitmaps"); if (width != 16 || height != 16) error("Can only create 16x16 bitmaps"); e = (WORD *) data; for (i = 0; i < 16; i++) { WORD w = *e++; WORD z = 0; for (j = 0; j < 16; j++) // swap the bits in the bytes if (w & (1 << j)) SetPixelV(hDCb, j, i, WinXPColour(color)); } DeleteDC(hDCb); ReleaseDC(xid[d].hwnd.hWnd, hDC); return ((Pixmap) hbm); }
void _DrawFrame(HDC hdc, POINT const *pPoints, int iCount, COLORREF clrLine) { HGDIOBJ hPen = NULL; HGDIOBJ hOldPen; int i; hPen = CreatePen(PS_SOLID, 1, clrLine); hOldPen = SelectObject(hdc, hPen); MoveToEx(hdc, pPoints[0].x, pPoints[0].y, NULL); for(i = 1; i < iCount; ++i) LineTo(hdc, pPoints[i].x, pPoints[i].y); SetPixelV(hdc, pPoints[iCount-1].x, pPoints[iCount-1].y, clrLine); SelectObject(hdc, hOldPen); DeleteObject(hPen); }
// add bitmap at the specified column void CCustomListRowWnd::AddBitmap(INT32 col, HBITMAP hBitmap,HBITMAP, DWORD dwBackColour) { CStatic* pStat = new CStatic(); ASSERT(m_ColumnObjects[col] == NULL); m_ColumnObjects[col] = pStat ; CRect cr; GetClientRect(&cr); BITMAP bitmap; CBitmap::FromHandle(hBitmap)->GetBitmap(&bitmap); CRect srect; srect.left = m_Parent->m_Parent->m_ColumnOffsetsArray[col] ; srect.right = srect.left + bitmap.bmWidth; srect.top = cr.Height()/2 - bitmap.bmHeight/2; srect.bottom = cr.Height()/2 + bitmap.bmHeight/2; //// HDC hBitmapDC = CreateCompatibleDC(NULL); if (!hBitmapDC) { ERROR2RAW("Non-fatal GDI error"); } SelectObject(hBitmapDC, hBitmap); // Iff we haven't been told what the background colour is... // We make the assumption that the pixel in the lower right corner has the background colour if (dwBackColour == 0xFFFFFFFF) dwBackColour = (DWORD) GetPixel(hBitmapDC, bitmap.bmWidth - 1, bitmap.bmHeight -1); DWORD sysBkColour = GetSysColor(COLOR_3DFACE); for (INT32 i = 0; i < bitmap.bmWidth; i++) { for (INT32 j = 0; j < bitmap.bmHeight; j++) { if ((DWORD) GetPixel(hBitmapDC, i, j) == dwBackColour) SetPixelV(hBitmapDC, i, j, (COLORREF) sysBkColour); } } DeleteDC(hBitmapDC); //// pStat->Create(NULL, WS_VISIBLE | SS_BITMAP, srect, this); pStat->SetBitmap(hBitmap); }
// --- funkcja wykonywana w ka¿dym przebiegu efektu --- void Pracuj() { POINT ptPiksel; BYTE byOdcien; // wybieramy pewn¹ iloœæ pikseli i zmieniamy ich kolory for (unsigned i = 0; i < ZMIENNOSC; ++i) { // losujemy wspó³rzêdne zmienianego piksela ptPiksel.x = rand() % g_rcObszarKlienta.right; ptPiksel.y = rand() % g_rcObszarKlienta.bottom; // losujemy odcieñ szaroœci byOdcien = rand() % 256; // zmieniamy piksel SetPixelV (g_hdcOkno, ptPiksel.x, ptPiksel.y, RGB(byOdcien, byOdcien, byOdcien)); } }
int GetTrueScreenDepth(HDC hDC) { // don't think I really use/rely on this method anymore...luckily since it looks gross int RetDepth = GetDeviceCaps(hDC, BITSPIXEL); if (RetDepth = 16) { // Find out if this is 5:5:5 or 5:6:5 HBITMAP hBMP = CreateCompatibleBitmap(hDC, 1, 1); HBITMAP hOldBMP = (HBITMAP)SelectObject(hDC, hBMP); // TODO do we need to delete this? if (hOldBMP != NULL) { SetPixelV(hDC, 0, 0, 0x000400); if ((GetPixel(hDC, 0, 0) & 0x00FF00) != 0x000400) RetDepth = 15; SelectObject(hDC, hOldBMP); } DeleteObject(hBMP); } return RetDepth; }
void draw_rect(int x, int y, int w, int h, COLORREF c) { HPEN pn, po; HBRUSH br, bo; if(w == 1 && h == 1) { SetPixelV(dc, x, y, intensecolors ? c : col_bar_line); }else{ if(!intensecolors) { if(c) { pn = CreatePen(PS_SOLID, 1, col_bar_line); br = CreateSolidBrush(col_bar_fill); }else{ pn = CreatePen(PS_SOLID, 1, 0); br = CreateSolidBrush(0); } }else{ if(w != 1) pn = CreatePen(PS_SOLID, 1, 0); else pn = CreatePen(PS_SOLID, 1, c ); br = CreateSolidBrush(c); } po = (HPEN) SelectObject(dc, pn); bo = (HBRUSH) SelectObject(dc, br); Rectangle(dc, x, y, x + w, y + h); SelectObject(dc, po); SelectObject(dc, bo); DeleteObject(pn); DeleteObject(br); } }
//alpha融合图像,显示 //src的长宽均小于dest位图的长宽 void operator()(HDC myDc, const CBMP& srcBmp, const CBMP& destBmp) { int minWid = min(srcBmp.m_iWid, destBmp.m_iWid); int minHgh = min(srcBmp.m_iHgh, destBmp.m_iHgh); int maxWid = max(srcBmp.m_iWid, destBmp.m_iWid); int maxHgh = max(srcBmp.m_iHgh, destBmp.m_iHgh); int src = 0; int dst = 0; HBITMAP hbmp; HDC hBfr; hbmp = CreateCompatibleBitmap( myDc, srcBmp.m_iWid, srcBmp.m_iHgh ); hBfr = CreateCompatibleDC( myDc ); SelectObject( hBfr, hbmp ); // 只是在src的区域上面做融合 for (; src<srcBmp.m_iSize; src+=4, dst+=4) { int pos = src/4; int x = pos % srcBmp.m_iWid; int y = pos / srcBmp.m_iWid; COLOR colorSrc = srcBmp(src); COLOR colorDest = destBmp(x, y); BYTE red = AlphaBlend(colorSrc.red, colorDest.red, alpha); BYTE green = AlphaBlend(colorSrc.green, colorDest.green, alpha); BYTE blue = AlphaBlend(colorSrc.blue, colorDest.blue, alpha); SetPixelV( hBfr, x, y, RGB( red, green, blue) ); //SetPixelV( hBfr, x, y, RGB(colorDest.red, colorDest.green, colorDest.blue) ); //SetPixelV( hBfr, x, y, RGB(srcBmp.byte[src], srcBmp.byte[src+1], srcBmp.byte[src+2]) ); } //显示 也可以缩放 StretchBlt( myDc, 0, 0, srcBmp.m_iWid, srcBmp.m_iHgh, hBfr, 0, 0, srcBmp.m_iWid, srcBmp.m_iHgh, SRCCOPY ); }
int GetTrueScreenDepth(HDC hDC) { int RetDepth = GetDeviceCaps(hDC, BITSPIXEL); if (RetDepth = 16) { // Find out if this is 5:5:5 or 5:6:5 HDC DeskDC = GetDC(NULL); // TODO probably wrong for HWND hmm... HBITMAP hBMP = CreateCompatibleBitmap(DeskDC, 1, 1); ReleaseDC(NULL, DeskDC); HBITMAP hOldBMP = (HBITMAP)SelectObject(hDC, hBMP); if (hOldBMP != NULL) { SetPixelV(hDC, 0, 0, 0x000400); if ((GetPixel(hDC, 0, 0) & 0x00FF00) != 0x000400) RetDepth = 15; SelectObject(hDC, hOldBMP); } DeleteObject(hBMP); } return RetDepth; }
// helper function to change the background colour of the bitmap to the one used by dialog backgrounds BOOL SetBitmapBkgToSystem(HBITMAP hBitmap) { BITMAP bitmap; HDC hBitmapDC = CreateCompatibleDC(NULL); if (!GetObject(hBitmap, sizeof(bitmap), &bitmap) || !hBitmapDC) { ERROR2RAW("Non-fatal GDI error"); return(FALSE); } SelectObject(hBitmapDC, hBitmap); // We make the assumption that the pixel in the lower right corner has the background colour DWORD currentBkColour = (DWORD) GetPixel(hBitmapDC, bitmap.bmWidth - 1, bitmap.bmHeight -1); DWORD sysBkColour = GetSysColor(COLOR_3DFACE); for (INT32 i = 0; i < bitmap.bmWidth; i++) { for (INT32 j = 0; j < bitmap.bmHeight; j++) { if ((DWORD) GetPixel(hBitmapDC, i, j) == currentBkColour) SetPixelV(hBitmapDC, i, j, (COLORREF) sysBkColour); } } DeleteDC(hBitmapDC); return TRUE; }
static void paint_cb(HWND window, PAINTSTRUCT* ps, HDC dc) { int textwidth, textheight; glyphcache_getfontsize(&textwidth, &textheight); int x1 = ps->rcPaint.left / textwidth; x1 -= 1; /* because of overlapping characters */ if (x1 < 0) x1 = 0; int y1 = ps->rcPaint.top/textheight; int x2 = ps->rcPaint.right/textwidth; x2 += 1; /* because of overlapping characters */ if (x2 >= screenwidth) { RECT r = {screenwidth*textwidth, 0, ps->rcPaint.right, ps->rcPaint.bottom}; FillRect(dc, &r, GetStockObject(BLACK_BRUSH)); x2 = screenwidth; } int y2 = ps->rcPaint.bottom / textheight; if (y2 >= screenheight) { RECT r = {0, screenheight*textheight, ps->rcPaint.right, ps->rcPaint.bottom}; FillRect(dc, &r, GetStockObject(BLACK_BRUSH)); y2 = screenheight-1; } int state = SaveDC(dc); HPEN brightpen = CreatePen(PS_SOLID, 0, 0xffffff); HPEN normalpen = CreatePen(PS_SOLID, 0, 0x888888); HPEN dimpen = CreatePen(PS_SOLID, 0, 0x555555); for (int y = y1; y <= y2; y++) { int sy = y * textheight; /* Clear this line (or at least the part of it we're drawing). */ RECT r = {ps->rcPaint.left, sy, ps->rcPaint.right, sy+textheight}; FillRect(dc, &r, GetStockObject(BLACK_BRUSH)); /* Draw the actual text. */ for (int x = x1; x < x2; x++) { int seq = y*screenwidth + x; int sx = x * textwidth; unsigned int id = frontbuffer[seq]; struct glyph* glyph = glyphcache_getglyph(id, dc); if (glyph) { BitBlt(dc, sx+glyph->xoffset, sy+glyph->yoffset, glyph->realwidth, glyph->realheight, glyph->dc, 0, 0, SRCPAINT); if (id & DPY_UNDERLINE) { if (id & DPY_BRIGHT) SelectObject(dc, brightpen); else if (id & DPY_DIM) SelectObject(dc, dimpen); else SelectObject(dc, normalpen); MoveToEx(dc, sx, sy+textheight-1, NULL); LineTo(dc, sx+glyph->width, sy+textheight-1); } } } /* Now go through and invert any characters which are in reverse. */ for (int x = x1; x < x2; x++) { int seq = y*screenwidth + x; int sx = x * textwidth; unsigned int id = frontbuffer[seq]; if (id & DPY_REVERSE) { int w; struct glyph* glyph = glyphcache_getglyph(id, dc); if (glyph) w = glyph->width; else w = textwidth; BitBlt(dc, sx, sy, w, textheight, NULL, 0, 0, DSTINVERT); } } } /* Draw the cursor caret. */ { int x = cursorx*textwidth; int y = cursory*textheight; SelectObject(dc, brightpen); MoveToEx(dc, x, y, NULL); LineTo(dc, x, y+textheight); SetPixelV(dc, x-1, y-1, 0xffffff); SetPixelV(dc, x+1, y-1, 0xffffff); SetPixelV(dc, x-1, y+textheight, 0xffffff); SetPixelV(dc, x+1, y+textheight, 0xffffff); } DeleteObject(brightpen); DeleteObject(normalpen); DeleteObject(dimpen); RestoreDC(dc, state); }
/* second-phase constrcutor */ bool WinBitmap::construct(const byte* dataBuf, uint32 nbrBytes, int dpiCorrectionFactor) { /* get the current DC format */ m_dc = CreateCompatibleDC(NULL); if(m_dc == NULL) { return(false); } /** TGA Implementation **/ #if 1 register int32 row, col; register int32 index; int32 red, green, blue, alpha; int32 bitDepth; HDC maskDC = NULL; HDC tmpDC = NULL; HDC tmpMaskDC = NULL; HBITMAP oldMaskBmp = NULL; HBITMAP tmpBmp = NULL; HBITMAP tmpMask = NULL; HBITMAP oldTmpBmp = NULL; HBITMAP oldTmpMask = NULL; /* get the BMP file information */ TGAHEADER tgaHeader; ::memcpy(&tgaHeader, dataBuf, sizeof(TGAHEADER)); /* get the location of the color data */ int offset = sizeof(TGAHEADER) + tgaHeader.numCharsID; const byte* colorData = reinterpret_cast<const byte*>(&dataBuf[offset]); bool useColorMap = false; if ( tgaHeader.colorMapType == 1 ) { // Use color map. useColorMap = true; // Read the color map data. int offsetToColorData = readColorMapData( tgaHeader, colorData ); // Add the offset to colorData so that the colorData actually // points to the color data instead of to the color map. colorData += offsetToColorData; } // colorData should now point at the color data! /* set the dimensions */ int width = tgaHeader.imageWidth; int height = tgaHeader.imageHeight; // Removed since the images will be requested in correct size from server // m_width = width * dpiCorrectionFactor; // m_height = height * dpiCorrectionFactor; m_width = width; m_height = height; /* get the bit-depth of the image */ bitDepth = tgaHeader.bitsPerPixel; /* create the bitmap using the given info */ m_bmp = CreateBitmap(m_width, m_height, 1, GetDeviceCaps(m_dc, BITSPIXEL), NULL); if(m_bmp == NULL) { /* cannot create bitmap */ return(false); } tmpDC = CreateCompatibleDC( NULL ); if(tmpDC == NULL) { return(false); } tmpBmp = CreateBitmap(width, height, 1, GetDeviceCaps(m_dc, BITSPIXEL), NULL); if(tmpBmp == NULL) { DeleteDC(tmpDC); return(false); } /* select the bitmap into the DC */ m_oldBmp = (HBITMAP)SelectObject(m_dc, m_bmp); oldTmpBmp = (HBITMAP)SelectObject(tmpDC, tmpBmp); /* create the same sized monocrome mask if required */ if(bitDepth == 32) { m_mask = CreateBitmap(m_width, m_height, 1, 1, NULL); /* check for errors */ if(m_mask == NULL) { SelectObject(tmpDC, oldTmpBmp); DeleteObject(tmpBmp); DeleteDC(tmpDC); return(false); } /* create DC, and select the mask into it */ maskDC = CreateCompatibleDC(NULL); /* check for errors */ if(maskDC == NULL) { SelectObject(tmpDC, oldTmpBmp); DeleteObject(tmpBmp); DeleteDC(tmpDC); return(false); } /* select our monochrome mask into it */ oldMaskBmp = (HBITMAP)SelectObject(maskDC, m_mask); tmpMask = CreateBitmap(width, height, 1, 1, NULL); /* check for errors */ if(tmpMask == NULL) { SelectObject(tmpDC, oldTmpBmp); DeleteObject(tmpBmp); DeleteDC(tmpDC); SelectObject(maskDC, oldMaskBmp); DeleteDC(maskDC); return(false); } /* create DC, and select the mask into it */ tmpMaskDC = CreateCompatibleDC(NULL); /* check for errors */ if(tmpMaskDC == NULL) { SelectObject(tmpDC, oldTmpBmp); DeleteObject(tmpBmp); DeleteDC(tmpDC); SelectObject(maskDC, oldMaskBmp); DeleteDC(maskDC); DeleteObject(tmpMask); return(false); } /* select our monochrome mask into it */ oldTmpMask = (HBITMAP)SelectObject(tmpMaskDC, tmpMask); } /* Bottom-up TGAs are expected .. read and create */ index = 0; for(row = height-1; row >= 0; --row) { for(col = 0; col < width; ++col) { /* 32-bit TGAs need different processing from 24-bit */ if(bitDepth == 32) { if ( useColorMap ) { int colorMapIdx = colorData[ index++ ]; PIXEL p = m_colorMap[ colorMapIdx ]; blue = p.blue; green = p.green; red = p.red; alpha = 255; } else { // No color map. /* read the color value in components */ blue = colorData[index++]; green = colorData[index++]; red = colorData[index++]; alpha = colorData[index++]; } /* write the color pixel */ SetPixel(tmpDC, col, row, MS_RGB(red,green,blue)); /* check the alpha component */ if(alpha > 127) { /* solid pixel */ SetPixel(tmpMaskDC, col, row, MS_RGB(255,255,255)); } else { /* transparent pixel */ SetPixel(tmpMaskDC, col, row, MS_RGB(0,0,0)); } } /* expecting 24-bit RGB Image */ else { if ( useColorMap ) { int colorMapIdx = colorData[ index++ ]; PIXEL p = m_colorMap[ colorMapIdx ]; blue = p.blue; green = p.green; red = p.red; } else { // No color map. /* read the color value in components */ blue = colorData[index++]; green = colorData[index++]; red = colorData[index++]; } /* write the color pixel */ SetPixel(tmpDC, col, row, MS_RGB(red,green,blue)); } } } StretchBlt(m_dc, 0, 0, m_width, m_height, tmpDC, 0, 0, width, height, SRCCOPY); /* delete temp dc and bitmap */ SelectObject(tmpDC, oldTmpBmp); DeleteObject(tmpBmp); DeleteDC(tmpDC); /* release the mask DC if used */ if(bitDepth == 32) { StretchBlt(maskDC, 0, 0, m_width, m_height, tmpMaskDC, 0, 0, width, height, SRCCOPY); m_visibleRect = calculateVisibleRect(maskDC, m_width, m_height); /* delete mask dc */ SelectObject(maskDC, oldMaskBmp); DeleteDC(maskDC); /* delete tmp mask dc and temp mask bitmap */ SelectObject(tmpMaskDC, oldTmpMask); DeleteObject(tmpMask); DeleteDC(tmpMaskDC); } if(bitDepth == 32) { /* set our masked flag */ m_isMasked = true; } else { m_isMasked = false; } /* success */ return(true); #endif /** BMP Implementation **/ #if 0 register int32 row, col; register int32 index; int32 red, green, blue, alpha; HDC maskDC = NULL; HBITMAP oldMaskBmp = NULL; /* get the BMP file information */ BITMAPFILEHEADER bmHeader; BITMAPINFOHEADER bmInfo; ::memcpy(&bmHeader, dataBuf, sizeof(BITMAPFILEHEADER)); ::memcpy(&bmInfo, &dataBuf[sizeof(BITMAPFILEHEADER)], sizeof(BITMAPINFOHEADER)); /* get the location of the color data */ const byte* colorData = reinterpret_cast<const byte*>(&dataBuf[bmHeader.bfOffBits]); /* set the dimensions */ m_width = bmInfo.biWidth; m_height = bmInfo.biHeight; /* create the bitmap using the given info */ m_bmp = CreateBitmap(m_width, m_height, 1, GetDeviceCaps(m_dc, BITSPIXEL), NULL); if(m_bmp == NULL) { /* cannot create bitmap */ return(false); } /* select the bitmap into the DC */ m_oldBmp = (HBITMAP)SelectObject(m_dc, m_bmp); /* create the same sized monocrome mask if required */ if(bmInfo.biBitCount == 32) { m_mask = CreateBitmap(m_width, m_height, 1, 1, NULL); /* check for errors */ if(m_mask == NULL) { return(false); } /* create DC, and select the mask into it */ maskDC = CreateCompatibleDC(NULL); /* check for errors */ if(maskDC == NULL) { return(false); } /* select our monochrome mask into it */ oldMaskBmp = (HBITMAP)SelectObject(maskDC, m_mask); } /* Bottom-up BMP's are expected .. read and create */ index = 0; for(row = m_height-1; row >= 0; --row) { for(col = 0; col < m_width; ++col) { /* 32-bit BMP's need different processing from 24-bit */ if(bmInfo.biBitCount == 32) { /* read the color value in components */ alpha = colorData[index++]; blue = colorData[index++]; green = colorData[index++]; red = colorData[index++]; /* write the color pixel */ SetPixelV(m_dc, col, row, MS_RGB(red,green,blue)); /* check the alpha component */ if(alpha > 127) { /* solid pixel */ SetPixelV(maskDC, col, row, MS_RGB(255,255,255)); } else { /* transparent pixel */ SetPixelV(maskDC, col, row, MS_RGB(0,0,0)); } } /* expecting 24-bit RGB Image */ else { /* read the color value in components */ blue = colorData[index++]; green = colorData[index++]; red = colorData[index++]; /* write the color pixel */ SetPixelV(m_dc, col, row, MS_RGB(red,green,blue)); } } } /* release the mask DC if used */ if(bmInfo.biBitCount == 32) { SelectObject(maskDC, oldMaskBmp); DeleteDC(maskDC); } if(bmInfo.biBitCount == 32) { /* set our masked flag */ m_isMasked = true; } else { m_isMasked = false; } /* success */ return(true); #endif /* TESTING Implemntation */ #if 0 /* try to create the bitmap -- TESTING */ m_bmp = CreateBitmap(7, 7, 1, GetDeviceCaps(m_dc, BITSPIXEL), NULL); if(m_bmp == NULL) { /* delete the DC */ DeleteDC(m_dc); return(false); } /* select the bitmap into the DC */ m_oldBmp = (HBITMAP)SelectObject(m_dc, m_bmp); /* set the dimensions */ m_width = 7; m_height = 7; /* TEST - clear the bitmap */ HBRUSH clrBrush = CreateSolidBrush( MS_RGB(200,20,20) ); RECT bmpRect; SetRect(&bmpRect, 0, 0, m_width, m_height); FillRect(m_dc, &bmpRect, clrBrush); DeleteObject(clrBrush); /* success */ return(true); #endif }
static void test_Render(void) { IPicture *pic; HRESULT hres; short type; PICTDESC desc; OLE_XSIZE_HIMETRIC pWidth; OLE_YSIZE_HIMETRIC pHeight; COLORREF result, expected; HDC hdc = GetDC(0); /* test IPicture::Render return code on uninitialized picture */ OleCreatePictureIndirect(NULL, &IID_IPicture, TRUE, (VOID**)&pic); hres = IPicture_get_Type(pic, &type); ok(hres == S_OK, "IPicture_get_Type does not return S_OK, but 0x%08x\n", hres); ok(type == PICTYPE_UNINITIALIZED, "Expected type = PICTYPE_UNINITIALIZED, got = %d\n", type); /* zero dimensions */ hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 10, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); /* nonzero dimensions, PICTYPE_UNINITIALIZED */ hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 10, NULL); ole_expect(hres, S_OK); IPicture_Release(pic); desc.cbSizeofstruct = sizeof(PICTDESC); desc.picType = PICTYPE_ICON; desc.u.icon.hicon = LoadIcon(NULL, IDI_APPLICATION); if(!desc.u.icon.hicon){ win_skip("LoadIcon failed. Skipping...\n"); ReleaseDC(NULL, hdc); return; } OleCreatePictureIndirect(&desc, &IID_IPicture, TRUE, (VOID**)&pic); /* zero dimensions, PICTYPE_ICON */ hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 10, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 10, 0, 0, 0, 0, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 10, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 10, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); hres = IPicture_Render(pic, hdc, 0, 0, 0, 0, 0, 0, 10, 10, NULL); ole_expect(hres, CTL_E_INVALIDPROPERTYVALUE); /* Check if target size and position is respected */ IPicture_get_Width(pic, &pWidth); IPicture_get_Height(pic, &pHeight); SetPixelV(hdc, 0, 0, 0x00F0F0F0); SetPixelV(hdc, 5, 5, 0x00F0F0F0); SetPixelV(hdc, 10, 10, 0x00F0F0F0); expected = GetPixel(hdc, 0, 0); hres = IPicture_Render(pic, hdc, 1, 1, 9, 9, 0, 0, pWidth, -pHeight, NULL); ole_expect(hres, S_OK); if(hres != S_OK) { IPicture_Release(pic); ReleaseDC(NULL, hdc); return; } /* Evaluate the rendered Icon */ result = GetPixel(hdc, 0, 0); ok(result == expected, "Color at 0,0 should be unchanged 0x%06X, but was 0x%06X\n", expected, result); result = GetPixel(hdc, 5, 5); ok(result != expected || broken(result == expected), /* WinNT 4.0 and older may claim they drew */ /* the icon, even if they didn't. */ "Color at 5,5 should have changed, but still was 0x%06X\n", expected); result = GetPixel(hdc, 10, 10); ok(result == expected, "Color at 10,10 should be unchanged 0x%06X, but was 0x%06X\n", expected, result); IPicture_Release(pic); ReleaseDC(NULL, hdc); }
inline void _SetPixel_n(HDC hDC, int y1, int x1, COLORREF color){ SetPixelV(hDC, x1, y1, color); }
/**************************************************************************** * * FUNCTION: MakeNewANDMaskBasedOnPoint * * PURPOSE: Creates a new AND mask for the icon image * * PARAMS: LPICONIMAGE lpIcon - pointer to icon image data * POINT pt - coords of transparent pixel * * RETURNS: BOOL - TRUE for success, FALSE for failure * * COMMENTS: Creates the AND mask using the color of the pixel at pt * as a transparent color. The XOR mask is changed as well. * This is because the OS expects the XOR mask to have the * AND mask already applied (ie black in transparent areas) * * History: * July '95 - Created * \****************************************************************************/ BOOL MakeNewANDMaskBasedOnPoint( LPICONIMAGE lpIcon, POINT pt ) { HBITMAP hXORBitmap, hOldXORBitmap; HDC hDC, hMemDC1; LPBYTE pXORBits; COLORREF crTransparentColor; LONG i,j; // Account for height*2 thing lpIcon->lpbi->bmiHeader.biHeight /= 2; // Need a DC hDC = GetDC( NULL ); // Use DIBSection for source hXORBitmap = CreateDIBSection( hDC, lpIcon->lpbi, DIB_RGB_COLORS, &pXORBits, NULL, 0 ); memcpy( pXORBits, lpIcon->lpXOR, (lpIcon->lpbi->bmiHeader.biHeight) * BytesPerLine((LPBITMAPINFOHEADER)(lpIcon->lpbi)) ); hMemDC1 = CreateCompatibleDC( hDC ); hOldXORBitmap = SelectObject( hMemDC1, hXORBitmap ); // Set the color table if need be if( lpIcon->lpbi->bmiHeader.biBitCount <= 8 ) SetDIBColorTable( hMemDC1, 0, DIBNumColors((LPSTR)(lpIcon->lpbi)), lpIcon->lpbi->bmiColors); // What's the transparent color? crTransparentColor = GetPixel( hMemDC1, pt.x, pt.y ); // Loop through the pixels for(i=0;i<lpIcon->lpbi->bmiHeader.biWidth;i++) { for(j=0;j<lpIcon->lpbi->bmiHeader.biHeight;j++) { // Is the source transparent at this point? if( GetPixel( hMemDC1, i, j ) == crTransparentColor ) { // Yes, so set the pixel in AND mask, and clear it in XOR mask SetMonoDIBPixel( lpIcon->lpAND, lpIcon->lpbi->bmiHeader.biWidth, lpIcon->lpbi->bmiHeader.biHeight, i, j, TRUE ); if( lpIcon->lpbi->bmiHeader.biBitCount == 1 ) SetMonoDIBPixel( pXORBits, lpIcon->lpbi->bmiHeader.biWidth, lpIcon->lpbi->bmiHeader.biHeight, i, j, FALSE ); else SetPixelV( hMemDC1, i, j, RGB(0,0,0) ); } else { // No, so clear pixel in AND mask SetMonoDIBPixel( lpIcon->lpAND, lpIcon->lpbi->bmiHeader.biWidth, lpIcon->lpbi->bmiHeader.biHeight, i, j, FALSE ); } } } // Flush the SetPixelV() calls GdiFlush(); SelectObject( hMemDC1, hOldXORBitmap ); // Copy the new XOR bits back to our storage memcpy( lpIcon->lpXOR, pXORBits, (lpIcon->lpbi->bmiHeader.biHeight) * BytesPerLine((LPBITMAPINFOHEADER)(lpIcon->lpbi)) ); // Clean up DeleteObject( hXORBitmap ); DeleteDC( hMemDC1 ); ReleaseDC( NULL, hDC ); // UnAccount for height*2 thing lpIcon->lpbi->bmiHeader.biHeight *= 2; return TRUE; }
// changed by MW void WinDrawPoint (int x, int y, OSPictContext context) { SetPixelV (context->hDC, x, y, context->penColor); // (for printing) } /* WinDrawPoint */
ENTRYPOINT void draw_galaxy(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); GC gc = MI_GC(mi); unistruct *gp = &universes[MI_SCREEN(mi)]; double d, eps, cox, six, cor, sir; /* tmp */ int i, j, k; /* more tmp */ XPoint *dummy = NULL; if (! dbufp) XClearWindow(MI_DISPLAY(mi), MI_WINDOW(mi)); if(spin){ gp->rot_y += 0.01; gp->rot_x += 0.004; } cox = COSF(gp->rot_y); six = SINF(gp->rot_y); cor = COSF(gp->rot_x); sir = SINF(gp->rot_x); eps = 1/(EPSILON * sqrt_EPSILON * DELTAT * DELTAT * QCONS); for (i = 0; i < gp->ngalaxies; ++i) { Galaxy *gt = &gp->galaxies[i]; for (j = 0; j < gp->galaxies[i].nstars; ++j) { Star *st = >->stars[j]; XPoint *newp = >->newpoints[j]; double v0 = st->vel[0]; double v1 = st->vel[1]; double v2 = st->vel[2]; for (k = 0; k < gp->ngalaxies; ++k) { Galaxy *gtk = &gp->galaxies[k]; double d0 = gtk->pos[0] - st->pos[0]; double d1 = gtk->pos[1] - st->pos[1]; double d2 = gtk->pos[2] - st->pos[2]; d = d0 * d0 + d1 * d1 + d2 * d2; if (d > EPSILON) d = gtk->mass / (d * sqrt(d)) * DELTAT * DELTAT * QCONS; else d = gtk->mass / (eps * sqrt(eps)); v0 += d0 * d; v1 += d1 * d; v2 += d2 * d; } st->vel[0] = v0; st->vel[1] = v1; st->vel[2] = v2; st->pos[0] += v0; st->pos[1] += v1; st->pos[2] += v2; newp->x = (short) (((cox * st->pos[0]) - (six * st->pos[2])) * gp->scale) + gp->midx; newp->y = (short) (((cor * st->pos[1]) - (sir * ((six * st->pos[0]) + (cox * st->pos[2])))) * gp->scale) + gp->midy; } for (k = i + 1; k < gp->ngalaxies; ++k) { Galaxy *gtk = &gp->galaxies[k]; double d0 = gtk->pos[0] - gt->pos[0]; double d1 = gtk->pos[1] - gt->pos[1]; double d2 = gtk->pos[2] - gt->pos[2]; d = d0 * d0 + d1 * d1 + d2 * d2; if (d > EPSILON) d = 1 / (d * sqrt(d)) * DELTAT * QCONS; else d = 1 / (EPSILON * sqrt_EPSILON) * DELTAT * QCONS; d0 *= d; d1 *= d; d2 *= d; gt->vel[0] += d0 * gtk->mass; gt->vel[1] += d1 * gtk->mass; gt->vel[2] += d2 * gtk->mass; gtk->vel[0] -= d0 * gt->mass; gtk->vel[1] -= d1 * gt->mass; gtk->vel[2] -= d2 * gt->mass; } gt->pos[0] += gt->vel[0] * DELTAT; gt->pos[1] += gt->vel[1] * DELTAT; gt->pos[2] += gt->vel[2] * DELTAT; #if 1 // hacked and optimized by katahiromz { if (dbufp) { int count = gt->nstars; const XPoint *pt = gt->oldpoints; while (count-- > 0) { SetPixelV(display, pt->x, pt->y, 0); ++pt; } } XSetForeground(display, gc, MI_PIXEL(mi, gt->galcol)); { int count = gt->nstars; const XPoint *pt = gt->newpoints; const unsigned long rgb = gc->foreground_rgb; while (count-- > 0) { SetPixelV(display, pt->x, pt->y, rgb); ++pt; } } } #else if (dbufp) { XSetForeground(display, gc, MI_WIN_BLACK_PIXEL(mi)); XDrawPoints(display, window, gc, gt->oldpoints, gt->nstars, CoordModeOrigin); } XSetForeground(display, gc, MI_PIXEL(mi, COLORSTEP * gt->galcol)); XSetForeground(display, gc, MI_PIXEL(mi, gt->galcol)); XDrawPoints(display, window, gc, gt->newpoints, gt->nstars, CoordModeOrigin); #endif dummy = gt->oldpoints; gt->oldpoints = gt->newpoints; gt->newpoints = dummy; } gp->step++; if (gp->step > gp->f_hititerations * 4) startover(mi); }
int main(int argc, char* argv[]) { HANDLE hMPQ=0,hMPQ2=0,hMPQ3=0; DWORD *dwPalette = (DWORD *)_alloca(1024); memset(dwPalette,0,1024); LoadStorm("SFMpq.dll"); SetMpqDll("SFMpq.dll"); if (SFileOpenArchive!=0) { char *buffer = (char *)_alloca(13); memcpy(buffer,"StarDat.mpq",12); if (SFileOpenArchive(buffer,1000,0,&hMPQ)==0) return 0; memcpy(buffer,"BrooDat.mpq",12); SFileOpenArchive(buffer,2000,0,&hMPQ2); memcpy(buffer,"Patch_rt.mpq",13); SFileOpenArchive(buffer,3000,0,&hMPQ3); } BufferInfo BI; LoadPalette("tileset\\Platform.wpe",dwPalette); HANDLE hGrp, hGrp2; if (argc>1) hGrp = LoadGrp(argv[1]); else hGrp = LoadGrp("unit\\zerg\\zergling.grp"); HDC hDC = GetDC(0); GRPHEADER GrpInfo; if (GetGrpInfo(hGrp,&GrpInfo)==0) {GrpInfo.nFrames=0;GrpInfo.wMaxWidth=0;GrpInfo.wMaxHeight=0;} BI.nWidth = GrpInfo.wMaxWidth; BI.nHeight = GrpInfo.wMaxHeight; //BI.nWidth = 255; //BI.nHeight = 255; BI.pBuffer = (signed short *)malloc(GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short)); WORD i,x,y; DWORD j, nGrpSize; unsigned int u,v; memset(BI.pBuffer, 0xFF, GrpInfo.nFrames * BI.nWidth * BI.nHeight * sizeof(short)); //for (DWORD j=0;j<16;j++){ /*for (WORD i=0;i<GrpInfo.nFrames;i++) { DrawGrp(hGrp,hDC,0,0,i,dwPalette,ALPHA_BLEND,0x401020); }*/ signed short clrPixel; RECT rect; /*for (i=0;i<GrpInfo.nFrames;i++) { for (j=0;j<16;j++) { rand_s(&u); rand_s(&v); u = u % 800; v = v % 600; DrawGrp(hGrp,hDC,u,v,i,dwPalette,ALPHA_BLEND,0x404040); } }*/ SetFunctionGetPixel((GETPIXELPROC)ReadPixelFromBuffer); SetFunctionSetPixel((SETPIXELPROC)WritePixelToBuffer); for (i=0;i<GrpInfo.nFrames;i++) { BI.nFrame = i; u = (BI.nWidth - GrpInfo.wMaxWidth) / 2; v = (BI.nHeight - GrpInfo.wMaxHeight) / 2; for (y = 0; y < BI.nHeight; y++) { for (x = 0; x < BI.nWidth; x++) { WritePixelToBuffer(&BI, x, y, -1); } } DrawGrp(hGrp,(HDC)&BI,u,v,i,0,USE_INDEX,0); } hGrp2 = hGrp; hGrp = CreateGrp(BI.pBuffer, GrpInfo.nFrames, BI.nWidth, BI.nHeight, FALSE, &nGrpSize); /*HANDLE hFile; hFile = CreateFile("generated zergling.grp", GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); if (hFile != INVALID_HANDLE_VALUE) { WriteFile(hFile, hGrp, nGrpSize, &j, 0); CloseHandle(hFile); }*/ BI.nFrame = 0xFFFF; j=0; for (i=0;i<GrpInfo.nFrames;i+=1) { rect.left = rect.top = 0; rect.right = rect.left + BI.nWidth; rect.bottom = rect.top + BI.nHeight; for (x = 0; x < BI.nWidth * BI.nHeight; x++) BI.pBuffer[x] = -1; //for (j=0;j<(1 * 1);j++) { // DrawGrp(hGrp,(HDC)&BI,i,0,i % (17*8),dwPalette,ALPHA_BLEND,0x401020); //DrawGrp(hGrp2,(HDC)&BI,0,0,i,0,USE_INDEX,0x401020); //u = memcmp(BI.pBuffer, &BI.pBuffer[i * BI.nWidth * BI.nHeight], BI.nWidth * BI.nHeight * sizeof(short)); DrawGrp(hGrp,(HDC)&BI,0,0,i,0,USE_INDEX,0x401020); u = memcmp(BI.pBuffer, &BI.pBuffer[i * BI.nWidth * BI.nHeight], BI.nWidth * BI.nHeight * sizeof(short)); for (x = 0; x < BI.nWidth; x++) for (y = 0; y < BI.nHeight; y++) { clrPixel = BI.pBuffer[(y * BI.nWidth) + x]; if (clrPixel != -1) SetPixelV(hDC, x, y, dwPalette[clrPixel]); } //} if (u) { printf("Output of re-encoded graphic for frame %d does not match original! Total %d\n", i, ++j); //break; } FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1)); } for (i=4;i<400;i+=17) { rect.left = rect.top = 400-i; rect.right = rect.left + BI.nWidth; rect.bottom = rect.top + BI.nHeight; for (x = 0; x < BI.nWidth * BI.nHeight; x++) BI.pBuffer[x] = -1; for (j=0;j<32;j++) { // DrawGrp(hGrp,(HDC)&BI,400-i,0,i % (17*8),dwPalette,HORIZONTAL_FLIP|ALPHA_BLEND,0x401020); DrawGrp(hGrp,(HDC)&BI,0,0,i % (17*8),0,HORIZONTAL_FLIP|USE_INDEX,0x401020); for (x = 0; x < BI.nWidth; x++) for (y = 0; y < BI.nHeight; y++) { clrPixel = BI.pBuffer[(y * BI.nWidth) + x]; if (clrPixel != -1) SetPixelV(hDC, 400-i + x, 400-i + y, dwPalette[clrPixel]); } } FillRect(hDC, &rect, (HBRUSH) (COLOR_WINDOW+1)); } for (i = 0; i < BI.nWidth; i++) for (j = 0; j < BI.nHeight; j++) { clrPixel = BI.pBuffer[(j * BI.nWidth) + i]; if (clrPixel != -1) SetPixelV(hDC, 400 + i, 300 + j, dwPalette[clrPixel]); } //} ReleaseDC(0,hDC); free(BI.pBuffer); DestroyGrp(hGrp); DestroyGrp(hGrp2); if (SFileCloseArchive!=0) { if (hMPQ3!=0) SFileCloseArchive(hMPQ3); if (hMPQ2!=0) SFileCloseArchive(hMPQ2); if (hMPQ!=0) SFileCloseArchive(hMPQ); } return 0; }