What code did you write today?

Page may contain affiliate links. Please see terms for details.

Shut Up Legs

Down Under Member
Yes, I know: another one of those "What xyz did you do today?" threads. :laugh: Sometimes, though, I feel the need to share what software code I've written recently with other people (and hopefully those who understand what on earth I'm babbling on about will reply with something interesting.

Today, it's reading JPEG metadata:

Yesterday, I was trying to write some code (in a Windows C++ executable) to read just enough of a JPEG image file to get the values of its width and height attributes, i.e. its resolution metadata. The motivation for this is that I'm writing an image-displaying screen saver for Windows, and I wanted to add a feature where the user could filter the images to be displayed by minimum width and/or height in pixels, so that the screen saver doesn't do annoying things such as display tiny little thumbnail images (like the Windows image display screen saver does, and this is one of the reasons I started writing my own).
I'm already using the FreeImage image-processing library to load the images, then OpenGL to display them on the virtual screen saver window canvas, but the main drawback of FreeImage is that to know the resolution of the image, you have to load the entire file, and so I was searching for a way to get the resolution by scanning through as few bytes of the file as possible.

Simple enough, I thought: there's a table somewhere near the start of the file with various parameters stored in it, right? Wrong! :headshake:


A few JPEG standards later:
JPEG (JFIF): http://www.w3.org/Graphics/JPEG/
JPEG (EXIF): www.cipa.jp/std/documents/e/DC-008-2012_E.pdf
I know a little bit more about where the width and height are stored, but I'm still working on my final solution for JPEGs. Then, I'll have to do the same for a few other commonly-occurring image formats in Windows, e.g. BMP, GIF and PNG.

For some JPEGs, the width and height are available in the SOF0 (Start Of Frame 0) header, and are easily enough read. But for others encoded using the EXIF standard (see below), accessing these 2 values involves reading the EXIF header, following pointers to the offset of other headers, etc. and isn't so straightforward.
One thing I plan to do, though, is look at the source code of FreeImage (and similar libraries), to get hints on what kind of code I need to write for my size-filter. This may speed things up a bit.
As a typical example: I have a roughly 1.5MB JPEG image file for which I was getting incorrect width and height values by just reading the SOF0 header: it was giving me 160x120 instead of the actual 4000x3000 (i.e. it's a 12Mpixel JPEG). So for this one, which happens to be an EXIF-encoded JPEG, I need to use the more complex approach, and hopefully will have to scan through no more than about 2KB or so, before finding the attributes I need.

Once I have the algorithms all worked out, I'll write the size-determining code in a library, then link it into my screen saver executable.

Geeky regards,

--- Victor.
 

vickster

Legendary Member
None...but I did populate some PowerPoint slides with market research data on male urinary incontinence pads...pays the bills eh! :wacko:
 

Archeress

Veteran
Location
Bristol
Not code but been researching multi-objective evolutionary algorithms for a presentation on state of the art research in search based software engineering. This is for the module emerging topics in software engineering for my MSc.

Hugs
Archeress x
 
Oh, can I play?

I didn't write any code today, but I finally got around to looking at an open source project of mine that was on googlecode, and then moved to github when googlecode shut down, that I haven't played with since the move - so it was/is moribund. It's a long time since I played with ant and java so it took me several hours to work out what 3 tiny changes were required to make it build again. Now I have to bring it up to date with more current libraries.

Recently I've been having a lot of fun with the Strava, MyCyclingLog, Endomondo and RideWithGPS APIs. See signature for more details.

@Shut Up Legs have you looked at ImageMagick? No help?
 
OP
OP
Shut Up Legs

Shut Up Legs

Down Under Member
Oh, can I play?

I didn't write any code today, but I finally got around to looking at an open source project of mine that was on googlecode, and then moved to github when googlecode shut down, that I haven't played with since the move - so it was/is moribund. It's a long time since I played with ant and java so it took me several hours to work out what 3 tiny changes were required to make it build again. Now I have to bring it up to date with more current libraries.

Recently I've been having a lot of fun with the Strava, MyCyclingLog, Endomondo and RideWithGPS APIs. See signature for more details.

@Shut Up Legs have you looked at ImageMagick? No help?
The MyCyclingLog API works now? I was using it for a while: I've been using a Java cycling-logging app that I wrote for years now, and one of its features was an automatic upload of a list of selected cycling trips to MCL. Then, the MCL API mysteriously stopped responding to my requests, and the site's owner, Michael Watts, never responds to anyone's support requests, as far as I can tell.
 
U

User33236

Guest
Added some php to a member page on the website I operate for my camera club to allow members to upload competition entries.

Had a mental block on adding a prefix to file names. Whilst trying to get it right I made a typing error (missed out a slash) and bizarrely it did, almost exactly, what I wanted so left it. Will do back and sort it out eventually when I get some time again.
 
I wrote the Drivers Highway Code, that took all of 2seconds :rolleyes:
 
The MyCyclingLog API works now? I was using it for a while: I've been using a Java cycling-logging app that I wrote for years now, and one of its features was an automatic upload of a list of selected cycling trips to MCL. Then, the MCL API mysteriously stopped responding to my requests, and the site's owner, Michael Watts, never responds to anyone's support requests, as far as I can tell.
No, it's working fine. Not a problem so far (I've only been using it for a month or so - touch wood).

https://www.cyclechat.net/threads/strava-to-mycyclinglog.194509/

(even implemented a delete option, via a bit of cURL jiggery-pokery. Needed as my first attempt to copy rides but a lot of bogus data in MCL)

Thanks for the tip: I just had a quick look at the ImageMagick C++ API PDF (i.e. for "Magick++"), and it looks like it might be useful.
:okay:
 
Wot I helped do today:
12705674_942830575772175_4204483146320640921_n.jpg


The 1871 cargo boat Raven being lifted out of the water for the first time in 40+ years.
 

marknotgeorge

Hol den Vorschlaghammer!
Location
Derby.
Can I play?
I've been writing code to get Windows 10 devices to talk to Bluetooth LE Cycling Speed and Cadence sensors. More specifically, working round a Windows bug that throws an exception the second time the program accesses the device after it's been paired. Gah!
 

goo_mason

Champion barbed-wire hurdler
Location
Leith, Edinburgh
Amending the VBA I wrote to pick relevant Wintel servers out of a list of thousands to be patched each month, create a tab for each platform and write the servers to each one. It then resizes the columns, adds a header row to each, prompts for a month name and saves the file with that month in the file name.

Always impress myself as I have never been trained in VBA and picked it up as I went along. The fact that it works never fails to amaze me!
 
OP
OP
Shut Up Legs

Shut Up Legs

Down Under Member
Amending the VBA I wrote to pick relevant Wintel servers out of a list of thousands to be patched each month, create a tab for each platform and write the servers to each one. It then resizes the columns, adds a header row to each, prompts for a month name and saves the file with that month in the file name.

Always impress myself as I have never been trained in VBA and picked it up as I went along. The fact that it works never fails to amaze me!
I've written VBA code before (under protest, and reluctantly). It's far from my favourite programming language. But yes, I agree it can be useful in the workplace sometimes.
 
Top Bottom