How to use libjpeg in xCode

Discussion in 'iOS Programming' started by Samar-, Nov 3, 2012.

  1. Samar- macrumors newbie

    Joined:
    Nov 3, 2012
    #1
    I'm developing an iPhone application and I'm kind of new to everything. I'm working on Mountain Lion OS X 10.8 and using xCode v4.5. I need JPEG handling capabilities in my project and I want to use the libjpeg (http://www.ijg.org/) library. I have tried a few different approaches, but being a bit naive, I'm not really sure how to begin. After downloading packages I've made usual ./configure; make and make install. Right now I have (jconfig.h, jerror.h, jmorecfg.h, jpeglib.h) under (/usr/local/include) and (libjpeg.a, libjpeg.la) under (/usr/local/lib) but I have no idea how to link/use this in my xCode project.
    Can anyone link me to a tutorial or give me a push in the right direction?
    If anyone successfully installed and used jpeg library please help..
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    iOS can do various things with JPEG images without adding any libraries.

    "JPEG handling capabilities" is too vague. Please describe what you want to accomplish using libjpeg, that can't be accomplished with existing iOS capabilities. If you don't know, then you should study UIImage and the underlying image-file handling, so you know what's possible without libjpeg.


    Your question is basically an XY problem:
    http://www.perlmonks.org/index.pl?node_id=542341
    .. You want to do X, and you think Y is the best way of doing it.
    .. Instead of asking about X, you ask about Y.
     
  3. samdev macrumors regular

    Joined:
    Sep 16, 2011
    #3
    The UIImage class already supports these formats:

    Code:
    Tagged Image File Format (TIFF)		.tiff, .tif
    Joint Photographic Experts Group (JPEG)	.jpg, .jpeg
    Graphic Interchange Format (GIF)	.gif
    Portable Network Graphic (PNG)		.png
    Windows Bitmap Format (DIB)		.bmp, .BMPf
    Windows Icon Format 			.ico
    Windows Cursor				.cur
    XWindow bitmap				.xbm
    
    But, unless your JPGs are like camera pictures/photographs, I would avoid using them.
    I recommend using PNG instead, because iOS does a crap job of loading JPGs, especially for Retina displays.
    You get a lot of banding. JPGs are lossy, and quality is lost when loading them.

    Special warning:
    Do not use JPG for GUI elements. Your app will look like crap under Retina. Always use PNG.
     
  4. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    Using an open source library like libjpeg can be straightforward. Usually the hard part is building the library but you seem to have already done that. make install probably isn't useful. You're not interested in installing into /usr.

    Make two folders in your project folder, one for the .a file and the other for the headers. Add the header folder to your project. Add the .a file to your project in the frameworks group. If you've built your library correctly that should be all that's required to use it.

    This also might be informative:

    http://www.imagemagick.org/download/iOS/
     
  5. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #5
    If this is for an iPhone project, then compiling it for your Mac doesn't help. It will have to be compiled for ARM to work on the iPhone.
     
  6. Samar- thread starter macrumors newbie

    Joined:
    Nov 3, 2012
    #6
    I'm developing a steganography app and my ultimate goal is to be able to manipulate the DCT coefficients of jpeg images. I now that I access the DCT coefficients in libjpeg using the jpeg_read_coefficients function but I'm not sure if that is possible with UIImage. Hope this clears my problem

    ----------

    As I said my ultimate goal is to manipulate the DCT coefficient of a JPEG image to hide some data. I didn't consider other image formats because I want the user to directly choose his/her cover image from the phone library or to take a new one with the camera and both would be JPEG. I guess I might consider converting the image format from JPEG to something simpler. I'll see how it goes.
    Thanks for your reply..

    ----------

    That looks helpful, thanks..

    ----------

    Can you please explain how I can compile for ARM so it work on the iPhone? and would it work on the simulator or it has to be a real device?
     
  7. Samar- thread starter macrumors newbie

    Joined:
    Nov 3, 2012
    #7
    I tried copying the headers and the .a file into my project but I'm getting the following warning:
    ld: warning: ignoring file /Users/.../libjpeg.a, file was built for archive which is not the architecture being linked (i386)
    I guess I didn't build the library correctly. Do you know how I can build it to work with the iPhone and the simulator?
    I appreciate your help..
     

Share This Page