objective c - Converting from UIImage/CGImage to Leptonica Pix structure -



objective c - Converting from UIImage/CGImage to Leptonica Pix structure -

i want utilize leptonica library in ios application image processing , have troubles figuring out how leptonica's pix construction uiimage. suggest following:

uiimage *image = [uiimage imagenamed:@"test.png"]; ... cfdataref imagedata = cgdataprovidercopydata(cgimagegetdataprovider([image cgimage])); const uint8 *rasterdata = cfdatagetbyteptr(data);

can suggest how correctly convert info leptonica's pix structure:

/*-------------------------------------------------------------------------* * basic pix * *-------------------------------------------------------------------------*/ struct pix { l_uint32 w; /* width in pixels */ l_uint32 h; /* height in pixels */ l_uint32 d; /* depth in bits */ l_uint32 wpl; /* 32-bit words/line */ l_uint32 refcount; /* reference count (1 if no clones) */ l_int32 xres; /* image res (ppi) in x direction */ /* (use 0 if unknown) */ l_int32 yres; /* image res (ppi) in y direction */ /* (use 0 if unknown) */ l_int32 informat; /* input file format, iff_* */ char *text; /* text string associated pix */ struct pixcolormap *colormap; /* colormap (may null) */ l_uint32 *data; /* image info */ };

upd:

i doing this:

uiimage *image = [uiimage imagenamed:@"test.png"]; cfdataref info = cgdataprovidercopydata(cgimagegetdataprovider([image cgimage])); const uint8 *imagedata = cfdatagetbyteptr(data); pix *mypix = (pix *) malloc(sizeof(pix)); cgimageref mycgimage = [image cgimage]; mypix->w = cgimagegetwidth (mycgimage); mypix->h = cgimagegetheight (mycgimage); mypix->d = cgimagegetbitspercomponent(mycgimage); mypix->wpl = cgimagegetbytesperrow (mycgimage) / 4; mypix->data = (l_uint32 *) imagedata; mypix->colormap = null; nslog(@"pixwrite=%d", pixwrite("/tmp/lept-res.bmp", mypix, iff_bmp));

but quite different original picture:

http://dl.dropbox.com/u/4409984/so/lept-orig.png

vs.

http://dl.dropbox.com/u/4409984/so/lept-res.png

what doing wrong?

once have cgimage, can of info straight cgimage.

cgimageref mycgimage = [image cgimage]; struct pix mypix; mypix.w = cgimagegetwidth (mycgimage); mypix.h = cgimagegetheight (mycgimage); mypix.d = cgimagegetbitspercomponent (mycgimage); mypix.wpl = cgimagegetbytesperrow (mycgimage) / 4; ... etc. ...

objective-c uiimage cgimage

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -