Sunday, February 15, 2009

Making your own Aero glass windows

In this post, I will share you how to make your forms in Windows Vista (or Windows 7) glassy style. Like in Windows media player.

The example will be written on Delphi, but it will look similar on other languages. It's quite easy, all you need to do is to import the dwmapi.dll in your app. You can find all useful information about Desktop Window Manager on MSDN (http://msdn.microsoft.com/en-us/library/aa969540(VS.85).aspx). Shortly, DWM is the new Windows desktop composition feature. When it is enabled, individual windows drawing is redirected to off-screen surfaces in video memory, which are then rendered into a desktop image and presented on the display.

So you import this library, like this:

procedure InitDWM();
var
  Handle: THandle;
begin
  Handle := LoadLibrary('dwmapi.dll');
  if Handle = 0 then
    raise Exception.Create('Can''t load dwmapi.dll');
  @MakeDWM := GetProcAddress(Handle,
    'DwmExtendFrameIntoClientArea');
  if not Assigned(MakeDWM) then
    raise Exception.Create(
      'Can''t get DwmExtendFrameIntoClientArea');
end;

As you see the only function you need to import from this library is DwmExtendFrameIntoClientArea. This function allows to extend window border areas to a suitable view. 

It takes two parameters. The first one is window handle and the second one is pointer to a Margins structure.

HRESULT DwmExtendFrameIntoClientArea(  
  HWND hWnd,
  const MARGINS *pMarInset
);

In Delphi this function and structure defines like this:
type
  TMargins = record
    LeftWidth: Integer;
    RightWidth: Integer;
    TopHeight: Integer;
    BottomHeight: Integer;
  end;

var
  MakeDWM: function (Handle: THandle;
      var
AMargins: TMargins): Integer; stdcall;



Monday, September 29, 2008

Fractal Image Compression

Recently I was very interested for fractal image compression. Read about it on Wikipedia (fractals, fractals compression). I start surfing web to look for images compressed with this algorithm and the first image i found was on the www.steckles.com. Author was made a comparison between three image compression algorithms Vector Quantization, Fractal Compression and JPEG. His conclusion was too easy: "Stick with Jpeg, unless you really like bad image quality and long waits". The only thing I don't like in those article was that the examples of images were without evidence of the image size. Here you can find my own dilettantish test :).

Uncompressed image (RAW format 256x256 pix, 8 bit, 64 kb)

JPEG compressed image (JPEG format 256x256 pix, 8 bit, 23 kb)
it was the maximum compression I was obtain of JPEG format

Fractal compressed image (Fractal compression 256x256 pix, 8 bit, 7 kb)

Conclusion:

Yes, fractal compression is very slowly today, especially for big images, but it is easy to see the potential. You can see by sight, a difference in image size and it's quality. I think it is having prospects.  In this little experiment I was compress source image in 9 times. Wikipedia says it will be possible to compress image up to 1000 times without catastrophical loss in quality. Will see :).

Monday, September 22, 2008

PostgreSql Oid to Name (oid2name)

Function gets name of object by oid and its catalog name:
CREATE OR REPLACE FUNCTION oid2name(
  id integer,
  catalog varchar
)
RETURNS varchar AS
$$
SELECT cast(c.name as varchar)
FROM 
  (
  select
    CASE $2
    WHEN 'pg_class' THEN
      (select t.relname as name
       from pg_catalog.pg_class t
       WHERE oid = $1)
    WHEN 'pg_constraint' THEN
       (select t.conname as name
        from pg_catalog.pg_constraint t
        WHERE oid = $1)
    WHEN 'pg_type' THEN
       (select t.typname as name
        from pg_catalog.pg_type t
        WHERE oid = $1)
    WHEN 'pg_conversion' THEN
       (select t.conname as name
        from pg_catalog.pg_conversion t
        WHERE oid = $1) 
    WHEN 'pg_proc' THEN
       (select t.proname as name
        from pg_catalog.pg_proc t
        WHERE oid = $1) 
    WHEN 'pg_rewrite' THEN
       (select t.rulename as name
        from pg_catalog.pg_rewrite t
        WHERE oid = $1)
    WHEN 'pg_trigger' THEN
       (select t.tgname as name
        from pg_catalog.pg_trigger t
        WHERE oid = $1)
    WHEN 'pg_language' THEN
      (select t.lanname as name
       from pg_catalog.pg_language t
       WHERE oid = $1)
    WHEN 'pg_namespace' THEN
      (select t.nspname as name
       from pg_catalog.pg_namespace t  
       WHERE oid = $1)
    END as name
  ) as c
$$
LANGUAGE 'sql'
IMMUTABLE
CALLED ON NULL INPUT
SECURITY INVOKER;

Wednesday, April 16, 2008

First message in blog...

Welcome to my blog.
This is a test message.