Changeset 73 for trunk/ScreenTools.pas
- Timestamp:
- Jan 15, 2017, 4:12:10 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ScreenTools.pas
r72 r73 9 9 {$ENDIF} 10 10 StringTables, LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, 11 Forms, Menus ;11 Forms, Menus, GraphType; 12 12 13 13 type … … 42 42 procedure SetXY(X, Y: Integer); inline; // Set pixel position relative to base 43 43 procedure SetX(X: Integer); inline; // Set horizontal pixel position relative to base 44 procedure Init(Bitmap: T Bitmap; BaseX: Integer = 0; BaseY: Integer = 0); inline;44 procedure Init(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0); inline; 45 45 end; 46 46 PPixelPointer = ^TPixelPointer; … … 188 188 gfNoError = $01; 189 189 gfNoGamma = $02; 190 gfJPG = $04;191 190 192 191 type … … 411 410 end; 412 411 412 procedure ApplyGammaToBitmap(Bitmap: TBitmap); 413 var 414 PixelPtr: TPixelPointer; 415 X, Y: Integer; 416 begin 417 Bitmap.BeginUpdate; 418 PixelPtr.Init(Bitmap); 419 for Y := 0 to Bitmap.Height - 1 do begin 420 for X := 0 to Bitmap.Width - 1 do begin 421 PixelPtr.Pixel^.B := GammaLUT[PixelPtr.Pixel^.B]; 422 PixelPtr.Pixel^.G := GammaLUT[PixelPtr.Pixel^.G]; 423 PixelPtr.Pixel^.R := GammaLUT[PixelPtr.Pixel^.R]; 424 PixelPtr.NextPixel; 425 end; 426 PixelPtr.NextLine; 427 end; 428 Bitmap.EndUpdate; 429 end; 430 431 procedure CopyGray8BitTo24bitBitmap(Dst, Src: TRasterImage); 432 var 433 SrcPtr, DstPtr: TPixelPointer; 434 X, Y: Integer; 435 begin 436 //Dst.SetSize(Src.Width, Src.Height); 437 SrcPtr.Init(Src); 438 DstPtr.Init(Dst); 439 for Y := 0 to Src.Height - 1 do begin 440 for X := 0 to Src.Width - 1 do begin 441 DstPtr.Pixel^.B := SrcPtr.Pixel^.B; 442 DstPtr.Pixel^.G := SrcPtr.Pixel^.B; 443 DstPtr.Pixel^.R := SrcPtr.Pixel^.B; 444 SrcPtr.NextPixel; 445 DstPtr.NextPixel; 446 end; 447 SrcPtr.NextLine; 448 DstPtr.NextLine; 449 end; 450 end; 451 413 452 function LoadGraphicFile(bmp: TBitmap; Path: string; Options: integer): boolean; 414 453 var 415 PixelPtr: TPixelPointer;416 454 jtex: tjpegimage; 417 X, Y: Integer; 418 begin 419 result := true; 420 if Options and gfJPG <> 0 then 421 begin 455 Png: TPortableNetworkGraphic; 456 begin 457 Result := True; 458 if ExtractFileExt(Path) = '.jpg' then begin 422 459 jtex := tjpegimage.create; 423 460 try 424 jtex. loadfromfile(Path + '.jpg');461 jtex.LoadFromFile(Path); 425 462 except 426 result := false; 427 end; 428 if result then 429 begin 430 if Options and gfNoGamma = 0 then 431 bmp.PixelFormat := pf24bit; 432 bmp.Width := jtex.Width; 433 bmp.Height := jtex.Height; 434 bmp.Canvas.draw(0, 0, jtex); 463 Result := False; 464 end; 465 if result then begin 466 if Options and gfNoGamma = 0 then bmp.PixelFormat := pf24bit; 467 Bmp.SetSize(jtex.Width, jtex.Height); 468 Bmp.Canvas.Draw(0, 0, jtex); 435 469 end; 436 470 jtex.Free; 437 end 438 else 439 begin 471 end else 472 if ExtractFileExt(Path) = '.png' then begin 473 Png := TPortableNetworkGraphic.Create; 474 Png.PixelFormat := Bmp.PixelFormat; 440 475 try 441 bmp.loadfromfile(Path + '.bmp');476 Png.LoadFromFile(Path); 442 477 except 443 result := false; 444 end; 445 if result then 446 begin 478 Result := False; 479 end; 480 if Result then begin 481 if Options and gfNoGamma = 0 then bmp.PixelFormat := pf24bit; 482 bmp.SetSize(Png.Width, Png.Height); 483 if (Png.RawImage.Description.Format = ricfGray) then begin 484 // LCL doesn't support 8-bit colors properly. Use 24-bit instead. 485 Bmp.PixelFormat := pf24bit; 486 CopyGray8BitTo24bitBitmap(Bmp, Png) 487 end else Bmp.Canvas.draw(0, 0, Png); 488 end; 489 Png.Free; 490 end else 491 if ExtractFileExt(Path) = '.bmp' then begin 492 try 493 bmp.LoadFromFile(Path); 494 except 495 Result := False; 496 end; 497 if Result then begin 447 498 if Options and gfNoGamma = 0 then 448 499 bmp.PixelFormat := pf24bit; 449 500 end 450 end; 451 if not result then 452 begin 501 end else 502 raise Exception.Create('Unsupported image file type ' + ExtractFileExt(Path)); 503 504 if not Result then begin 453 505 if Options and gfNoError = 0 then 454 506 Application.MessageBox(PChar(Format(Phrases.Lookup('FILENOTFOUND'), 455 507 [Path])), 'C-evo', 0); 456 exit; 457 end; 508 Exit; 509 end; 510 458 511 if (Options and gfNoGamma = 0) and (Gamma <> 100) then 459 begin 460 Bmp.BeginUpdate; 461 PixelPtr.Init(bmp); 462 for Y := 0 to Bmp.Height - 1 do begin 463 for X := 0 to Bmp.Width - 1 do begin 464 PixelPtr.Pixel^.B := GammaLUT[PixelPtr.Pixel^.B]; 465 PixelPtr.Pixel^.G := GammaLUT[PixelPtr.Pixel^.G]; 466 PixelPtr.Pixel^.R := GammaLUT[PixelPtr.Pixel^.R]; 467 PixelPtr.NextPixel; 468 end; 469 PixelPtr.NextLine; 470 end; 471 Bmp.EndUpdate; 472 end 512 ApplyGammaToBitmap(Bmp); 473 513 end; 474 514 … … 484 524 inc(i); 485 525 result := i; 486 if i = nGrExt then 487 begin 488 FileName := HomeDir + 'Graphics' + DirectorySeparator + Name + '.bmp'; 526 if i = nGrExt then begin 489 527 Source := TBitmap.Create; 490 try491 Source.LoadFromFile(FileName)492 except528 Source.PixelFormat := pf24bit; 529 FileName := HomeDir + 'Graphics' + DirectorySeparator + Name; 530 if not LoadGraphicFile(Source, FileName) then begin 493 531 Result := -1; 494 Application.MessageBox(PChar(Format(Phrases.Lookup('FILENOTFOUND'), 495 [FileName])), 'C-evo', 0); 496 exit; 532 Exit; 497 533 end; 498 534 … … 501 537 502 538 xmax := Source.Width - 1; // allows 4-byte access even for last pixel 503 if xmax > 970 then 504 xmax := 970; 539 if xmax > 970 then xmax := 970; 505 540 506 541 GrExt[nGrExt].Data := Source; … … 1396 1431 MainTextureAge := Age; 1397 1432 LoadGraphicFile(Image, HomeDir + 'Graphics' + DirectorySeparator + 'Texture' + 1398 IntToStr(Age + 1) , gfJPG);1433 IntToStr(Age + 1) + '.jpg'); 1399 1434 clBevelLight := Colors.Canvas.Pixels[clkAge0 + Age, cliBevelLight]; 1400 1435 clBevelShade := Colors.Canvas.Pixels[clkAge0 + Age, cliBevelShade]; … … 1442 1477 end; 1443 1478 1444 procedure TPixelPointer.Init(Bitmap: T Bitmap; BaseX: Integer = 0; BaseY: Integer = 0); inline;1479 procedure TPixelPointer.Init(Bitmap: TRasterImage; BaseX: Integer = 0; BaseY: Integer = 0); inline; 1445 1480 begin 1446 1481 BytesPerLine := Bitmap.RawImage.Description.BytesPerLine; … … 1571 1606 1572 1607 nGrExt := 0; 1573 HGrSystem := LoadGraphicSet('System'); 1574 HGrSystem2 := LoadGraphicSet('System2'); 1575 Templates := TBitmap.create; 1576 LoadGraphicFile(Templates, HomeDir + 'Graphics' + DirectorySeparator + 'Templates', gfNoGamma); 1608 HGrSystem := LoadGraphicSet('System.png'); 1609 HGrSystem2 := LoadGraphicSet('System2.png'); 1610 Templates := TBitmap.Create; 1577 1611 Templates.PixelFormat := pf24bit; 1578 Colors := TBitmap.create; 1579 LoadGraphicFile(Colors, HomeDir + 'Graphics' + DirectorySeparator + 'Colors'); 1580 Paper := TBitmap.create; 1581 LoadGraphicFile(Paper, HomeDir + 'Graphics' + DirectorySeparator + 'Paper', gfJPG); 1582 BigImp := TBitmap.create; 1583 LoadGraphicFile(BigImp, HomeDir + 'Graphics' + DirectorySeparator + 'Icons'); 1584 MainTexture.Image := TBitmap.create; 1612 LoadGraphicFile(Templates, HomeDir + 'Graphics' + DirectorySeparator + 'Templates.png', gfNoGamma); 1613 Colors := TBitmap.Create; 1614 Colors.PixelFormat := pf24bit; 1615 LoadGraphicFile(Colors, HomeDir + 'Graphics' + DirectorySeparator + 'Colors.png'); 1616 Paper := TBitmap.Create; 1617 Paper.PixelFormat := pf24bit; 1618 LoadGraphicFile(Paper, HomeDir + 'Graphics' + DirectorySeparator + 'Paper.jpg'); 1619 BigImp := TBitmap.Create; 1620 BigImp.PixelFormat := pf24bit; 1621 LoadGraphicFile(BigImp, HomeDir + 'Graphics' + DirectorySeparator + 'Icons.png'); 1622 MainTexture.Image := TBitmap.Create; 1585 1623 MainTextureAge := -2; 1586 1624 ClickFrameColor := GrExt[HGrSystem].Data.Canvas.Pixels[187, 175]; 1587 InitOrnamentDone := false;1588 GenerateNames := true;1625 InitOrnamentDone := False; 1626 GenerateNames := True; 1589 1627 end; 1590 1628
Note:
See TracChangeset
for help on using the changeset viewer.