Delphi Pages Forums

Delphi Pages Forums (http://www.delphipages.com/forum/index.php)
-   General (http://www.delphipages.com/forum/forumdisplay.php?f=2)
-   -   IsValidJPG no longer working (http://www.delphipages.com/forum/showthread.php?t=218688)

Zaaka 09-13-2019 02:15 AM

IsValidJPG no longer working
 
Hi all I have been using the following function to detect 'bad' jpg/jpeg images but it has suddenly stopped working, it is in a library that rarely gets altered. the error is the red line which states 'the left hand side can not be assigned to' like I said the code has not altered, can anybody help or have a better solution for detecting good/bad jpg's

Code:

function IsValidJPG(FileName: String): Boolean;
var
    H, W: Integer;
    Jpg: TJPEGImage;
    Bmp: TBitmap;
    F: File of Word;
    Head: Word;
    p: pInteger;
    pB: pByte;
    pE: Cardinal;
    pColor: Integer;
    Label fin;
begin
    Result := FALSE;

    if (FileExists(FileName))
    then begin
      AssignFile(F, FileName);
      try
        Reset(F);
        Read(F, Head);
      finally
        CloseFile(F);
      end;

      if (Head <> $D8FF) then exit;

      try
        Jpg := TJpegImage.Create;
        Bmp := TBitmap.Create;

        // The First check, does it load?
        jpg.LoadFromFile(FileName);

        // Yes, now draw it out to a BMP for manipulation
        H := Jpg.Height;
        W := Jpg.Width;
        Bmp.Height := H;
        Bmp.Width :=  W;
        Bmp.Canvas.Draw(0, 0, Jpg);

        // Grab the First line of the Image, in binary
        // if the color is invalid, the Image is bad.
        p := Bmp.ScanLine [H - 1];
        pColor := p^;
        if (pColor = $808080)
        then begin
          FreeAndNil(Jpg);
          FreeAndNil(Bmp);
          Result := FALSE;
          exit;
        end;

        // Now jump to the last scanline
        // Check every four dwords of last scanline for a suspect blue Value
        // It goes backwards through the last line of the image and checks to
        // see if the color is less than the constant $E1.
        // If it is, then result is changed from FALSE to TRUE and the routine
        // exits with IsValidJPEG returning TRUE. Otherwise, if all the pixels
        // in that line have a color greater than or equal too $E1 (suspect blue???),
        // then the result remains FALSE and IsValidJPEG returns false...
        pE := Cardinal(p) + Cardinal(H shr 1);
        Cardinal(pB) := Cardinal(p);
        while (Cardinal(pB) < pE)
        do begin
          if (pB^ < $E1)
          then begin
            Result := TRUE;
            Break;
          end
          else begin
            inc(pB);
            if (pB^ >=  $E1)
            then  begin
              inc(pB);
              if (pB^ >=  $E1)
              then begin
                Result := TRUE;
                Break;
              end;
              dec(pB);
            end;
            dec(pB);
          end;
          inc(pB, 16);
        end;
      finally
        FreeAndNil(Jpg);
        FreeAndNil(Bmp);
      end;
    end;
end;



All times are GMT. The time now is 06:22 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.