Monday, June 21, 2010

Tracing transparency outline of an Image


/**
* Process the image and return the number of pure red pixels in it.
*/


- (NSUInteger) processImage: (UIImage*) image
{
NSUInteger numberOfRedPixels = 0;


// Allocate a buffer big enough to hold all the pixels


struct pixel* pixels = (struct pixel*) calloc(1, image.size.width * image.size.height * sizeof(struct pixel));
if (pixels != nil)
{
// Create a new bitmap


CGContextRef context = CGBitmapContextCreate(
(void*) pixels,
image.size.width,
image.size.height,
8,
image.size.width * 4,
CGImageGetColorSpace(image.CGImage),
kCGImageAlphaPremultipliedLast
);

if (context != NULL)
{
// Draw the image in the bitmap


CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, image.size.width, image.size.height), image.CGImage);

// Now that we have the image drawn in our own buffer, we can loop over the pixels to
// process it. This simple case simply counts all pixels that have a pure red component.


// There are probably more efficient and interesting ways to do this. But the important
// part is that the pixels buffer can be read directly.

NSUInteger numberOfPixels = image.size.width * image.size.height;
int cnt = 0;
int width = image.size.width;
//pixels+=2;
while (numberOfPixels > 10+image.size.width) {
if (((pixels-1)->a==0 || (pixels+1)->a==0 || (pixels+width)->a==0 || (pixels+width-1)->a==0 || (pixels+width+1)->a==0 || (pixels-width)->a==0 || (pixels-width-1)->a==0 || (pixels-width+1)->a==0) && (pixels)->a > 0) {
numberOfRedPixels++;
(pixels)->r = 0;
(pixels)->g = 255;
(pixels)->b = 0;
(pixels)->a = 255;
}
cnt++;
pixels++;
numberOfPixels--;
}

CGImageRef imageRef = CGBitmapContextCreateImage(context);

UIImage *myImage = [UIImage imageWithCGImage:imageRef];
[imageView setImage:myImage];

if(myImage != nil){
//UIImage *myImage = [UIImage imageWithCGImage:imageRef];
NSData* imageData = UIImageJPEGRepresentation(myImage, 1.0);
NSLog(@"Writing image to file:!");
[imageData writeToFile:@"/Users/lee/playground/resultImage.jpg" atomically:NO];
}


}


//free(pixels);
}

return numberOfRedPixels;
}


- (IBAction) processImage
{
//[self init];
NSUInteger numberOfRedPixels = [self processImage: inputImage];
label_.text = [NSString stringWithFormat: @"There are %d transparent pixels in the image", numberOfRedPixels];
}


This is just a sample code for tracing transparent outlines of images in iphone OS examples, This is just my personal notes. If you happened to stumble on this, feel free to comment, so I can explain this further.

Wednesday, March 17, 2010

Unlimited Detail Technology

This is the new technology I found so much of an interest that I wish I could steal their source code and release it in the open source in order to solve issues with graphics cards drivers in linux.




This is really a break through in computer graphics. Unlimited Detail Technology is a new startup company behind the technology. Their concept is logical in which it is based in 3D search engine algorithm, pulling only the points that are needed 1 for each pixel for a deterministic screen resolution (ie 1025 x 768).




The company mentioned that they had approach the 2 giant graphics cards vendors: ATI and nVidia (which they call polygon company). The 2 polygon companies don't like the idea of dumping the polygon based rendering so they were not able to reach the board of directors.

Upon seeing their demo of their technology, I can see the inevitable detail of the objects, and their are thousands of them comprising billions of points which would have been impossible to be rendered with current polygon based graphics cards.

You may say that 3D movies such as Shrek had a stunning photo-realistic appeal. Of course they do, but no in real time considering Shrek 3 is rendered with more than 1,000 Linux desktops and more than 3,000 CPU servers, consuming close to 20 million CPU render hours. reference.
How much power could they have saved if Unlimited Detail Technology is what they have used and its in real time.(yeah you're right that doesn't exist yet). Will future 3D movies invest on this? well may be not coz they have a lot of money for the costly wide array of servers to the job. If they are concerned that the amount of cooling power to those machines contributes to global warming. Let's go green!

Okay, I see that there is a future for this technology and may need some time for wider adaption. A smarter company may buy into this technology let me predict the future, Ohh! Google bought it and use the technology for rendering 3D web engine o3d. This technology doesn't need much of the hardware rendering, so it would be viable across multiple platform. Com'on google buy it then used it in o3d web engine, then release the code to the open.

Thursday, February 11, 2010

Whatever you do in flash, you could do it now on standard HTML

Before it is whatever you could do in desktop application you could do it in the web( through the used of plugins, thanks to Adobe/macromedia flash ). Now its whatever you do in flash you could do it in standard html.

Wanted to play more animation with your images other than from tiny to large such as rotate it clockwise and counterclock wise, without flash plugin, just javascript and standard HTML DOM elements manipulation.


An interactive pie chart?



Wanted to display a chart like that of google analytics?


Wanted to edit charts points? Ok move it! I mean the dots.


How about flashy maps, again without flash.


Or just wanted to play a lightweight counterstrike in an instant.


Isn't it looks flashy?
Actually it is SVG (Scalable Vector Graphics) manipulation.

Ok what projects are you planning to build?

More info at this at http://raphaeljs.com/
Yes its open source.

Wednesday, February 10, 2010

Firefox plugins you may need when developing GWT apps in linux

