ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Checking for corrupt but open-able jpg file
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

Waheed

Kuwait
36 Posts

Posted - Mar 05 2019 :  09:02:45  Show Profile  Reply
I can load the included file in TImageEnView, but this image is corrupt.

My question is: how can I check if it is corrupt. I used this function to check but it didn't work,
Image1.IO.ParamsFromFile( fileName, True )

it returned true which means it is not corrupt.

(The compressed file contains the hi-res image that I want to check)

attach/Waheed/201935103644_072.zip
1262.92 KB

-----------------
3 Monitors
Windows 10
Delphi 2007
ImageEn v.8.3

w2m

USA
1990 Posts

Posted - Mar 05 2019 :  14:22:49  Show Profile  Reply
I you need to view the image you need to use Image1.IO.LoadFromFile.
Image1.IO.ParamsFromFile does not load the image... it only loads params.

Bill Miller
Adirondack Software & Graphics
Email: w2m@hughes.net
EBook: http://www.imageen.com/ebook/
Custom Commercial ImageEn Development
Go to Top of Page

Waheed

Kuwait
36 Posts

Posted - Mar 05 2019 :  15:05:05  Show Profile  Reply
I am able to view the image. But as you can see it is corrupted. How can I check if it corrupted?
I'm talking about hundreds of files. I don't want to view only to check, is there a function that can do it?

-----------------
3 Monitors
Windows 10
Delphi 2007
ImageEn v.8.3
Go to Top of Page

xequte

38616 Posts

Posted - Mar 05 2019 :  15:38:11  Show Profile  Reply
Hi Waheed

Unfortunately, corruption by its very nature is unpredictable, so testing it for it is not easy.

For example, ParamsFromFile may fail if the corruption is so bad that the header cannot be read, otherwise it will return true.

LoadFromFile may fail if the corruption makes the image unreadable, but generally corrupted image data does not look different (to a computer) from regular image data and so the image loads OK, but a human realizes the image is incorrect.

In your test image, the image data is truncated, but because JPEG does not include a checksum to make it clear that data has been lost, all apps will load it without error.



Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Waheed

Kuwait
36 Posts

Posted - Mar 05 2019 :  21:37:52  Show Profile  Reply
How about if I test that there is a block of gray color in the image, usually at the end.
How can I do that?

-----------------
3 Monitors
Windows 10
Delphi 2007
ImageEn v.8.3
Go to Top of Page

xequte

38616 Posts

Posted - Mar 05 2019 :  23:46:09  Show Profile  Reply
Hi Waheed

It depends on the source of the images, of course, but usually with damaged JPEG images I don't see truncation (where you end up with a solid block of color), but corruption of some of the data (creating images where the colors and content is all messed up).

However if you are seeing a lot of this kind of truncation, you could test whether your images are largely one color:

https://www.imageen.com/help/TImageEnProc.GetDominantColor.html

e.g. more than 33% gray means it is corrupted.

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

Waheed

Kuwait
36 Posts

Posted - Mar 06 2019 :  06:26:46  Show Profile  Reply
Thanks Nigel for your feedback,
Here is my solution if any one interested:


// first check if the image file can be loaded
if not Image1.IO.ParamsFromFile( fileName, True ) then begin
   ShowMessage('File: '+fileName+' is corrupt. Please write it down.');
end else begin
   // the image can be loaded, but may be truncated
   Image1.IO.LoadFromFile(fileName);
   if chkAutoFit.Checked then
      Image1.Fit;
      Image1.SelectionBase := iesbBitmap;
      // select a lower right square of the image
      Image1.Select(Image1.fBitmap.Width - 100, Image1.fBitmap.Height - 100,
                    Image1.fBitmap.Width, Image1.fBitmap.Height);
      // save it in IEBitmap object
      Image1.CopySelectionToIEBitmap(bmp1);
      // get the dominant color which should be gray
      colorPercentage := ImageEnProc1.GetDominantColor(cl);
      // if 90% of the color is gray
      if (cl.r=128) and (cl.g=128) and (cl.b=128) and
         (colorPercentage>90.0) then begin
         ShowMessage('Bad image: '+fileName);
      end;
end;

You need TImageEnView, ImageEnProc
Maybe you can do everything non-visually. But this is just my solution.

Enjoy.

-----------------
3 Monitors
Windows 10
Delphi 2007
ImageEn v.8.3
Go to Top of Page

xequte

38616 Posts

Posted - Mar 06 2019 :  17:37:21  Show Profile  Reply
Hi Waheed

That looks good. You could probably improve the performance by iterating just through the scanlines. See the examples at:

https://www.imageen.com/help/TIEBitmap.ScanLine.html


Nigel
Xequte Software
www.imageen.com
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: