From: <tw...@us...> - 2020-11-14 16:58:23
|
Revision: 3377 http://sourceforge.net/p/gexperts/code/3377 Author: twm Date: 2020-11-14 16:58:21 +0000 (Sat, 14 Nov 2020) Log Message: ----------- updated to latest version from OSDN Modified Paths: -------------- trunk/ExternalSource/dzlib/u_dzConvertUtils.pas trunk/ExternalSource/dzlib/u_dzFileStreams.pas trunk/ExternalSource/dzlib/u_dzGraphicsUtils.pas trunk/ExternalSource/dzlib/u_dzOsUtils.pas trunk/ExternalSource/dzlib/u_dzTypes.pas trunk/ExternalSource/dzlib/u_dzVclUtils.pas Modified: trunk/ExternalSource/dzlib/u_dzConvertUtils.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzConvertUtils.pas 2020-11-14 14:37:55 UTC (rev 3376) +++ trunk/ExternalSource/dzlib/u_dzConvertUtils.pas 2020-11-14 16:58:21 UTC (rev 3377) @@ -921,7 +921,6 @@ end; {$IFNDEF Win64} - function TryStr2Float(const _s: string; out _flt: Extended; _DecSeparator: Char = '.'): Boolean; var {$IF Declared(TFormatSettings)} Modified: trunk/ExternalSource/dzlib/u_dzFileStreams.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzFileStreams.pas 2020-11-14 14:37:55 UTC (rev 3376) +++ trunk/ExternalSource/dzlib/u_dzFileStreams.pas 2020-11-14 16:58:21 UTC (rev 3377) @@ -132,7 +132,10 @@ /// exception message. /// NOTE: TStream.WriteBuffer is *not* virtual, so you must declare the object as /// TdzFile rather TStream for this method to be called. </summary. - procedure WriteBuffer(const _Buffer; _Count: LongInt); + procedure WriteBuffer(const _Buffer; _Count: NativeInt); overload; +{$IF SizeOf(LongInt) <> SizeOf(NativeInt)} + procedure WriteBuffer(const _Buffer; _Count: LongInt); overload; +{$IFEND} ///<summary> Closes the file and sets the handle to INVALID_HANDLE_VALUE </summary> procedure Close; ///<summary> returns true if Position = Size </summary> @@ -291,7 +294,7 @@ Stream := TdzFile.Create(_fn); try Stream.OpenCreateWriteNoSharing; - Stream.WriteBuffer(_Buffer, _Size); + Stream.WriteBuffer(_Buffer, NativeInt(_Size)); finally FreeAndNil(Stream); end; @@ -417,7 +420,7 @@ FFileFlags := _FileFlags; end; -procedure TdzFile.WriteBuffer(const _Buffer; _Count: Integer); +procedure TdzFile.WriteBuffer(const _Buffer; _Count: NativeInt); var Written: Integer; LastError: LongWord; @@ -436,6 +439,14 @@ end; end; +{$IF SizeOf(LongInt) <> SizeOf(NativeInt)} + +procedure TdzFile.WriteBuffer(const _Buffer; _Count: LongInt); +begin + WriteBuffer(_Buffer, NativeInt(_Count)); +end; +{$IFEND} + function TdzFile.Eof: Boolean; begin Result := Position = Size; Modified: trunk/ExternalSource/dzlib/u_dzGraphicsUtils.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzGraphicsUtils.pas 2020-11-14 14:37:55 UTC (rev 3376) +++ trunk/ExternalSource/dzlib/u_dzGraphicsUtils.pas 2020-11-14 16:58:21 UTC (rev 3377) @@ -559,7 +559,7 @@ /// Calculate the histogram for a bitmap with PixelFormat = pf24 for the given channel /// @param bmp is the bitmap to process /// @param Channel determines how to calculate the brightness -/// @returns a TUInt32Array256 containing the histogram </summary> +/// @returns a TUInt64Array256 containing the histogram </summary> function TBitmap24_GetHistogram(_bmp: TBitmap; _Channel: TRgbBrightnessChannelEnum): TUInt64Array256; ///<summary> /// Calculate the histograms for red, green and blue for a bitmap with PixelFormat = pf24 @@ -579,6 +579,8 @@ procedure TBitmap24_GetHistograms(_bmp: TBitmap; _BrightnessChannel: TRgbBrightnessChannelEnum; out _Red, _Green, _Blue, _Brightness: TUInt64Array256); overload; +function TBitmap8_GetHistogram(_bmp: TBitmap): TUInt64Array256; overload; + type // Note: The bitmap is stored upside down, so the y coordinates are reversed! TPixel24FilterCallback = procedure(_x, _y: Integer; var _Pixel: TdzRgbTriple) of object; @@ -3264,6 +3266,43 @@ Result := RainbowColor((_Hue - _MinHue) / (_MaxHue - _MinHue + 1)); end; +function TBitmap8_GetHistogram(_bmp: TBitmap): TUInt64Array256; overload; +const + BytesPerPixel = 1; +var + w: Integer; + h: Integer; + x: Integer; + y: Integer; + ScanLine: PByte; + Pixel: PByte; + BytesPerLine: Integer; +begin + for x := Low(Result) to High(Result) do + Result[x] := 0; + + h := _bmp.Height; + if h = 0 then begin + Exit; //==> + end; + + w := _bmp.Width; + + BytesPerLine := ((w * 8 * BytesPerPixel + 31) and not 31) div 8; + Assert(BytesPerLine = Graphics.BytesPerScanline(w, BytesPerPixel * 8, 32)); + + ScanLine := _bmp.ScanLine[0]; + for y := 0 to h - 1 do begin + Assert(ScanLine = _bmp.ScanLine[y]); + Pixel := ScanLine; + for x := 0 to w - 1 do begin + Inc(Result[Pixel^]); + Inc(Pixel, BytesPerPixel); + end; + Dec(ScanLine, BytesPerLine); + end; +end; + function TBitmap24_GetHistogram(_bmp: TBitmap; _Channel: TRgbBrightnessChannelEnum): TUInt64Array256; overload; const BytesPerPixel = SizeOf(TdzRgbTriple); Modified: trunk/ExternalSource/dzlib/u_dzOsUtils.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzOsUtils.pas 2020-11-14 14:37:55 UTC (rev 3376) +++ trunk/ExternalSource/dzlib/u_dzOsUtils.pas 2020-11-14 16:58:21 UTC (rev 3377) @@ -9,11 +9,15 @@ Windows, SysUtils, Classes, - u_dzTranslator; + u_dzTranslator, + u_dzTypes; type - EOsFunc = class(Exception); + EOsFunc = class(EdzException); EOFNoFileinfo = class(EOsFunc); + EPowerRequestFailed = class(EOsFunc) + ErrorCode: Word; + end; ///<summary> /// Determines the computername @@ -217,6 +221,7 @@ /// @returns an interface which, when released, calls PowerClearRequest /// See also BlockScreenSaver </summary> function SetPowerRequest(const _Reason: WideString; _RequestType: TPowerRequestType): IInterface; +function TrySetPowerRequest(const _Reason: WideString; _RequestType: TPowerRequestType; out _Request: IInterface): Boolean; ///<summary> /// Uses the Windows API PowerCreateRequest and PowerSetRequest (Windows 7 and later) to @@ -916,6 +921,9 @@ end; constructor TPowerRequest.Create(const _Reason: WideString; _RequestType: TPowerRequestType); +var + LastError: DWORD; + Error: EPowerRequestFailed; begin inherited Create; FDllHandle := SafeLoadLibrary(kernel32); @@ -931,10 +939,31 @@ FContext.Version := POWER_REQUEST_CONTEXT_VERSION; FContext.Flags := POWER_REQUEST_CONTEXT_SIMPLE_STRING; FContext.SimpleReasonString := @FReason[0]; + FRequestHandle := PowerCreateRequest(@FContext); - if FRequestHandle = INVALID_HANDLE_VALUE then - RaiseLastOSError; - Win32Check(PowerSetRequest(FRequestHandle, _RequestType)); + if FRequestHandle = INVALID_HANDLE_VALUE then begin + LastError := GetLastError; + if LastError <> 0 then + Error := EPowerRequestFailed.CreateFmt(_('PowerCreateRequest failed with error code %d. (%s)'), + [LastError, SysErrorMessage(LastError)]) + else + Error := EPowerRequestFailed.CreateFmt(_('PowerCreateRequest failed with error code %d. (unknown error)'), + [LastError]); + Error.ErrorCode := LastError; + raise Error; + end; + + if not PowerSetRequest(FRequestHandle, _RequestType) then begin + LastError := GetLastError; + if LastError <> 0 then + Error := EPowerRequestFailed.CreateFmt(_('PowerCreateRequest failed with error code %d. (%s)'), + [LastError, SysErrorMessage(LastError)]) + else + Error := EPowerRequestFailed.CreateFmt(_('PowerCreateRequest failed with error code %d. (unknown error)'), + [LastError]); + Error.ErrorCode := LastError; + raise Error; + end; end; destructor TPowerRequest.Destroy; @@ -956,6 +985,17 @@ Result := TPowerRequest.Create(_Reason, _RequestType); end; +function TrySetPowerRequest(const _Reason: WideString; _RequestType: TPowerRequestType; out _Request: IInterface): Boolean; +begin + try + _Request := SetPowerRequest(_Reason, _RequestType); + Result := True; + except + Result := False; + _Request := nil; + end; +end; + function CharToOem(const _s: string): AnsiString; begin SetLength(Result, Length(_s)); Modified: trunk/ExternalSource/dzlib/u_dzTypes.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzTypes.pas 2020-11-14 14:37:55 UTC (rev 3376) +++ trunk/ExternalSource/dzlib/u_dzTypes.pas 2020-11-14 16:58:21 UTC (rev 3377) @@ -63,6 +63,13 @@ {$IF not declared(NativeUInt)} NativeUInt = UInt32; {$IFEND} +{$IF not declared(UIntPtr)} +{$IF sizeOf(Pointer)=4} + UIntPtr = UInt32; +{$ELSE} + UIntPtr = UInt64; +{$IFEND} +{$IFEND} type EdzException = class(Exception) Modified: trunk/ExternalSource/dzlib/u_dzVclUtils.pas =================================================================== --- trunk/ExternalSource/dzlib/u_dzVclUtils.pas 2020-11-14 14:37:55 UTC (rev 3376) +++ trunk/ExternalSource/dzlib/u_dzVclUtils.pas 2020-11-14 16:58:21 UTC (rev 3377) @@ -6811,7 +6811,7 @@ ZeroMemory(@Info, SizeOf(Info)); Info.cbSize := SizeOf(Info); - // we need to typecast this because we pass a pointer ot TMonitorInfoEx rather than TMonitorInfo + // we need to typecast this because we pass a pointer to TMonitorInfoEx rather than TMonitorInfo if not GetMonitorInfo(hm, PMonitorInfo(@Info)) then RaiseLastOSError; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |