diff --git a/mapeditor.lfm b/mapeditor.lfm index 95d3187..e215f5c 100644 --- a/mapeditor.lfm +++ b/mapeditor.lfm @@ -3,7 +3,7 @@ object MapEdit: TMapEdit Height = 682 Top = 159 Width = 1130 - Caption = 'Map Edititor' + Caption = 'Map Editor' ClientHeight = 662 ClientWidth = 1130 Menu = MainMenu1 diff --git a/rmabout.pas b/rmabout.pas index 76341fc..8c29d7c 100644 --- a/rmabout.pas +++ b/rmabout.pas @@ -8,7 +8,7 @@ interface Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,lclintf; Const - ProgramName ='Raster Master v1.4 R75'; + ProgramName ='Raster Master v1.4 R77'; ProgramLicense = 'Released under MIT License'; type diff --git a/rmcolorvga.lfm b/rmcolorvga.lfm index 71091c3..babf737 100644 --- a/rmcolorvga.lfm +++ b/rmcolorvga.lfm @@ -12,7 +12,7 @@ object RMVgaColorDialog: TRMVgaColorDialog AnchorSideRight.Side = asrBottom Left = 13 Height = 120 - Top = -3 + Top = 8 Width = 474 ButtonHeight = 60 ButtonWidth = 60 diff --git a/rmcore.pas b/rmcore.pas index 1472755..7a39cca 100644 --- a/rmcore.pas +++ b/rmcore.pas @@ -559,6 +559,8 @@ function CanLoadPaletteFile(PaletteMode : integer) : boolean; function isAmigaPaletteMode(pm : integer) : boolean; function ColIndexToHoverInfo(colIndex : integer; pm : integer) : string; +procedure LoadPaletteBuf(var PalBuf : TRMPaletteBuf; PaletteMode : integer); +Procedure MakeRGBToEGACompatible(r,g,b : integer;var er,eg,eb : integer); implementation @@ -712,7 +714,6 @@ function RGBToEGAIndex(r,g,b : integer) : integer; var i : integer; begin - (* for i:=0 to 63 do begin if (EGADefault64[i].r = r) AND(EGADefault64[i].g = g) AND (EGADefault64[i].b = b) then @@ -721,9 +722,32 @@ function RGBToEGAIndex(r,g,b : integer) : integer; exit; end; end; - RGBToEGAIndex:=RGBToEGAIndex2(r,g,b); // not precise but we come up with a number - *) - RGBToEGAIndex:=RGBTOEGA(r,g,b); + RGBToEGAIndex:=RGBToEGA(EightToTwoBit(r),EightToTwoBit(g),EightToTwoBit(b)); + //RGBToEGAIndex:=RGBToEGAIndex2(r,g,b); // not precise but we come up with a number + + // RGBToEGAIndex:=RGBTOEGA(r,g,b); +end; + +Procedure MakeRGBToEGACompatible(r,g,b : integer;var er,eg,eb : integer); +var + i : integer; +begin + for i:=0 to 63 do + begin + if (EGADefault64[i].r = r) AND(EGADefault64[i].g = g) AND (EGADefault64[i].b = b) then + begin + er:=r; + eg:=g; + eb:=b; + exit; + end; + end; + er:=EightToTwoBit(r); + er:=TwoToEightBit(er); + eg:=EightToTwoBit(g); + eg:=TwoToEightBit(eg); + eb:=EightToTwoBit(b); + eb:=TwoToEightBit(eb); end; function RGBToEGAIndex2(r,g,b : integer) : integer; @@ -757,6 +781,35 @@ procedure GetDefaultRGBVGA(index : integer;var cr : TRMColorREc); cr:=VGADefault256[index]; end; + +procedure LoadPaletteBuf(var PalBuf : TRMPaletteBuf; PaletteMode : integer); +begin + if PaletteMode = PaletteModeMono then + begin + Move(MonoDefault,PalBuf,sizeof(MonoDefault)); + end + else if PaletteMode = PaletteModeCGA0 then + begin + Move(CGADefault0,PalBuf,sizeof(CGADefault0)); + end + else if PaletteMode = PaletteModeCGA1 then + begin + Move(CGADefault1,PalBuf,sizeof(CGADefault1)); + end + else if isAmigaPaletteMode(PaletteMode) then + begin + Move(AmigaDefault32,PalBuf,sizeof(AmigaDefault32)); + end + else if PaletteMode = PaletteModeEGA then + begin + Move(EGADefault16,PalBuf,sizeof(EGADefault16)); + end + else + begin + Move(VGADefault256,PalBuf,sizeof(VGADefault256)); + end; +end; + Constructor TRMPalette.create; begin ColorCount:=0; diff --git a/rmmain.pas b/rmmain.pas index 49d8a5b..a8d2dd2 100644 --- a/rmmain.pas +++ b/rmmain.pas @@ -1467,6 +1467,8 @@ procedure TRMMainForm.UpdatePaletteMenu; PaletteEGA.Checked:=false; PaletteVGA.Checked:=false; PaletteVGA256.Checked:=false; + PaletteXGA.Checked:=false; + PaletteXGA256.Checked:=false; PaletteAmiga.Checked:=false; PaletteAmiga2.Checked:=false; PaletteAmiga4.Checked:=false; @@ -1483,6 +1485,14 @@ procedure TRMMainForm.UpdatePaletteMenu; begin PaletteVGA.Checked:=true; end + else if pm = PaletteModeXGA256 then + begin + PaletteXGA256.Checked:=true; + end + else if pm = PaletteModeXGA then + begin + PaletteXGA.Checked:=true; + end else if pm = PaletteModeEGA then begin PaletteEGA.Checked:=true; @@ -2087,7 +2097,7 @@ procedure TRMMainForm.OpenFileClick(Sender: TObject); end else if (ext = '.LBM') or (ext = '.BBM') or (ext = '.ILBM') or (ext = '.IFF') then begin - if ReadILBM(OpenDialog1.FileName,x,y,x2,y2,lp) <> 0 then + if ReadILBM(OpenDialog1.FileName,x,y,x2,y2,lp,pm) <> 0 then begin ShowMessage('Error Opening IFF/ILBM file!'); exit; diff --git a/rwbmp.pas b/rwbmp.pas index 7f89179..96ab360 100644 --- a/rwbmp.pas +++ b/rwbmp.pas @@ -264,7 +264,6 @@ function GetMaxColor : integer; RMCoreBase.PutPixel(x+i-1,y+j-1,Uline[i-1]); end; end; - end else if myBmp.Bits=4 then begin @@ -331,7 +330,7 @@ function GetMaxColor : integer; If (lp=1) and (CanLoadPaletteFile(pm)) and (myColNum > 0) then //we do not load palette for mono and cga or if we are select/clip open mode pal=0 - begin + begin if pm=PaletteModeEGA then //if we are in ega palette mode we need to be able to remap rgb color ega64 palette begin //if not we skip setting that color for i:=0 to myColNum-1 do @@ -339,10 +338,8 @@ function GetMaxColor : integer; cr.r:=bmpPal[i].red; cr.g:=bmpPal[i].green; cr.b:=bmpPal[i].blue; - if RGBToEGAIndex(cr.r,cr.g,cr.b) > -1 then //if this returns an index to EGA color we can accept it - begin - RMCoreBase.Palette.SetColor(i,cr); - end; + MakeRGBToEGACompatible(cr.r,cr.g,cr.b,cr.r,cr.g,cr.b); + RMCoreBase.Palette.SetColor(i,cr); end; end else if isAmigaPaletteMode(pm) then diff --git a/rwgif.pas b/rwgif.pas index 83a362f..66eab61 100644 --- a/rwgif.pas +++ b/rwgif.pas @@ -121,13 +121,57 @@ function RGif(x,y,x2,y2,Lp,Pm : integer;filename : string) : integer; error:=LoadGif(filename); if (error = 0) and (Lp = 1) and (pm <>PaletteModeMono ) and (pm<>PaletteModeCGA0) and (pm<>PaletteModeCGA1) and (pm<> PaletteModeEGA) then begin - For i:=0 to myNumCols-1 do - begin - cr.r:=GifPalette[i*3]; - cr.g:=GifPalette[i*3+1]; - cr.b:=GifPalette[i*3+2]; - RMCoreBase.Palette.SetColor(i,cr); - end; + // For i:=0 to myNumCols-1 do + // begin + // cr.r:=GifPalette[i*3]; + // cr.g:=GifPalette[i*3+1]; + // cr.b:=GifPalette[i*3+2]; + // RMCoreBase.Palette.SetColor(i,cr); + // end; + + if pm=PaletteModeEGA then //if we are in ega palette mode we need to be able to remap rgb color ega64 palette + begin //if not we skip setting that color + for i:=0 to myNumCols-1 do + begin + cr.r:=GifPalette[i*3]; + cr.g:=GifPalette[i*3+1]; + cr.b:=GifPalette[i*3+2]; + MakeRGBToEGACompatible(cr.r,cr.g,cr.b,cr.r,cr.g,cr.b); + RMCoreBase.Palette.SetColor(i,cr); + end; + end + else if isAmigaPaletteMode(pm) then + begin + for i:=0 to myNumCols-1 do + begin + cr.r:=FourToEightBit(EightToFourBit(GifPalette[i*3])); + cr.g:=FourToEightBit(EightToFourBit(GifPalette[i*3+1])); + cr.b:=FourToEightBit(EightToFourBit(GifPalette[i*3+2])); + RMCoreBase.Palette.SetColor(i,cr); + end; + end + else if (pm=PaletteModeVGA) or (pm=PaletteModeVGA256) then + begin + for i:=0 to myNumCols-1 do + begin + cr.r:=SixToEightBit(EightToSixBit(GifPalette[i*3])); //we bitshift because if palette was saved when PaletteModeXga or PaletteModeXga256 + cr.g:=SixToEightBit(EightToSixBit(GifPalette[i*3+1])); //we will have invalid values + cr.b:=SixToEightBit(EightToSixBit(GifPalette[i*3+2])); + RMCoreBase.Palette.SetColor(i,cr); + // SetColor(i,cr); + end; + end + else if (pm=PaletteModeXGA) or (pm=PaletteModeXGA256) then + begin + for i:=0 to myNumCols-1 do + begin + cr.r:=GifPalette[i*3]; + cr.g:=GifPalette[i*3+1]; + cr.b:=GifPalette[i*3+2]; + RMCoreBase.Palette.SetColor(i,cr); + // SetColor(i,cr); + end; + end; end; RGif:=error; end; diff --git a/rwilbm.pas b/rwilbm.pas index 5ac5732..3671a3d 100644 --- a/rwilbm.pas +++ b/rwilbm.pas @@ -37,7 +37,7 @@ function WriteILBM(filename : string; x,y,x2,y2 : word;cmp :byte) : word; -function ReadILBM(filename : string; x,y,x2,y2,lp : integer) : word; +function ReadILBM(filename : string; x,y,x2,y2,lp,pm : integer) : word; Implementation @@ -310,7 +310,7 @@ function ReadILBM(filename : string; x,y,x2,y2,lp : integer) : word; end; //next i end; -Procedure ProcessCMAP(var F: File;cmapsize : longword; lp : integer); +Procedure ProcessCMAP(var F: File;cmapsize : longword; lp,pm : integer); var numColors,i : integer; cmap : ColorMapRec; @@ -322,10 +322,41 @@ function ReadILBM(filename : string; x,y,x2,y2,lp : integer) : word; BlockRead(F,cmap,sizeof(cmap)); if lp = 1 then begin - cr.r:=cmap.red; - cr.g:=cmap.green; - cr.b:=cmap.blue; - SetColor(i,cr); + // cr.r:=cmap.red; + // cr.g:=cmap.green; + // cr.b:=cmap.blue; + // SetColor(i,cr); + if pm=PaletteModeEGA then //if we are in ega palette mode we need to be able to remap rgb color ega64 palette + begin //if not we skip setting that color + cr.r:=cmap.red; + cr.g:=cmap.green; + cr.b:=cmap.blue; + MakeRGBToEGACompatible(cr.r,cr.g,cr.b,cr.r,cr.g,cr.b); + RMCoreBase.Palette.SetColor(i,cr); + end + else if isAmigaPaletteMode(pm) then + begin + cr.r:=FourToEightBit(EightToFourBit(cmap.red)); + cr.g:=FourToEightBit(EightToFourBit(cmap.green)); + cr.b:=FourToEightBit(EightToFourBit(cmap.blue)); + RMCoreBase.Palette.SetColor(i,cr); + end + else if (pm=PaletteModeVGA) or (pm=PaletteModeVGA256) then + begin + cr.r:=SixToEightBit(EightToSixBit(cmap.red)); //we bitshift because if palette was saved when PaletteModeXga or PaletteModeXga256 + cr.g:=SixToEightBit(EightToSixBit(cmap.green)); //we will have invalid values + cr.b:=SixToEightBit(EightToSixBit(cmap.blue)); + RMCoreBase.Palette.SetColor(i,cr); + // SetColor(i,cr); + end + else if (pm=PaletteModeXGA) or (pm=PaletteModeXGA256) then + begin + cr.r:=cmap.red; + cr.g:=cmap.green; + cr.b:=cmap.blue; + RMCoreBase.Palette.SetColor(i,cr); + // SetColor(i,cr); + end; end; // SetRGBPalette(i,cmap.red ,cmap.green ,cmap.blue ); //todo end; @@ -347,7 +378,7 @@ function ReadILBM(filename : string; x,y,x2,y2,lp : integer) : word; chunkname[chunknamelength]:=chr(newbyte); end; -Procedure Process(var F : File;x,y,x2,y2,lp : integer); +Procedure Process(var F : File;x,y,x2,y2,lp,pm : integer); var chunkname : chunknamerec; chunknamelength : integer; @@ -392,7 +423,7 @@ function ReadILBM(filename : string; x,y,x2,y2,lp : integer) : word; begin BlockRead(F,cmapsize,sizeof(cmapsize)); cmapsize:=LongToLE(cmapsize); - ProcessCMAP(F,cmapsize,lp); + ProcessCMAP(F,cmapsize,lp,pm); end else if (chunkname ='BODY') And FoundBMap then begin @@ -728,7 +759,7 @@ function WriteILBM(filename : string; x,y,x2,y2 : word;cmp :byte) : word; end; -function ReadILBM(filename : string; x,y,x2,y2,lp : integer) : word; +function ReadILBM(filename : string; x,y,x2,y2,lp,pm : integer) : word; var f : file; begin @@ -736,7 +767,7 @@ function ReadILBM(filename : string; x,y,x2,y2,lp : integer) : word; Assign(F,filename); {$I-} Reset(F,1); - Process(F,x,y,x2,y2,lp); + Process(F,x,y,x2,y2,lp,pm); Close(f); {$I+} ReadILBM:=IORESULT; diff --git a/rwpcx.pas b/rwpcx.pas index 0ed252e..618e250 100644 --- a/rwpcx.pas +++ b/rwpcx.pas @@ -664,10 +664,8 @@ function GetMaxColor : integer; cr.r:=PcxPal[i,0]; cr.g:=PcxPal[i,1]; cr.b:=PcxPal[i,2]; - if RGBToEGAIndex(cr.r,cr.g,cr.b) > -1 then //if this returns an index to EGA color we can accept it - begin - RMCoreBase.Palette.SetColor(i,cr); - end; + MakeRGBToEGACompatible(cr.r,cr.g,cr.b,cr.r,cr.g,cr.b); + RMCoreBase.Palette.SetColor(i,cr); end; end else if isAmigaPaletteMode(pm) then diff --git a/rwpng.pas b/rwpng.pas index 4c225b5..002bd1c 100644 --- a/rwpng.pas +++ b/rwpng.pas @@ -237,21 +237,21 @@ function FindPaletteIndex(r,g,b : integer;var BasePalette : TRMPaletteBuf;pm,nCo if pm = PaletteModeEGA then begin - r:=TwoToEightBit(EightToTwoBit(r)); - g:=TwoToEightBit(EightToTwoBit(g)); - b:=TwoToEightBit(EightToTwoBit(b)); + // r:=TwoToEightBit(EightToTwoBit(r)); + // g:=TwoToEightBit(EightToTwoBit(g)); + // b:=TwoToEightBit(EightToTwoBit(b)); ColorIndex:=FindNearColorMatch(BasePalette,nColors,r,g,b); if ColorIndex > 15 then ColorIndex:=ColorIndex Mod 15; //just picks a color base mod 15 - we need something end else if (pm=PaletteModeVGA) or (pm=paletteModeVGA256) then begin - + (* r:=SixToEightBit(EightToSixBit(r)); g:=SixToEightBit(EightToSixBit(g)); b:=SixToEightBit(EightToSixBit(b)); - + *) (* r:=TwoToEightBit(EightToTwoBit(r)); g:=TwoToEightBit(EightToTwoBit(g)); @@ -273,9 +273,9 @@ function FindPaletteIndex(r,g,b : integer;var BasePalette : TRMPaletteBuf;pm,nCo b:=FourToEightBit(EightToFourBit(b)); *) - r:=TwoToEightBit(EightToTwoBit(r)); - g:=TwoToEightBit(EightToTwoBit(g)); - b:=TwoToEightBit(EightToTwoBit(b)); + // r:=TwoToEightBit(EightToTwoBit(r)); + // g:=TwoToEightBit(EightToTwoBit(g)); + // b:=TwoToEightBit(EightToTwoBit(b)); ColorIndex:=FindNearColorMatch(BasePalette,nColors,r,g,b); //near performas findexact also if (ColorIndex > (nColors-1)) then ColorIndex:=ColorIndex Mod (nColors-1); @@ -326,22 +326,16 @@ procedure TEasyPNG.CreatePaletteUsingBasePalette(var BasePalette : TRMPaletteBuf if (PaletteMode = PaletteModeVGA256) or (PaletteMode = PaletteModeVGA) then begin - (* - r:=SixToEightBit(EightToSixBit(r)); - g:=SixToEightBit(EightToSixBit(g)); - b:=SixToEightBit(EightToSixBit(b)); - *) - For i:=0 to TopNColors-1 do begin - r:=TwoToEightBit(EightToTwoBit(TopPalette[i].r)); - g:=TwoToEightBit(EightToTwoBit(TopPalette[i].g)); - b:=TwoToEightBit(EightToTwoBit(TopPalette[i].b)); + r:=TopPalette[i].r; + g:=TopPalette[i].g; + b:=TopPalette[i].b; FindInPalette:=FindColorInPalette(BasePalette,palCounter,r,g,b); if (FindInPalette=-1) then //not found begin - if palCounter < (nColors-1) then + if palCounter < nColors then //was nColors-1 begin BasePalette[palCounter].r:=r; BasePalette[palCounter].g:=g; @@ -350,6 +344,13 @@ procedure TEasyPNG.CreatePaletteUsingBasePalette(var BasePalette : TRMPaletteBuf end; end; end; + + For i:=0 to TopNColors-1 do + begin + BasePalette[i].r:=SixToEightBit(EightToSixBit(BasePalette[i].r)); + BasePalette[i].g:=SixToEightBit(EightToSixBit(BasePalette[i].g)); + BasePalette[i].b:=SixToEightBit(EightToSixBit(BasePalette[i].b)); + end; end else if (PaletteMode = PaletteModeXGA256) or (PaletteMode = PaletteModeXGA) then begin @@ -362,7 +363,7 @@ procedure TEasyPNG.CreatePaletteUsingBasePalette(var BasePalette : TRMPaletteBuf FindInPalette:=FindColorInPalette(BasePalette,palCounter,r,g,b); if (FindInPalette=-1) then //not found begin - if palCounter < (nColors-1) then + if palCounter < nColors then //was nColors-1 begin BasePalette[palCounter].r:=r; BasePalette[palCounter].g:=g; @@ -376,42 +377,42 @@ procedure TEasyPNG.CreatePaletteUsingBasePalette(var BasePalette : TRMPaletteBuf begin For i:=0 to TopNColors-1 do begin - r:=TwoToEightBit(EightToTwoBit(TopPalette[i].r)); - g:=TwoToEightBit(EightToTwoBit(TopPalette[i].g)); - b:=TwoToEightBit(EightToTwoBit(TopPalette[i].b)); + r:=TopPalette[i].r; + g:=TopPalette[i].g; + b:=TopPalette[i].b; + FindInPalette:=FindColorInPalette(BasePalette,palCounter,r,g,b); if (FindInPalette=-1) then //not found or found in index higher than 15 begin - EGAIndex:=RGBToEGAIndex(r,g,b); - if EGAIndex < 64 then + if palCounter < nColors then begin - BasePalette[palCounter].r:=EGADefault64[EGAIndex].r; - BasePalette[palCounter].g:=EGADefault64[EGAIndex].g; - BasePalette[palCounter].b:=EGADefault64[EGAIndex].b; + BasePalette[palCounter].r:=r; + BasePalette[palCounter].g:=g; + BasePalette[palCounter].b:=b; inc(palCounter); end; end; end; + + For i:=0 to TopNColors-1 do + begin + MakeRGBToEGACompatible(BasePalette[i].r,BasePalette[i].g,BasePalette[i].b, + BasePalette[i].r,BasePalette[i].g,BasePalette[i].b); + end; end else if isAmigaPaletteMode(PaletteMode) then begin For i:=0 to TopNColors-1 do begin - (* - r:=FourToEightBit(EightToFourBit(r)); - g:=FourToEightBit(EightToFourBit(g)); - b:=FourToEightBit(EightToFourBit(b)); - *) - - r:=TwoToEightBit(EightToTwoBit(TopPalette[i].r)); // this gives better results than the above - g:=TwoToEightBit(EightToTwoBit(TopPalette[i].g)); - b:=TwoToEightBit(EightToTwoBit(TopPalette[i].b)); + r:=TopPalette[i].r; + g:=TopPalette[i].g; + b:=TopPalette[i].b; FindInPalette:=FindColorInPalette(BasePalette,palCounter,r,g,b); if (FindInPalette=-1) then begin - if palCounter < (nColors-1) then + if palCounter < nColors then //was nColors-1 begin BasePalette[palCounter].r:=r; BasePalette[palCounter].g:=g; @@ -420,6 +421,12 @@ procedure TEasyPNG.CreatePaletteUsingBasePalette(var BasePalette : TRMPaletteBuf end; end; end; + For i:=0 to TopNColors-1 do + begin + BasePalette[i].r:=FourToEightBit(EightToFourBit(BasePalette[i].r)); + BasePalette[i].g:=FourToEightBit(EightToFourBit(BasePalette[i].g)); + BasePalette[i].b:=FourToEightBit(EightToFourBit(BasePalette[i].b)); + end; end; end; @@ -460,7 +467,7 @@ procedure TEasyPNG.CopyImageToCore(var BasePalette : TRMPaletteBuf;PaletteMode,C procedure TEasyPNG.CopyPaletteToCore(NewPalette : TRMPaletteBuf;PaletteMode : integer); begin // pm:=RMCoreBAse.Palette.GetPaletteMode; - if (PaletteMode = PaletteModeVGA256) or (PaletteMode = PaletteModeVGA) or (PaletteMode = PaletteModeEGA) or (isAmigaPaletteMode(PaletteMode)) then + if (PaletteMode in [PaletteModeXGA256,PaletteModeXGA,PaletteModeVGA256,PaletteModeVGA,PaletteModeEGA]) or (isAmigaPaletteMode(PaletteMode)) then begin RMCoreBase.Palette.SetPalette(NewPalette); end; diff --git a/spriteimport.lfm b/spriteimport.lfm index 47cb95d..c71f56a 100644 --- a/spriteimport.lfm +++ b/spriteimport.lfm @@ -20,17 +20,17 @@ object SpriteImportForm: TSpriteImportForm ParentFont = False TabOrder = 0 object SpriteImage: TImage - Left = 19 - Height = 102 - Top = 13 - Width = 102 + Left = 8 + Height = 123 + Top = 8 + Width = 136 end object OpenSpriteSheet: TButton - Left = 147 + Left = 160 Height = 25 Top = 13 Width = 166 - Caption = 'Open Sprite Sheet' + Caption = 'Import Sprite Sheet' OnClick = OpenSpriteSheetClick ParentFont = False TabOrder = 0 @@ -66,9 +66,9 @@ object SpriteImportForm: TSpriteImportForm Text = '32 X 32' end object NewPaletteComboBox: TComboBox - Left = 550 + Left = 728 Height = 23 - Top = 15 + Top = 13 Width = 237 ItemHeight = 15 ItemIndex = 1 @@ -84,18 +84,26 @@ object SpriteImportForm: TSpriteImportForm Text = 'New Palette(From Entire Image)' end object PaletteComboBox: TComboBox - Left = 813 + Left = 552 Height = 23 Top = 13 Width = 134 ItemHeight = 15 - ItemIndex = 1 + ItemIndex = 4 Items.Strings = ( + 'Mono Palette' + 'CGA0 Palette' + 'CGA1 Palette' 'EGA Palette' 'VGA Palette' 'VGA Palette 256' 'XGA Palette' 'XGA Palette 256' + 'Amiga Palette 32' + 'Amiga Palette 16' + 'Amiga Palette 8' + 'Amiga Palette 4' + 'Amiga Palette 2' ) OnChange = PaletteComboBoxChange ParentFont = False @@ -113,6 +121,16 @@ object SpriteImportForm: TSpriteImportForm ParentColor = False ParentFont = False end + object ImportFromClipboard: TButton + Left = 160 + Height = 25 + Top = 48 + Width = 166 + Caption = 'Import From Clipboard' + OnClick = ImportFromClipboardClick + ParentFont = False + TabOrder = 4 + end end object ScrollBox1: TScrollBox AnchorSideLeft.Control = Owner diff --git a/spriteimport.pas b/spriteimport.pas index 66c7a33..74fff33 100644 --- a/spriteimport.pas +++ b/spriteimport.pas @@ -6,7 +6,7 @@ interface uses Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls, - StdCtrls, ExtDlgs,rwpng,rmcore,rmthumb; + StdCtrls, ExtDlgs,Clipbrd,LCLIntf,LCLType,rwpng,rmcore,rmthumb; type @@ -15,6 +15,7 @@ interface TSpriteImportForm = class(TForm) InfoLabel: TLabel; OpenDialog1: TOpenDialog; + ImportFromClipboard: TButton; SpriteSizeComboBox: TComboBox; NewPaletteComboBox: TComboBox; PaletteComboBox: TComboBox; @@ -26,6 +27,7 @@ TSpriteImportForm = class(TForm) ScrollBox1: TScrollBox; ZoomTrackBar: TTrackBar; procedure FormCreate(Sender: TObject); + procedure ImportFromClipboardClick(Sender: TObject); procedure NewPaletteComboBoxChange(Sender: TObject); procedure OpenSpriteSheetClick(Sender: TObject); procedure PaletteComboBoxChange(Sender: TObject); @@ -93,6 +95,28 @@ procedure TSpriteImportForm.OpenSpriteSheetClick(Sender: TObject); end; end; +procedure TSpriteImportForm.ImportFromClipboardClick(Sender: TObject); +var + pwidth,pheight : integer; +begin + if Clipboard.HasFormat(PredefinedClipboardFormat(pcfBitmap)) then + begin + lastx:=-1; + lasty:=-1; + + EasyPNG.Picture1.Bitmap.LoadFromClipboardFormat(PredefinedClipboardFormat(pcfBitmap)); + pwidth:=EasyPNG.Picture1.Width; + pheight:=EasyPNG.Picture1.Height; + SourceImage.AutoSize:=true; + SourceImage.Picture.Bitmap.SetSize(1,1); + SourceImage.Picture.Bitmap.SetSize(pwidth*ZoomSize,pheight*ZoomSize); + SourceImage.Canvas.CopyRect(Rect(0,0,pwidth*ZoomSize,pheight*ZoomSize),EasyPNG.Picture1.Bitmap.Canvas,Rect(0,0,pwidth,pheight)); + SourceImage.AutoSize:=false; + EasyPNG.BuildHashes(0,0,pwidth-1,pheight-1); //we only need the palette colors from the area we are loading - image can have more colors somewhere else + TopColorCount:=EasyPNG.BuildTopColors(TopColors); + end; +end; + procedure TSpriteImportForm.PaletteComboBoxChange(Sender: TObject); var pwidth,pheight : integer; @@ -108,6 +132,21 @@ procedure TSpriteImportForm.PaletteComboBoxChange(Sender: TObject); end; end; +procedure TSpriteImportForm.NewPaletteComboBoxChange(Sender: TObject); +var + pwidth,pheight : integer; +begin + NewPaletteFrom:=NewPaletteComboBox.ItemIndex; + if NewPaletteFrom = 1 then + begin + pwidth:=EasyPNG.Picture1.Width; + pheight:=EasyPNG.Picture1.Height; + + EasyPNG.BuildHashes(0,0,pwidth-1,pheight-1); //we only need the palette colors from the area we are loading - image can have more colors somewhere else + TopColorCount:=EasyPNG.BuildTopColors(TopColors); + end; +end; + procedure TSpriteImportForm.SourceImageClick(Sender: TObject); var @@ -125,33 +164,77 @@ procedure TSpriteImportForm.SourceImageClick(Sender: TObject); TempSprite:=TBitMap.Create; TempSprite.SetSize(SpriteWidth,SpriteHeight); ZoomToReal(LastX,LastY,ClipX,ClipY); + ColorCount:=16; + if NewPaletteMode = 0 then begin - PaletteMode:=PaletteModeEGA; + PaletteMode:=PaletteModeMono; + ColorCount:=2; end else if NewPaletteMode = 1 then begin - PaletteMode:=PaletteModeVGA; + PaletteMode:=PaletteModeCGA0; + ColorCount:=4; end else if NewPaletteMode = 2 then + begin + PaletteMode:=PaletteModeCGA1; + ColorCount:=4; + end + else if NewPaletteMode = 3 then + begin + PaletteMode:=PaletteModeEGA; + end + else if NewPaletteMode = 4 then + begin + PaletteMode:=PaletteModeVGA; + end + else if NewPaletteMode = 5 then begin PaletteMode:=PaletteModeVGA256; ColorCount:=256; end - else if NewPaletteMode = 3 then + else if NewPaletteMode = 6 then begin PaletteMode:=PaletteModeXGA; end - else if NewPaletteMode = 4 then + else if NewPaletteMode = 7 then begin PaletteMode:=PaletteModeXGA256; ColorCount:=256; + end + else if NewPaletteMode = 8 then + begin + PaletteMode:=PaletteModeAmiga32; + ColorCount:=32; + end + else if NewPaletteMode = 9 then + begin + PaletteMode:=PaletteModeAmiga16; + ColorCount:=16; + end + else if NewPaletteMode = 10 then + begin + PaletteMode:=PaletteModeAmiga8; + ColorCount:=8; + end + else if NewPaletteMode = 11 then + begin + PaletteMode:=PaletteModeAmiga4; + ColorCount:=4; + end + else if NewPaletteMode = 12 then + begin + PaletteMode:=PaletteModeAmiga2; + ColorCount:=2; end; + LoadPaletteBuf(OurPalette,PaletteMode); + ImageThumbBase.AddImportImage(SpriteWidth,SpriteHeight); ImageCount:=ImageThumbBase.GetCount; - OurPalette:=VGADefault256; + if NewPaletteFrom = 0 then //clip area begin @@ -317,24 +400,13 @@ procedure TSpriteImportForm.FormCreate(Sender: TObject); ClipWidth:=ZoomSize*SpriteWidth; ClipHeight:=ZoomSize*SpriteHeight; - NewPaletteFrom:=1; - NewPaletteMode:=1; + NewPaletteFrom:=1; //new palette from entire image + NewPaletteMode:=4; //vga end; -procedure TSpriteImportForm.NewPaletteComboBoxChange(Sender: TObject); -var - pwidth,pheight : integer; -begin - NewPaletteFrom:=NewPaletteComboBox.ItemIndex; - if NewPaletteFrom = 1 then - begin - pwidth:=EasyPNG.Picture1.Width; - pheight:=EasyPNG.Picture1.Height; - EasyPNG.BuildHashes(0,0,pwidth-1,pheight-1); //we only need the palette colors from the area we are loading - image can have more colors somewhere else - TopColorCount:=EasyPNG.BuildTopColors(TopColors); - end; -end; + + procedure TSpriteImportForm.ZoomToReal(zx,zy : integer;var rx,ry : integer); begin