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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Checking for corrupt but open-able jpg file

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Waheed Posted - Mar 05 2019 : 09:02:45
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
7   L A T E S T    R E P L I E S    (Newest First)
xequte Posted - Mar 06 2019 : 17:37:21
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
Waheed Posted - Mar 06 2019 : 06:26:46
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
xequte Posted - Mar 05 2019 : 23:46:09
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
Waheed Posted - Mar 05 2019 : 21:37:52
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
xequte Posted - Mar 05 2019 : 15:38:11
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
Waheed Posted - Mar 05 2019 : 15:05:05
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
w2m Posted - Mar 05 2019 : 14:22:49
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