Changeset 2393
- Timestamp:
- Jun 14, 2008, 3:02:23 PM (15 years ago)
- Location:
- www/img2oric
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
www/img2oric/img2oric.c
r2392 r2393 406 406 { 407 407 #if defined _WIN32 408 PBITMAPINFO pbinfo; 409 BITMAPINFO binfo; 410 BITMAPFILEHEADER bfheader; 411 ULONG bisize; 412 HANDLE hfile; 408 413 HBITMAP tmp; 409 414 HDC hdc; 415 DWORD ret; 410 416 #else 411 417 SDL_Surface *tmp, *surface; 418 #endif 419 FILE *f; 412 420 uint8_t *pixels; 413 #endif414 FILE *f;415 421 int *src, *dst, *srcl, *dstl; 416 422 int stride, x, y, depth, c; … … 479 485 uint8_t bg = 0, fg = 7; 480 486 481 fprintf(stderr, "\rProcessing... %i%%", (y * 100 + 50) / HEIGHT);487 fprintf(stderr, "\rProcessing... %i%%", (y * 100 + 99) / HEIGHT); 482 488 483 489 for(x = 0; x < WIDTH; x += 6) … … 517 523 } 518 524 525 fclose(f); 526 519 527 fprintf(stderr, " done.\n"); 520 528 … … 529 537 SetPixel(hdc, x, y, RGB(r, g, b)); 530 538 } 531 /* FIXME: how do I save the image now? */ 539 540 binfo.bmiHeader.biSize = sizeof(binfo.bmiHeader); 541 binfo.bmiHeader.biBitCount = 0; 542 GetDIBits(hdc, tmp, 0, 0, NULL, &binfo, DIB_RGB_COLORS); 543 544 switch(binfo.bmiHeader.biBitCount) 545 { 546 case 24: 547 bisize = sizeof(BITMAPINFOHEADER); 548 break; 549 case 16: 550 case 32: 551 bisize = sizeof(BITMAPINFOHEADER) + sizeof(DWORD) * 3; 552 break; 553 default: 554 bisize = sizeof(BITMAPINFOHEADER) 555 + sizeof(RGBQUAD) * (1 << binfo.bmiHeader.biBitCount); 556 break; 557 } 558 559 pbinfo = (PBITMAPINFO)GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, bisize); 560 memcpy(pbinfo, &binfo, sizeof(BITMAPINFOHEADER)); 561 562 bfheader.bfType = 0x4D42; /* "BM" */ 563 bfheader.bfSize = sizeof(BITMAPFILEHEADER) 564 + bisize + pbinfo->bmiHeader.biSizeImage; 565 bfheader.bfReserved1 = 0; 566 bfheader.bfReserved2 = 0; 567 bfheader.bfOffBits = sizeof(BITMAPFILEHEADER) + bisize; 568 569 pixels = GlobalAlloc(GMEM_FIXED | GMEM_ZEROINIT, 570 binfo.bmiHeader.biSizeImage); 571 GetDIBits(hdc, tmp, 0, pbinfo->bmiHeader.biHeight, 572 pixels, pbinfo, DIB_RGB_COLORS); 573 574 hfile = CreateFile(BMPFILE, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 575 FILE_ATTRIBUTE_ARCHIVE, NULL); 576 WriteFile(hfile, &bfheader, sizeof(BITMAPFILEHEADER), &ret, NULL); 577 WriteFile(hfile, pbinfo, bisize, &ret, NULL); 578 WriteFile(hfile, pixels, pbinfo->bmiHeader.biSizeImage, &ret, NULL); 579 CloseHandle(hfile); 580 581 GlobalFree(pbinfo); 582 GlobalFree(pixels); 532 583 #else 533 584 for(y = 0; y < HEIGHT; y++) … … 539 590 #endif 540 591 541 fclose(f);542 543 592 return 0; 544 593 }
Note: See TracChangeset
for help on using the changeset viewer.