Page 1 of 1
How to Zoom on image in 'C'
Posted: 2013-05-02T15:02:53-07:00
by gfine
I am a noob with Imagemagick so please bear with me.
I am developing an application where I have a jpeg image in a memory buffer. Normally it just gets copied to a framebuffer and is displayed. What I have to do is Zoom in on the image. Here is basically what I am doing so far.
Code: Select all
Zoom_in_on_Image (jpegBuffer, jSize)
{
wand myWand;
size_t *image_length;
unsigned char *myBuffer;
// create wand
NewWandGenesis ( myWand);
// copy jpeg to wand
MagicReadImageFromBlob (myWand, jpegBuffer, jSize);
// Scale 2x
MagickMagnifyImage (myWand);
// get contents of the wand
myBuffer = MagickGetImageBlob(myWand, &image_length);
// copy it to the frame buffer memory
memcpy (frameBuffer, myBuffer,image_length);
// Display it in the frame buffer. If I use jpegBuffer it displayes a normal sized image.
display_fb (frameBuffer, Dev_0);
The code above is basically what I am doing, and not the live code as it is a product in development. I can not use the command line 'convert' program as I am dealing with memory bound images and there are no 'files' involved, just buffers.
I do not get any error returns. But image_length from the MagickGetImageBlob() is zero. So what am I missing in my steps? As I said I am new to using these libraries. I assume ReadImageFromBlob is copying it into the 'wand' instance. Is it?
Any pointers, help, examples (in C please) would be very much appreciated.
Glen
Re: How to Zoom on image in 'C'
Posted: 2013-05-02T17:19:29-07:00
by anthony
Note first I am not a normal user of C Wand API, though I have done so.
I had a quick look at the code for the call. For a while I thought I was on to something but it seems not.
Sorry unable to help.
Re: How to Zoom on image in 'C'
Posted: 2013-05-02T17:26:52-07:00
by magick
How do you know you do not not any errors? From your code, you're not checking. Call MagickGetException() and fix whatever it complains about.
Re: How to Zoom on image in 'C'
Posted: 2013-05-03T08:48:38-07:00
by gfine
OK. fair.
But what I posted is not the live code and it does checks the return of status(es) when I call an ImageMagick API. I beefed it up a bit with your suggestion, and the MagickReadImageFromBlob() is returning a "nodecodedelegate" error. I doublechecked and I do have libjpeg and the ./configure shows
jpeg = yes yes
I am guessing that for some odd reason in the cross compile (This is in an embedded TI DaVinci environment) libjpeg is not getting picked up properly. I am using jpegsrc.v9 and it cross compiles and seems to install properly. Is this the right library?
Glen
Re: How to Zoom on image in 'C'
Posted: 2013-05-03T09:08:43-07:00
by magick
Set the MAGICK_DEBUG environment variable to 'configure' and run your application, it looks like ImageMagick is not finding the configuration files. Next set MAGICK_DEBUG to 'module'. See if ImageMagick is looking in the right place for the JPEG coder.
Re: How to Zoom on image in 'C'
Posted: 2013-05-03T09:38:38-07:00
by gfine
Thanks. It is set on the ./configure.
However the above error seems to be that I didn't do a setformat before calling the MagickReadImageBlob. Now it tells me the source file is not a jpeg. But then that was an improper indirection (jpegbuffer versus &jpegBuffer) , and for some reason the first two bytes do not pass the jpeg signature check.
More later, debugging this. When finished and working, I'll post the real code.
Glen
Re: How to Zoom on image in 'C'
Posted: 2013-05-06T10:02:45-07:00
by gfine
Still continuing to debug.
Exception handling is good at reporting the status. At first I found I was not passing it the buffer properly as it reported the buffer was not a JPEG format. Fixed a problem with indirection, and now it calls into MagickReadImageBlob (wand, imgBuffer, image_len); and it does not return (in a reasonable amount of time). The system is not hung as I can telnet into it.
There is a watchdog program that 'kicks' an unresponsive process if it does not respond within 30 seconds, and so eventually the process with this code gets kicked.
The image is about 130k and is a JPG. It shouldn't take over 30 seconds should it? Anything I can use to see what is going on? MAGICK_DEBUG is there (for compile), and I am hooking exceptions.
Glen
[fixed typo]
Re: How to Zoom on image in 'C'
Posted: 2013-05-06T14:40:48-07:00
by gfine
Magick:
I guess some code might help. I should also mention that using -DMAGICK_DEBUG seems to have no efffect. What is the correct syntax. I have added it to the cross compile, and the application's makefile to no avail. I have even tried 'export MAGICK_DEBUG'. Your earlier answer is a little bit sparse. Nor could I find the document for it.
Code: Select all
void Zoom_in_on_image (char *Image_Buffer; private_image_data_t *Image_struct)
{
MagickBooleanType status;
MagickWand *magick_wand;
ExceptionInfo *exception;
ImageInfo *image_info;
ExceptionType an_error;
int j=0;
size_t iLen=0, iSize=0;
unsigned char *IM_Image_Buffer;
// Routine enters with a
// char * Image_Buffer ( pointer to the jpeg image)
// and an Image_struct which has data on the image like .img_size, .geometry members
// from an outside encoder
// The Image structure also has (for the decoder) .data and a .queue members
iSize = Image_struct.img_size;
printf("Beginning bytes, byte1=0x%X, byte2=0x%X\n",Image_Buffer[0],Image_Bufferf[1] );
// *** These bytes are 0xFF and 0xD8 *** which are the right bytes (SOI) for a JPEG
printf( "last 2 bytes = [0x%X], [0x%X]\n",Image_Buffer[iSize-2],Image_Buffer[iSize-1] );
// *** These bytes are 0xFF and 0xD9 *** which are the right bytes (EOI) for a JPEG
// Start of ImageMagicK code
MagickWandGenesis ();
magick_wand = NewMagickWand();
MagickGetException ( magick_wand, &an_error);
if (an_error)
printf( "Error in creating wand\n")
// Clear wand space
ClearMagickWand (magick_wand);
// Tell ImageMagick it is a jpeg
MagickSetFormat ( magick_wand, "JPG" );
// copy image into wand
// The failure is here **** Seems to be caught in a loop ***** Never gets past this point. *****
printf( "At ReadImageBlob\n");
status = MagickReadImageBlob ( magick_wand, Image_Buffer, iSize);
MagickGetException ( magick_wand, &an_error);
if (an_error)
{
ExceptionType severity;
char *err = MagickGetException(magick_wand, &severity);
printf( "ImageMagickReadImageBlob Error:[%s]", err);
MagickRelinquishMemory(err);
}
if (status)
{
printf("MagicReadImageBlob returned error=[%d]\n",status);
}
[ Zoom code goes here, and since I never get past the MagickReadImageBlob, it would be irrelevant ]
MagickWandTerminus();
As I said before. On Friday it was complaining about the delegate. Now it isn't. If I pass the image as &Image_Buffer it will complain about the start bytes. But the problem, now, is that it seems to be stuck in a loop.
Thanks in advance for any pointers as to what I am (or might be) doing wrong.
Glen