Monday, September 26, 2011

PNG Image scaling with Lib Cairo

Just wrote now for a tool and I liked the small utility.


#include "stdio.h"
#include

//#define ENABLE_DEBUG_LOG

#ifdef ENABLE_DEBUG_LOG
void printtImageDetails( cairo_surface_t * image, const char * text)
{
        if(text != NULL)
                printf("%s:\n", text);

        printf("W=%d H=%d\n", cairo_image_surface_get_width (image), cairo_image_surface_get_height (image));
        printf("Format:%d Stride:%d\n", cairo_image_surface_get_format(image), cairo_image_surface_get_stride (image));
}
#else
#define printtImageDetails(__image, __text)
#endif /* ENABLE_DEBUG_LOG */

void imageResize ( const char * sourceName, const char * destName, double ratio)
{
cairo_surface_t *image;
cairo_surface_t *dest;

image = cairo_image_surface_create_from_png (sourceName);
printtImageDetails(image, sourceName); 

dest = cairo_surface_create_similar (image, CAIRO_CONTENT_COLOR_ALPHA,
cairo_image_surface_get_width (image) * ratio,
cairo_image_surface_get_height (image) * ratio);

cairo_t *cr = cairo_create (dest);

cairo_scale (cr, ratio, ratio);
cairo_set_source_rgba (cr, 0, 0, 0, 0);
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (image);

printtImageDetails(dest, destName);
cairo_surface_write_to_png (dest, destName); 

cairo_destroy (cr);
cairo_surface_destroy (dest);

}/* end method imageResize */






Saturday, September 03, 2011

LLVM Project

Was compiling some code and LLVM is interesting. Some good info below.

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies. Despite its name, LLVM has little to do with traditional virtual machines, though it does provide helpful libraries that can be used to build them.

The Low Level Virtual Machine (LLVM) is a compiler infrastructure, written in C++, which is designed for compile-time, link-time, run-time, and "idle-time" optimization of programs written in arbitrary programming languages. Originally implemented for C/C++, the language-agnostic design (and the success) of LLVM has since spawned a wide variety of front ends, including Objective-C, Fortran, Ada, Haskell, Java bytecode, Python, Ruby, ActionScript, GLSL, Clang, and others.

The LLVM project started in 2000 at the University of Illinois at Urbana–Champaign, under the direction of Vikram Adve and Chris Lattner. LLVM was originally developed as a research infrastructure to investigate dynamic compilation techniques for static and dynamic programming languages. LLVM was released under the University of Illinois Open Source License, a BSD-style license. In 2005, Apple Inc. hired Lattner and formed a team to work on the LLVM system for various uses within Apple's development systems. LLVM is an integral part of Apple's latest development tools for Mac OS X and iOS.

LLVM began as a research project at the University of Illinois, with the goal of providing a modern, SSA-based compilation strategy capable of supporting both static and dynamic compilation of arbitrary programming languages. Since then, LLVM has grown to be an umbrella project consisting of a number of different subprojects, many of which are being used in production by a wide variety of commercial and open source projects as well as being widely used in academic research. Code in the LLVM project is licensed under the "UIUC" BSD-Style license.

The primary sub-projects of LLVM are:

    • The LLVM Core libraries provide a modern source- and target-independent optimizer, along with code generation support for many popular CPUs (as well as some less common ones!) These libraries are built around a well specified code representation known as the LLVM intermediate representation ("LLVM IR"). The LLVM Core libraries are well documented, and it is particularly easy to invent your own language (or port an existing compiler) to use LLVM as an optimizer and code generator.

    • Clang is an "LLVM native" C/C++/Objective-C compiler, which aims to deliver amazingly fast compiles (e.g. about 3x faster than GCC when compiling Objective-C code in a debug configuration), extremely useful error and warning messages and to provide a platform for building great source level tools. The Clang Static Analyzer is a tool automatically finds bugs in your code, and is a great example of the sort of tool that can be built using the Clang frontend as a library to parse C/C++ code.

    • dragonegg and llvm-gcc 4.2 integrate the LLVM optimizers and code generator with the GCC 4.5 (which is GPL3) and GCC 4.2 (which is GPL2) parsers, respectively. This allows LLVM to compile Ada, Fortran, and other languages supported by the GCC compiler frontends, and provides high-fidelity drop-in compatibility with their respective versions of GCC.

    • The LLDB project builds on libraries provided by LLVM and Clang to provide a great native debugger. It uses the Clang ASTs and expression parser, LLVM JIT, LLVM disassembler, etc so that it provides an experience that "just works". It is also blazing fast and much more memory efficient than GDB at loading symbols.

    • The libc++ and libc++ ABI projects provide a standard conformant and high-performance implementation of the C++ Standard Library, including full support for C++'0x.

    • The compiler-rt project provides highly tuned implementations of the low-level code generator support routines like "__fixunsdfdi" and other calls generated when a target doesn't have a short sequence of native instructions to implement a core IR operation.

    • The vmkit project is an implementation of the Java and .NET Virtual Machines that is built on LLVM technologies.

    • The klee project implements a "symbolic virtual machine" which uses a theorem prover to try to evaluate all dynamic paths through a program, in an effort to find bugs and to prove properties of functions. A major feature of klee is that it can produce a testcase in the event that it detects a bug.