Jump to content

lisichkin_alexander

Members
  • Content Count

    6
  • Joined

  • Last visited

Posts posted by lisichkin_alexander


  1. Thanks for the help.
    Yes, indeed the code:

    if (not a) or True then

    work.

    But why code:

    var
      b: boolean;
    begin
      b := False;
      if not b or True then
        writeln('b not or');
    end;

    work

    and code:

    var
      a: TplFilterValue<Boolean>;
    begin
      a := False;
      if not a or True then
        writeln('a not or');
    end;

    do not work?

    I assumed that I did not override for some operator for the record 😕

     

    P.S. I use Delphi 10.2, so I can not use operator assign

     


  2. Happy New Year, everyone!

     

    I create a class(record) with operator overloading.

    But I got an error: [dcc32 Error] E2015 Operator not applicable to this operand type

    Which operator did I forget to override?

     

    uses
      System.SysUtils, System.Generics.Collections, System.Rtti, System.TypInfo;
    
    type
      TplFilterValue<T> = record
        class operator Implicit(AValue: T): TplFilterValue<T>;
        class operator Implicit(AValue: TplFilterValue<T>): T;
        class operator LogicalNot(AValue: TplFilterValue<T>): Boolean;
        class operator LogicalOr(ALeft: TplFilterValue<T>; ARight: TplFilterValue<T>): Boolean;
        class operator LogicalAnd(ALeft: TplFilterValue<T>; ARight: TplFilterValue<T>): Boolean;
      private
        FValue: T;
        class function AsBoolean(AValue: TplFilterValue<T>): Boolean; static;
        procedure SetValue(AValue: T);
      public
        property Value: T read FValue write SetValue;
      end;
     
    procedure TplFilterValue<T>.SetValue(AValue: T);
    begin
      FValue := AValue;
    end;
    
    class operator TplFilterValue<T>.Implicit(AValue: T): TplFilterValue<T>;
    begin
      Result.FValue := AValue;
    end;
    
    class operator TplFilterValue<T>.Implicit(AValue: TplFilterValue<T>): T;
    begin
      Result := AValue.FValue;
    end;
    
    class function TplFilterValue<T>.AsBoolean(AValue: TplFilterValue<T>): Boolean;
    var
      LTypeInfo: PTypeInfo;
      LValue: TValue;
    begin
      LTypeInfo := System.TypeInfo(T);
      if LTypeInfo^.Name <> 'Boolean' then
        raise Exception.Create('Unsupported type operation');
      LValue := TValue.From<T>(AValue.FValue);
      Result := LValue.AsBoolean;
    end;
    
    class operator TplFilterValue<T>.LogicalNot(AValue: TplFilterValue<T>): Boolean;
    begin
      Result := not AsBoolean(AValue);
    end;
    
    class operator TplFilterValue<T>.LogicalOr(ALeft: TplFilterValue<T>; ARight: TplFilterValue<T>): Boolean;
    begin
      Result :=  AsBoolean(ALeft) or AsBoolean(ARight);
    end;
    
    class operator TplFilterValue<T>.LogicalAnd(ALeft: TplFilterValue<T>; ARight: TplFilterValue<T>): Boolean;
    begin
      Result :=  AsBoolean(ALeft) and AsBoolean(ARight);
    end;
    
    var
      a: TplFilterValue<Boolean>;
    begin
      try
        a := False;
        if not a then
          writeln('not a = True');
        if a or True then
          writeln('a or');
        if a and True then
          writeln('a and');
        if not(a) or True then   <<--- Error [dcc32 Error] E2015 Operator not applicable to this operand type
          writeln('a not or');
      except
        on E: Exception do
          Writeln(E.ClassName, ': ', E.Message);
      end;
    end.

     


  3. l have to explain why I started all this 🙂

     

    There is a Web service, written in Java, that we use to convert and compress images to Png.
    It was noticed that this service does not correctly convert colors for some Png images.
    I was given the task of building an algorithm that would determine that two pictures are identical.
    Moreover, with the condition, that colors are identical - the images themselves are considered the same.
    I came up with the idea of comparing the illumination histograms of two pictures.
    And this algorithm worked well, until I find some images with transparency - for which I did not correctly determine the color of some points.


    The question can be reformulated: how to get the R G B color of a point, taking into account transparency.


  4. Hello!

    It is required to calculate the illumination of a point in a TPNGImage object, taking into account transparency. I wrote the following algorithm:

    function GetBrightness(const AImage: TPNGImage; AX, AY: Integer): Integer;
    var
      LColor, LTransparentColor: TColor;
      r, g, b, alpha: Byte;
      tr, tg, tb: Byte;
      LDstAlpha: pByteArray;
    begin
      LColor := AImage.Pixels[AX, AY];
      r := Byte(LColor);
      g := Byte(LColor shr 8);
      b := Byte(LColor shr 16);
      if AImage.Transparent and (LColor <> 0) then
      begin
        if (AImage.Header.ColorType in [COLOR_RGBALPHA, COLOR_GRAYSCALEALPHA]) then
        begin
          LDstAlpha := AImage.AlphaScanline[AY];
          if Assigned(LDstAlpha) then
          begin
            alpha := LDstAlpha[AX];
            r := Byte(Round(r * alpha/255));
            g := Byte(Round(g * alpha/255));
            b := Byte(Round(b * alpha/255));
          end;
        end else
        if AImage.Header.ColorType = COLOR_PALETTE then
        begin
          LTransparentColor := AImage.TransparentColor;
          tr := Byte(LTransparentColor);
          tg := Byte(LTransparentColor shr 8);
          tb := Byte(LTransparentColor shr 16);
          r := Byte(Round(r * tr/255));
          g := Byte(Round(g * tg/255));
          b := Byte(Round(b * tb/255));
        end;
      end;
      Result := Round(0.3*r + 0.59*g + 0.11*b);
    end;

    Please analyze my algorithm for errors.

    P.S. Unfortunately, in my test base there are no images with TransparentColor - only with alpha channel.

    Alexander.

     


  5. I can make a few assumptions:
    1. A 32-bit application works with a database. and for some reason You need to process a large amount of information not on the server, but on the client and the amount of data exceeds 3GB of memory.
    2. You want to write a dll library for a 64-bit application
    (Extended stored procedure)

    3....

    This is only a 32 to 64 bit transition


  6. It’s not clear what you want to do, I can suggest using Windows API function

    CreateProcessWithLogonW =
        function(const lpUsername: PWideChar;
        const lpDomain: PWideChar; const lpPassword: PWideChar;
        dwLogonFlags: DWORD; const lpApplicationName: PWideChar;
        lpCommandLine: PWideChar; dwCreationFlags: DWORD;
        lpEnvironment: Pointer; const lpCurrentDirectory: PWideChar;
        lpStartupInfo: PStartupInfo;
        lpProcessInfo: PProcessInformation): Boolean; stdcall

×