瀏覽代碼

Readme Tweak +Don't allow exceptions from StretchBmp, just return False.

Martijn Laan 7 年之前
父節點
當前提交
68b36e7385
共有 2 個文件被更改,包括 55 次插入52 次删除
  1. 51 48
      Components/Resample.pas
  2. 4 4
      README.md

+ 51 - 48
Components/Resample.pas

@@ -148,58 +148,61 @@ const
   NULL = {$IFDEF VER90}nil{$ELSE}0{$ENDIF};
   NULL = {$IFDEF VER90}nil{$ELSE}0{$ENDIF};
 begin
 begin
   Result := False;
   Result := False;
-  if (DstWidth <= 0) or (DstHeight <= 0) then Exit;
-  //High quality resampling makes sense only
-  //in True Color and High Color display modes.
-  if GetDeviceCaps(Canvas.Handle, BITSPIXEL) <= 8 then Exit;
-  SrcWidth  := SrcBitmap.Width;
-  SrcHeight := SrcBitmap.Height;
-  if (SrcWidth <= 0) or (SrcHeight <= 0) then Exit;
-  FillChar(BI, SizeOf(BI), 0);
-  BI.bmiHeader.biSize := SizeOf(BI.bmiHeader);
-  BI.bmiHeader.biWidth := SrcWidth;
-  BI.bmiHeader.biHeight := SrcHeight;
-  BI.bmiHeader.biPlanes := 1;
-  BI.bmiHeader.biCompression := BI_RGB;
-  if Is32bit then begin
-    BI.bmiHeader.biBitCount := 32;
-    PixelSize := 4;
-    Proc := PutPixel32P;
-  end else begin
-    BI.bmiHeader.biBitCount := 24;
-    PixelSize := 3;
-    Proc := PutPixel24;
-  end;
-  DstLineSize := (DstWidth * PixelSize + 3) and not 3;
-  SrcLineSize := (SrcWidth * PixelSize + 3) and not 3;
-  GetMem(tmpBits, SrcHeight * DstLineSize);
   try
   try
-    GetMem(SrcBits, SrcLineSize * SrcHeight);
-    try
-      if GetDIBits(Canvas.Handle, SrcBitmap.Handle,
-        0, SrcHeight, SrcBits, BI, DIB_RGB_COLORS) = 0 then Exit;
-      //Stretch horizontally
-      ResampleBits(DstWidth, SrcWidth, SrcBits, tmpBits,
-        PixelSize, SrcHeight, SrcLineSize, DstLineSize, Proc);
-    finally
-      FreeMem(SrcBits);
+    if (DstWidth <= 0) or (DstHeight <= 0) then Exit;
+    //High quality resampling makes sense only
+    //in True Color and High Color display modes.
+    if GetDeviceCaps(Canvas.Handle, BITSPIXEL) <= 8 then Exit;
+    SrcWidth  := SrcBitmap.Width;
+    SrcHeight := SrcBitmap.Height;
+    if (SrcWidth <= 0) or (SrcHeight <= 0) then Exit;
+    FillChar(BI, SizeOf(BI), 0);
+    BI.bmiHeader.biSize := SizeOf(BI.bmiHeader);
+    BI.bmiHeader.biWidth := SrcWidth;
+    BI.bmiHeader.biHeight := SrcHeight;
+    BI.bmiHeader.biPlanes := 1;
+    BI.bmiHeader.biCompression := BI_RGB;
+    if Is32bit then begin
+      BI.bmiHeader.biBitCount := 32;
+      PixelSize := 4;
+      Proc := PutPixel32P;
+    end else begin
+      BI.bmiHeader.biBitCount := 24;
+      PixelSize := 3;
+      Proc := PutPixel24;
     end;
     end;
-    BI.bmiHeader.biWidth := DstWidth;
-    BI.bmiHeader.biHeight := DstHeight;
-    DIB := CreateDIBSection(Canvas.Handle, BI, DIB_RGB_COLORS, DstBits, NULL, 0);
-    if DIB = 0 then Exit;
+    DstLineSize := (DstWidth * PixelSize + 3) and not 3;
+    SrcLineSize := (SrcWidth * PixelSize + 3) and not 3;
+    GetMem(tmpBits, SrcHeight * DstLineSize);
     try
     try
-      //Stretch vertically
-      ResampleBits(DstHeight, SrcHeight, tmpBits, DstBits,
-        DstLineSize, DstWidth, PixelSize, PixelSize, Proc);
-      DstBitmap.Handle := DIB;
-      Result := True;
-    except
-      DeleteObject(DIB);
-      raise;
+      GetMem(SrcBits, SrcLineSize * SrcHeight);
+      try
+        if GetDIBits(Canvas.Handle, SrcBitmap.Handle,
+          0, SrcHeight, SrcBits, BI, DIB_RGB_COLORS) = 0 then Exit;
+        //Stretch horizontally
+        ResampleBits(DstWidth, SrcWidth, SrcBits, tmpBits,
+          PixelSize, SrcHeight, SrcLineSize, DstLineSize, Proc);
+      finally
+        FreeMem(SrcBits);
+      end;
+      BI.bmiHeader.biWidth := DstWidth;
+      BI.bmiHeader.biHeight := DstHeight;
+      DIB := CreateDIBSection(Canvas.Handle, BI, DIB_RGB_COLORS, DstBits, NULL, 0);
+      if DIB = 0 then Exit;
+      try
+        //Stretch vertically
+        ResampleBits(DstHeight, SrcHeight, tmpBits, DstBits,
+          DstLineSize, DstWidth, PixelSize, PixelSize, Proc);
+        DstBitmap.Handle := DIB;
+        Result := True;
+      except
+        DeleteObject(DIB);
+        raise;
+      end;
+    finally
+      FreeMem(tmpBits);
     end;
     end;
-  finally
-    FreeMem(tmpBits);
+  except
   end;
   end;
 end;
 end;
 
 

+ 4 - 4
README.md

@@ -198,10 +198,10 @@ How do the projects link together?
   your installations with the new code, you'll need to copy the new EXE
   your installations with the new code, you'll need to copy the new EXE
   file(s) to the Setup Compiler directory under the extension .E32.
   file(s) to the Setup Compiler directory under the extension .E32.
 
 
-- When debugging the Setup project you should set UseSetupLdr=no in your
-  script, and copy the resulting setup-*.bin files to the source code
-  directory. This way you can simulate an actual installation while running
-  under the Delphi debugger.
+- When debugging the Setup project you should set UseSetupLdr=no and
+  OutputBaseFilename=setup in your script, and copy the resulting setup-*.bin
+  files to the source code directory. This way you can simulate an actual
+  installation while runningunder the Delphi debugger.
 
 
 - All of the forms in the Setup project, with the exception of Main.dfm, have
 - All of the forms in the Setup project, with the exception of Main.dfm, have
   Scaled set to False. This is because they dynamically scale themselves at
   Scaled set to False. This is because they dynamically scale themselves at