Compiling/using libjpeg for iPhone (iOS 3.0+)? - objective-c

I want to use the libjpeg (http://www.ijg.org/) library in an iPhone iOS 3.0 or greater project. I have tried a few different approaches, but being a bit naive, I'm not really sure how to begin.
I've been playing with parts and pieces of the SDL library project from here http://code.google.com/p/sdl-static/ all to no real working outcomes.
Can anyone link me to a tutorial or give me a push in the right direction?
My ultimate goal is to be able to manipulate the DCT coefficients of jpeg images somewhat similar to this MatLab libjpeg wrapper.
http://www.philsallee.com/jpegtbx
So I would like to start with something like
UIImage *cover = [UIImage imageNamed:#"cover.jpg"];
// convert to the libjpeg structs
// do some DCT coefficient manipulations
UIImage *stego = ... // save it back to iOS SDK equivalent image type

You can unpack the entire library into your project and add the files to XCode. There's a file 'filelist.txt' which describes the minimal set you need to link into your project. Have a look at 'example.c' for how to call the API. I don't see functions to tweak the DCT coefficients - that you'll have to hack in yourself.

Related

How to generate barcode 128 for os x, objective c

I'm working on a project for a OSX and I'm using xcode 4.6.3. I need to generate a barcode image with Encoding 128, and insert it in a pdf file.
I've been researching and I can't figure out how I can do that. I tried to use cocoabarcode, I solved ARC error, but stil have some error tried to replace
sAttr = [[NSMutableAttributedString allocWithZone:[self zone]] initWithString:leftCaption attributes:[NSDictionary dictionaryWithObjectsAndKeys:font,NSFontAttributeName,leftAligmentStyle,NSParagraphStyleAttributeName,[NSNumber numberWithFloat:kerning],NSKernAttributeName,nil]];
(error: zone is unavailable: not available in automatic reference counting mode),
and other warnings deprecated methods,
I want to know if someone it's ussing this library, if it's work propertly, or if there are other library like this one for iphone, but I need for OSX, or any other suggestion about what classes or library I should research.
Thank you in advance!
May spire.barcode could help you, it supports Code 128 Barcode

Where are the image and sound files inside XCode?

Are the images and sound files that are used inside the Unity IDE somehow compiled into libiPhone-lib.a inside XCode? I'm looking for a way to access the audio files and images inside XCode/Objective-C. As far as I can tell by looking at the exported XCode project, there are no sound files or other resources anywhere to be seen
They are compiled into the lib as a byte code which is then interpreted at runtime. Disclosure of this would destroy Unity's business model, as everyone would make corrections into unity-produced code. It is more easy for them to interpret bytecode rather than translating it into human-readable language like C or objective-c.
The answer is: yes, they are compiled into lib.
If you want to access them from objective-c layer, you have to add them to project again in a usual xCode way ,so their data will be doubled in the project.

Xcode: Cocos2d: Can't create world with Box2D

My project originated as the cocos2d Box2D template and I'm having issues as soon as I tried to create a world:
world = new b2World(gravity,doSleep);
Gives the error: No matching constructor for initialization of 'b2World'.
The file is .mm, I assume it's some issue about library linking maybe? If so I'm using xCode 4, how can I check the lib is properly linked?
Thanks.
You are using Box2D v2.2 or newer. The b2World constructor no longer takes two arguments, just one (gravity). You have to set doSleep separately:
world = new b2World(gravity);
world->SetAllowSleeping(doSleep);
This won't be the only change you'll need to make to transition from Box2D v2.1.x to v2.2.x. Kobold2D has a working Box2D 2.2.1 sample project, even if you don't use Kobold2D you can get updated source code for Box2D basics. In particular the GLESDebugDraw class and how to setup a screen bounding box with a body using multiple shapes.

Add an image (or other resources) to a Mac or iOS Framework

Let's say I have an existing iOS or Mac Framework that we'll call Test.framework. This framework has compiled and linked successfully (a trick was done to lipo both i386 and armv6/7 archs for the iOS part) and is working perfectly fine.
Now I want to add an image to it let's call it 'test.png'. I have copied it into the Resources folder of my framework so that I have the following structure:
ls Test.framework
- Headers -> Versions/Current/Headers
- Resources -> Versions/Current/Resources
- Test -> Versions/Current/Test
- Versions
ls Test.framework/Resources
- Info.plist
- test.png
Yet when I create a project using my framework I cannot access that image.
I've tried:
[UIImage imageNamed:#"test.png"]
[UIImage imageNamed:#"Test.framework/test.png"]
[UIImage imageNamed:#"Test.framework/Resources/test.png"]
But nothing worked out that always gave me back a nil object.
Any ideas ?
EDIT
After much further investigation it seems what I am trying to accomplish can't be done on iOS. The reason is that the final application bundle (the .app) doesn't copy the private frameworks where applications compiled for Mac OS will.
This is further detailed in the iOS Bundle Structures documentation.
Thanks to Rob Keniger and xuzhe for their appreciated help. I will credit xuzhe for the answer as it is actually the most appropriate answer to my original problem (even though Rob comment made me dig quite deeper into the issue)
The "imageNamed:" method is only for images in your App bundle. You should use
[[UIImage alloc] initWithContentsOfFile:path];
instead.
About the path, since I am not sure if the "Test.Framework" is in you App bundle, I am not able to give you a sample code. But if it dose, the code below should work:
NSString* path = [Nsstring stringWithFormat:#"%#/Test.framework/Resources/test.png", [[NSBundle mainBundle] bundlePath]];
You can get the bundle for a particular class using [NSBundle bundleForClass:[SomeClass class]]. All you need to do is pass in a class that's defined in the framework and you'll have a reference to the framework's bundle.
You can then ask the bundle for the path to the image using the pathForResource:ofType: method of NSBundle, and then use the initWithContentsOfFile: method of NSImage to create your image.
Note that you should never hard-code paths. Ever. There are many different functions and methods for obtaining paths to resources, you never need to hard-code them.

How to implement a Cocoa-based Adobe Photoshop plugin

Cocoa used to work on CS3 with the trick of putting a Cocoa bundle inside the main Carbon plugin bundle, loading it from Carbon and issuing a NSApplicationLoad(). That's because Photoshop CS3 was Carbon-only and used to unload the plugin bundles.
Photoshop CS4 uses Cocoa and has its own NSAutorelease pool in place on the main thread.
On Photoshop CS4 very simple window-based xibs/nibs loaded by a NSWindowController work out of the box.
But just add a binding to a control on the window and you'll get funny crashes, optionally when you close the window, or the second time you use the plugin, or even when closing Photoshop itself.
Why everything seem to work well until I use some advanced Cocoa features? I'm stuck.
EDIT: I've really found myself the solution to the broader problem "How to use Cocoa in a Photoshop CS3/CS4 plugin?". See below.
You have to create a new Loadable Bundle target that contains your nibs and your Cocoa code. Add the bundle product to the Copy Bundle Resources phase of your plugin. Then the code for a filter plugin that loads a Cocoa window with some controls would be:
Boolean DoUI (void) {
// Create the CF Cocoa bundle
CFBundleRef pluginBundle;
CFURLRef cocoaBundleURL;
pluginBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.example.plugin"));
cocoaBundleURL = CFBundleCopyResourceURL(pluginBundle,
CFSTR("Cocoa_bundle"),
CFSTR("bundle"),
NULL);
CFBundleRef cocoaBundleRef;
cocoaBundleRef = CFBundleCreate(kCFAllocatorDefault, cocoaBundleURL);
CFRelease(cocoaBundleURL);
// start Cocoa (for CS3)
NSApplicationLoad();
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// load the cocoa bundle by identifier
NSBundle* cocoaBundle;
cocoaBundle = [NSBundle bundleWithIdentifier:#"com.example.plugin.cocoa"];
// load the window controller from the bundle
Class testControllerClass;
testControllerClass = [cocoaBundle classNamed:#"MyWindowController"];
MyWindowController* winController = [[testControllerClass alloc] init];
[NSApp runModalForWindow:[winController window]];
[[winController window] performClose:nil];
[winController release];
// release the bundle
CFRelease(cocoaBundleRef);
[pool release];
return 1;
}
This is based on the Craig Hockenberry bundle trick. I'm still testing it but it should work both on CS3 and CS4.
I just started working on writing a Cocoa-based plugin for CS4. Really, there is almost no information out there on this topic, and I've been figuring it out as I go.
Start from this Apple example, and make sure you download the whole project, because there are a few little details missing from the text:
Carbon/Cocoa
Pick one of the Photoshop SDK examples (I used ColorMunger), and keep it simple to start, so just try to replace the "About" dialog box, using the Apple example as your template. Once you have that working with no memory issues, you should be on your way.
I've been a Java and Ruby programmer for 10 years, so my C/C++ foo is rusty, and I'm just learning Objective C as I go. Two "gotchas" I ran into, just in case....
do NOT create a controller object in your NIB/XIB file. Because, based on that Apple example, the controller opens up the NIB file in it's init method, and you get a really interesting recursive loop
The Apple example is embedding the Cocoa stuff in a Carbon based C app. The Adobe examples are all C++. Don't forget your extern "C" {} in your header file.
CS2 will load PowerPC Mach-O code as readily as CS3/CS4. Has anyone tested this Cocoa approach in CS2?
Currently I use Carbon for CS2/CS3/CS4 as this is guaranteed to work everywhere the plugin loads; and Cocoa for CS5 of course, whether 32 or 64 bit.
Chris Cox isn't optimistic about Cocoa working in anything other than CS5:
http://forums.adobe.com/message/3256555#3256555
So what's the real deal here? It's pretty hard to ignore advice from the horse's mouth.