Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
anta40
Posts: 224
Registered: ‎07-26-2010
My Device: Z10
Accepted Solution

Editing EXIF tags?

I'm working on a simple EXIF viewer/editor.

 

I think we can use these to read the EXIF tags:

http://developer.blackberry.com/native/reference/bb10/com.qnx.doc.camera.lib_ref/topic/camera_meta_g...

 

But how to re-write the values for those tags?

BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: Editing EXIF tags?

are you trying to modify exif data before saving a jpg from the camera?

or are you loading them up from disk for editing?

Developer
anta40
Posts: 224
Registered: ‎07-26-2010
My Device: Z10

Re: Editing EXIF tags?

"or are you loading them up from disk for editing?"

 

Yes, this is what I mean.

BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: Editing EXIF tags?

in that case, don't look at the camera API.

 

libexif is available on the platform, so I suggest just searching the web for examples.

I have a sample here that uses libexif to detect whether the flash was fired in a photo:

https://github.com/blackberry/Presentations/tree/master/2012-BlackBerryJam-Americas/JAM15/FlashPhoto

 

This uses the camera API to locate the EXIF metadata in a photo before it is saved to disk, but I could just as easily have used libexif's functions to locate the EXIF data inside the JPEG buffer. 

 

The reason a separate way exists to do this via the camera API is so that we can support metadata in uncompressed images which may have no standard mechanism for encapsulating the metadata.

 

Cheers,

Sean

Developer
anta40
Posts: 224
Registered: ‎07-26-2010
My Device: Z10

ARe: Editing EXIF tags?

Ah yes you are right. I was looking at the wrong thing.

Indeed libexif is the correct thing.

 

And regarding reading/writing EXIF tags, you could learn from these 2 examples: cam_features.c and write-exif.c

http://libexif.cvs.sourceforge.net/viewvc/libexif/libexif/contrib/examples/

Developer
anta40
Posts: 224
Registered: ‎07-26-2010
My Device: Z10

Re: ARe: Editing EXIF tags?

I'm sorry for bumping this because actually I'm still confused.

 

Now I'm studying this code. First you search for the entry you are going to edit using init_tag(). After that, use exif_set_xxxx to write the change.

 

Let's say I'd like to change the camera model info (EXIF_TAG_MODEL). How could I edit this? I don't see exif_set_string() method?

BlackBerry Development Advisor
smcveigh
Posts: 668
Registered: ‎11-29-2011
My Device: developer

Re: ARe: Editing EXIF tags?

It's doable.  exiftool can do it.

 

from the code you pointed to on stackoverflow:

http://libexif.cvs.sourceforge.net/viewvc/libexif/libexif/contrib/examples/write-exif.c?view=markup

it looks like you would just use memcpy() to overwrite the entry->data.

You would need to find the entry for EXIF_TAG_MODEL first which you seem to already know how to do.

 

IF you require more space than is available in that particular tag to write your string (eg. trying to write "APPLE" into a field which may have previously only had enough space for "IBM"), then you may need to re-build the entire exif blob.

 

I would have to spend time looking up tutorials on the libexif doc site, but the procedure is probably more or less:

1. create a NEW exif object using eg. exif_data_new_from_file()

2. locate the tag you want to change

3. delete the old entry

4. allocate a new entry & fill it with the data you need

5. add the new entry to the exif object

6. render down to a binary blob using exif_data_save_data()

6. save the data back out to the file (you probably need to do some magic with libjpeg to replace the old blob in the file with the new one - eg. load, strip old blob, add new blob, save)

 

Cheers,

Sean

Developer
dbigham
Posts: 554
Registered: ‎04-01-2009
My Device: Z10, PlayBook

Re: ARe: Editing EXIF tags?

I'm still trying to figure out what the "right" solution is for writing EXIF data, but I think the fastest path to victory is to search for the source code for the "exif" linux command line utility and examine the file "actions.c", namely the function action_save.

 

Here it is:

 

void
action_save (ExifData *ed, ExifLog *log, ExifParams p, const char *fout)
{
	JPEGData *jdata;
	unsigned char *d = NULL;
	unsigned int ds;

	/* Parse the JPEG file. */
	jdata = jpeg_data_new ();
	jpeg_data_log (jdata, log);
	jpeg_data_load_file (jdata, p.fin);

	/* Make sure the EXIF data is not too big. */
	exif_data_save_data (ed, &d, &ds);
	if (ds) {
		free (d);
		if (ds > 0xffff)
			exif_log (log, -1, "exif", _("Too much EXIF data "
				"(%i bytes). Only %i bytes are allowed."),
				ds, 0xffff);
	};

	jpeg_data_set_exif_data (jdata, ed);

	/* Save the modified image. */
	jpeg_data_save_file (jdata, fout);
	jpeg_data_unref (jdata);

	fprintf (stdout, _("Wrote file '%s'."), fout);
	fprintf (stdout, "\n");
}

 

I had written my own custom code for writing the EXIF blob into a JPEG file, but it wasn't robust enough for real world purposes, where things aren't always as simple as we'd like.

 

I'm actually stuck at the moment because after adding libjpeg to my project, it's not liking:

 

#include <libjpeg/jpeg-data.h>

 

... and under "Includes" in my project, it doesn't seem to have an item for libjpeg. Maybe I'm running into an IDE bug...

Developer
dbigham
Posts: 554
Registered: ‎04-01-2009
My Device: Z10, PlayBook

Re: ARe: Editing EXIF tags?

Developer
dbigham
Posts: 554
Registered: ‎04-01-2009
My Device: Z10, PlayBook

Re: ARe: Editing EXIF tags?

Bummer.

 

Functions like jpeg_data_new are showing up as undefined references, not sure why, and my project won't compile.

 

I can ctrl-click on them ot see them in jpeg-data.h, though.