Here is a list of plugins you need to have a complete set of Java web app development environment in Linux.
Firstly, you need eclipse I suugest the latest eclispe 3.5 (Galileo)

Monday, February 1, 2010

How good of an application would it be?

What if I could build an application as complete as ADempiere. Basically it will be an ERP application
With this additional features that is lacking or harder to implement in the project:

  • Model inheritance, where in objects of the same kind can inherit properties of parent objects plus the object property
  • Multiple Record Action fields, buttons fields of a window or tabs could use the focused object or selected objects on the list as a parameter for the process it would execute.
  • Standalone Clientside Offline Support, where you could run the application using standard browsers(firefox, chrome, safari) with support of HTML DB or google gears without the hassles of installing a heavy server based rdbms, without breaking security.  The application would automatically synch back to server whenever network is available.
  • Lightweight,  could run even on simple low-specs machine such as the laptops and netbooks.
  • Modular, the user could choose which to be available in its applications so it would not be bloated, and has the ability to remove, re-add those modules.
  • Seamless Replication Strategy, synchronizing between multiple servers will be seamless and consistent wherein records for a certain object is traceable from what server it came from.
  • Multiple Server Capability, ability to use another server when one server is down, without breaking the consistency of the records, synchronization be made first when needed.
  • Maven support, automated build, testing and code commit will be simplified if the project is deployed in maven repository.
  • Flexible Layout Modification, general, monotonic layout for application view is good, but there is always a better way for each certain models the application be presented to its user.
  • Webbish 2.0, Intuitive UI, user interface designs will be enchanced, where in the data is contained by a UI and changed accordingly to user responses such as when a field is focused for editing.
  • Improvement of Workflow and Alert escalation implementation, I believe there is a better way of presenting the Workflow of tasks and alerts of an application to be somewhat like that of facebook status updates, with an alternate view somewhat like implemented in plurk timeline.
  • Database independence, with the advent of several database ORM and abstraction layers such as JPA and JDO the application will be deployable in any target database. Deploying into any rdbms should be simple. One of the most benefit would be, the application be deployable in the cloud such as google app engine which offers free quota, which enough for your application to start at zero expenses.

Seriously those features that I mentioned is continually itching me as a web developer. I am using my limited spare time to exhibit those features, one at a time, little by little.

Monday, January 25, 2010

State of the art web application Ajax frameworks


I can't see any other web application framework more mature than the GWT from google and ZK from potix corporation. Both ajax frameworks is implemented in Java. Each has different implementation approach. ZK uses server-centric approach while GWT uses client-centric(hosted mode is somewhat server centric as well). Both has advantages over the other. These list is the prominent I found so far.


Advantages of GWT over ZK
  • GWT is compiled in javascript, so Converting your web application to have offline support is pretty slick and seamless. Unlike ZK which most of the codes is run in the server.
    • More info:
      • Offline support for web application is a very usable feature so users won't have to connect to a network all the time to continue the use of their applications. Offline is the new hype in HTML 5.0 specification which for now is implemented using google gears plugin. Google gears plugin is available to most web browsers and it is installed by default with the newly available high performance google chrome browser.
  • It is easy to create custom components for your app in GWT from scratch which you could base your components from already defined GWT components, or you could extend those components with ease.
  • GWT provides an unrelenting flexibility with your components in a consistent manner (using same java codes) unlike zk you have to code custom flexibilty in javascript.
  • GWT does not require to use Java as the server side code to implement business logic in the server. In fact you could use any server platforms such as PHP, python, .net, etc. aside from Java.

Advantages of ZK over GWT
  • Coding business logic in ZK is pretty slick, simple and higher security imposition, where as in GWT it is a little bit tricky to link your client side logic and server side logic.
  • Scaling your application depends on your server you deployed your application. So whenever you need your users to have a better application performance, You just have to upgrade server resources.
  • ZK provides a lot of ready to use widgets and components.

Strengths of Java which is not found in PHP

There is a long list of advantages of some languages from other language but I just list down some of the prominent I found out so far.
This is not a comparison of languages over another language. This is just a little angle to looking one language over the other.


  1. When declaring Class members, you could use a function to define the member property
    • example: public String myText = SomeOtherClass.getMyText();
    • which is not allowed in PHP
  2. PHP has no method overloading (methods with the same name but with different signatures in which the right method to be invoked is determined by the matching supplied parameters and return values)
    • example in Java
      • public void getData(int Param)
      • public void getData(String Param)
      • public void getData(int Param1, String Param)
    • This could be in a similar way done in PHP by appending the data type into the function
      • function getData_int(Param)
      • function getData_string(Param)
      • function getData_int_string(Param1,Param2=null)
      • or something like:
        • function getData(param){
              type =  getType(param);     if(type==int){         ...     }else if(type == String){
                  ...
              }
      • }
  3. Namespace in PHP is very odd to see
    • in php: \\com\\somecompany\\webui::MainModule
    • in java is desirable: com.somecompany.webui.
    • when using php in procedural language codes you write is short and readable, but in OOP php(5.0+), theres a need to explicitly use $this-> to every method/property call of members in the class, which hinders readability of code, where as in java, you are not required to write "this" as long as there is no conflict to a method local variable.

A little bit of IT

There is an endless knowledge in the area of IT and Programming, Let's just make simple things. Let's just talk a certain little bit of it, rather than creating a large file of body of knowledge that we are not sure it is.