-
Apr 6th, 2015, 09:06 PM
#1
VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Whilst cairo is known as a VectorGraphics-Library - it supports fast Blending-Operators
on its Pixel-Surfaces (aka ImageSurfaces) - and most wrappers around this library will
offer (in addition to cairos blending-ops) a few additional Pixel-Massaging-Methods.
The vbRichClient has 6 of that category already implemented:
- cCairo.PreMultiplyAlpha
- cCairo.DeMultiplyAlpha
- cCairoSurface.FastBlur
- cCairoSurface.GaussianBlur
- cCairoSurface.Sharpen
- cCairoSurface.AdjustColors (Brightness, Contrast, Gamma - all in one routine)
Now, there's certainly much more pixel-algorithms out there in the wild -
but the above few are what I restricted myself to, since they are often needed.
To accomodate those who want to perform their own PixelOps on those Surfaces, I've choosen
to make pixel-access as easy as possible - and so there exist two Array-Binding-Methods:
- cCairoSurface.BindToArray(ByteArray) ... and its companion .ReleaseArray ByteArray
- cCairoSurface.BindToArrayLong(LongArray) ... and its companion .ReleaseArrayLong LongArray
This is done without copying any Data - I guess the underlying SafeArray-technique is quite
wellknown in the meantime - and the Arrays in question need to be dynamic and uninitialized ones.
Well, that said - let's look at what the Demo has to offer:
Edge-Detection is a wide field - and I decided not to implement "the whole bunch of algos for comparison",
instead I concentrated on a very simple one (the "Roberts-Cross") - with focus on performance.
Since the algorithm is so simple (only using a small 2x2 Kernel), it was quite easy to avoid an
"inner Kernel-Loop" - and since the Formulas were not all that complex in this case too, coming
up with some Lookup-Tables for them was also relative easy to accomplish.
I've tuned it a bit though:
Instead of a SquareRoot on the "squared differences", I found that a logarithmic scaling produced
somewhat nicer results - and since the kernel is so small (compared to Sobel, Prewitt & Co.), the
algo captures fine details quite well, but tends to be "noisy" - so, a slight (and fast) PreBlurring was
added into the processing-queue, to remedy that.
For comparison (direct links instead of the forums img-tag, to get "the real image" -
and to easier compare - after loading them all - by just clicking between Browser-Tabs):
https://softwarebydefault.files.word..._grayscale.jpg
https://softwarebydefault.files.word..._grayscale.jpg
http://vbRichClient.com/Downloads/Lo...ithPreBlur.png
The last link of the above three, was generated with the Demo.
Performancewise, the Algo (including the steps: PreBlur, GreyScaling, LogarithmicRoberts, GammaCorrection, Sharpen)
takes in Sum only about 20msec total when native compiled (performing all steps on a 800x600 TrueColor-Image).
The Demo includes a few Demo-Images - here some ScreenShots:
Monarch-Original-Image:
Monarch-EdgeDetected and in ColorMode (algo performed on each color-channel separately).
The GreyScale-Result-Link I've posted already further above...
And another Result of one of the Demo-Images in Color-Mode:
Here's the Source-Zip:
EdgeDetection.zip
Have fun,
Olaf
Last edited by Schmidt; Apr 8th, 2015 at 10:09 AM.
-
Feb 17th, 2024, 11:51 AM
#2
Hyperactive Member
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Last edited by tmighty2; Mar 18th, 2024 at 05:10 PM.
-
Feb 17th, 2024, 12:31 PM
#3
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Something happened yesterday that broke all attachments hosted on this forum (including images and archives).
-
Feb 17th, 2024, 05:23 PM
#4
Hyperactive Member
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Last edited by tmighty2; Mar 18th, 2024 at 05:10 PM.
-
Feb 17th, 2024, 05:34 PM
#5
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
I do hope they have a backup to restore, otherwise it would be a huge loss for sure.
-
Feb 18th, 2024, 01:33 AM
#6
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Have just looked at these downloaded Files now with a Hex-Editor - and at least all the Zip-Downloads are now prefixed by an automatically (WebServer-)applied "Google-TagManager-Script", which precedes the normal "PK"-zip header, looking like this: Probably caused by an over-eager PHP-Admin, who applied such Google-Tagging not only to *.html-Files, but to *all* File-Mime-Types. Olaf
Last edited by Schmidt; Feb 18th, 2024 at 01:39 AM.
-
Feb 18th, 2024, 11:56 AM
#7
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
It's worse than initially thought. Files are truncated, presumably at the original size. Just removing the added data isn't enough to fix these files. I've made a separate post about this already in forum feedback.
This could be bad.
-
Feb 18th, 2024, 12:16 PM
#8
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Leisure Suit Larry designer Al Lowe put it best in his famous catchphrase: "save early, save often!".
-
Feb 18th, 2024, 12:27 PM
#9
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Automated tools don't work well with VBulletin for things you need to be logged in to grab. Unfortunately I don't have a backup of this site. Internet Archive is borderline useless even for the publicly visible stuff; doesn't crawl as logged in.
I've suggested before we need backups in the community. Just dump the DB, exclude the PM tables and other private stuff.
-
Feb 18th, 2024, 12:54 PM
#10
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
It shouldn't be rocket science even for an automated tool not to touch binary files. This is what you get when you outsource on Fiverr!
-
Feb 18th, 2024, 01:12 PM
#11
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Originally Posted by fafalone
I've suggested before we need backups in the community. Just dump the DB, exclude the PM tables and other private stuff.
Every webhosting company has automated backups, it's just a matter of how often they run them.
-
Feb 18th, 2024, 03:08 PM
#12
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
I asked if there are backups, nobody answered so far, but I'm afraid that probably nobody even knows that.
-
Feb 18th, 2024, 06:21 PM
#13
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Originally Posted by fafalone
It's worse than initially thought. Files are truncated, presumably at the original size. Just removing the added data isn't enough to fix these files. I've made a separate post about this already in forum feedback.
This could be bad.
It could be, but it looks more like the problem is with the building of the response. As Olaf mentioned (with his nice bit of sleuthing), the server is probably adding the GTM crap to responses where it shouldn't be added. So a 512,000B ZIP file would result in a Content-Length: 512000 HTTP header - but the server is responding with X bytes of GTM JS code, and then 512000 - (GTM Content-Length) of ZIP byte data. I'd be very surprised if they prepended the GTM code to all of their stored binary data, but stranger choices have been made in computing history.
Last edited by jpbro; Feb 18th, 2024 at 06:24 PM.
-
Feb 18th, 2024, 08:00 PM
#14
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Makes sense, hope you're right. My knowledge of web site admin is ancient; back in my day we did prepend things like SEO to the binary html resources. But your explanation makes more sense with the truncation.
-
Feb 18th, 2024, 08:14 PM
#15
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
So basically files on disk are intact? They get changed only when being downloaded?
-
Feb 18th, 2024, 08:29 PM
#16
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Originally Posted by fafalone
Makes sense, hope you're right. My knowledge of web site admin is ancient; back in my day we did prepend things like SEO to the binary html resources. But your explanation makes more sense with the truncation.
I hope so too, it would be a real loss. I'm cautiously optimistic that the binary ZIPs are fine as it would be a really weird decision to modify them for almost any reason IMO. Maybe to stuff a vbforums.com advertisement text file in all of them or something? I've seen those kinds of files in other sites packaged ZIPs before...it would be verging on suicidal to make any modifications and not make a full backup first though, as that would at least give you a chance to roll back to pre-modified copies.
-
Feb 18th, 2024, 08:35 PM
#17
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Originally Posted by VanGoghGaming
So basically files on disk are intact?
That's the big question. The second question is if they have a backup.
The third question would be, but I expect it is not needed, if anybody on Earth has a backup of the site.
-
Feb 18th, 2024, 08:40 PM
#18
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Originally Posted by VanGoghGaming
So basically files on disk are intact? They get changed only when being downloaded?
Well there's no guarantee, they're OK, but it seems most plausible to me. When you ask vbforums.com for EdgeDetection.zip, it will look in its storage area and seethe ZIP file is 241,112 bytes long. When it builds the HTTP response to your request, it will build a header with a bunch of information about the response. Here's what I got back:
Code:
HTTP/2 200
content-type: application/zip
accept-ranges: bytes
cache-control: max-age=31536000, private
content-disposition: attachment; filename*=ISO-8859-1''EdgeDetection.zip
etag: "125421"
expires: Tue, 18 Feb 2025 01:31:05 GMT
last-modified: Tue, 07 Apr 2015 02:05:18 GMT
pragma:
server: Apache/2.4.29 (Ubuntu)
x-content-type-options: nosniff
x-permitted-cross-domain-policies: none
via: 1.1 varnish, 1.1 varnish
date: Mon, 19 Feb 2024 01:31:05 GMT
x-served-by: cache-chi-kigq8000034-CHI, cache-yyz4581-YYZ
x-cache: MISS, MISS
x-cache-hits: 0, 0
x-timer: S1708306265.317770,VS0,VE362
vary: User-Agent
strict-transport-security: max-age=31557600
content-length: 241112
X-Firefox-Spdy: h2
The important bit there is the content-length: 24112 line - that instructs your browser to expect exactly 241,112 bytes to be sent down the wire. vbforums then start sending the byte content and your browser stop looking for more data after receiving exactly 241,112 bytes and assumes that it now has the complete file. Normally a site should be sending only the byte data of the file, not any other data. The fact that we're first getting some Google tracking JS code (which would never be part of a ZIP file byte data (except maybe as part of a file within the archive) makes it look like a configuration error - someone has instructed to add the JS code to ALL responses, and not just responses where it might make sense to include it (e.g. HTML files).
The weird bit though, is that it is a code snippet that should be included within an HTML body, not as the leading text - so I don't understand how a mistake could be made that would prepend this to the binary data coming down the pipe...it shouldn't be being prepended to anything as far as I can tell.
Anyway, fingers crossed.
-
Feb 18th, 2024, 08:59 PM
#19
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
I wonder if it is possible to spoof the content-length and get more data from the client side... ? (to see if we can get the rest of the file)
-
Feb 18th, 2024, 09:12 PM
#20
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Originally Posted by Eduardo-
I wonder if it is possible to spoof the content-length and get more data from the client side... ? (to see if we can get the rest of the file)
I've been trying to do just that in case the server is actually sending the full data with the wrong content length, but the browser is chopping at the exact content length. ChatGPT gave me a few cURL and wget commands to try, but none produced a longer binary. StackOverflow had some promising sounding possibilities, but they all produce 0-byte files. I'll muck around a bit more to see if it's possible (perhaps some kind of raw TCP dump).
-
Feb 18th, 2024, 09:22 PM
#21
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Looks like netcat might be the ticket - it can slurp raw data over the network and won't stop until the connection is closed. Unfortunately vbforums.com returns nothing over Port 80/HTTP though, so naked netcat calls won't work. Tried OpenSSL for HTTPS support, and it connects OK but no data seems to be coming down the pipe...need to find the right magic incantation.
-
Feb 18th, 2024, 09:38 PM
#22
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Forgot that you need to be logged in to download attachments (and the referrer header probably needs to be set amongst others). Hoped that duping my browser request headers would work over openssl, but I'm still not getting any data back from vbforums.com. Hmmm...
-
Feb 18th, 2024, 09:40 PM
#23
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Originally Posted by jpbro
Forgot that you need to be logged in to download attachments
No, you don't need to be logged in.
-
Feb 18th, 2024, 09:55 PM
#24
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Originally Posted by Eduardo-
No, you don't need to be logged in.
Ah well, thought that might have been the issue, but either way it doesn't seem to matter as even copying the exact HTTP request header from a browser request that works 100% of the time, doesn't seem to be working through openssl with a successful connection and SSL handshake. Weird...
-
Feb 18th, 2024, 10:00 PM
#25
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
All I can say is that neither curl nor wget can write the attachment data to disk, and AFAIK they both honour the content-length header and error out if there's a mismatch. So that seems to imply that vbforums is sending too much data.
-
Feb 18th, 2024, 11:37 PM
#26
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
Anyway this is all way off-topic, sorry Olaf. Conversation has been moved to the OffTopic twinBasic Discord.
Mods, if you can please move the OT posts elsewhere once the fire(s) have been put out, that would be appreciated.
-
Mar 17th, 2024, 11:00 AM
#27
Hyperactive Member
-
Last edited by tmighty2; Mar 19th, 2024 at 08:10 PM.
-
Mar 26th, 2024, 03:24 PM
#28
Re: VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)
How to automatically crop an image, such as removing peripheral transparent pixels.Or cut according to the specified color as the background color
how to get rect info. The four coordinates of the valid image in the non-transparent area.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|