Seite 1 von 1

LZO

Verfasst: Mi Mär 09, 2011 9:09 pm
von gucky
Hallo,

ich wollte mal fragen, ob jemand schonmal was mit der datenkompressions-library LZO etwas gemacht hat.
da ich im internet nichts brauchbares finden konnte, wollte ich einmal fragen, ob jemand hier etwas mit dieser lib gemacht hat und mir kurz ein beispiel geben könnte, wie man es benutzt, da ich aus dem beispiel nicht schlau werde.

mfg

gucky

Re: LZO

Verfasst: Mi Mär 09, 2011 9:17 pm
von Xin
gucky hat geschrieben:ich wollte mal fragen, ob jemand schonmal was mit der datenkompressions-library LZO etwas gemacht hat.
da ich im internet nichts brauchbares finden konnte, wollte ich einmal fragen, ob jemand hier etwas mit dieser lib gemacht hat und mir kurz ein beispiel geben könnte, wie man es benutzt, da ich aus dem beispiel nicht schlau werde.
Ich habe mal einen Lempel-Ziv-Algorithmus (LZ77) spaßeshalber implementiert. Zumindest begann es damit, dass es Spaß machen sollte ;-)
Mit einer LZO-Lib habe ich noch nichts ausprobiert.

Wirf doch mal ein paar Links rein und eventuell das Beispiel mit der Stelle, die Dir unverständlich ist.

Re: LZO

Verfasst: Do Mär 10, 2011 8:41 pm
von gucky
ok
hier ein beispiel:

Code: Alles auswählen

#include "lzo/lzoconf.h"
#include "lzo/lzo1x.h"

/* portability layer */
static const char *progname = NULL;
#define WANT_LZO_MALLOC 1
#define WANT_XMALLOC 1
#include "examples/portab.h"


/* We want to compress the data block at 'in' with length 'IN_LEN' to
 * the block at 'out'. Because the input block may be incompressible,
 * we must provide a little more output space in case that compression
 * is not possible.
 */

#ifndef IN_LEN
#define IN_LEN      (128*1024L)
#endif
#define OUT_LEN     (IN_LEN + IN_LEN / 16 + 64 + 3)


/*************************************************************************
//
**************************************************************************/

int __lzo_cdecl_main main(int argc, char *argv[])
{
    int r;
    lzo_bytep in;
    lzo_bytep out;
    lzo_voidp wrkmem;
    lzo_uint in_len;
    lzo_uint out_len;
    lzo_uint new_len;

    if (argc < 0 && argv == NULL)   /* avoid warning about unused args */
        return 0;

    printf("\nLZO real-time data compression library (v%s, %s).\n",
           lzo_version_string(), lzo_version_date());
    printf("Copyright (C) 1996-2010 Markus Franz Xaver Johannes Oberhumer\nAll Rights Reserved.\n\n");

/*
 * Step 1: initialize the LZO library
 */
    if (lzo_init() != LZO_E_OK)
    {
        printf("internal error - lzo_init() failed !!!\n");
        printf("(this usually indicates a compiler bug - try recompiling\nwithout optimizations, and enable '-DLZO_DEBUG' for diagnostics)\n");
        return 4;
    }

/*
 * Step 2: allocate blocks and the work-memory
 */
    in = (lzo_bytep) xmalloc(IN_LEN);
    out = (lzo_bytep) xmalloc(OUT_LEN);
    wrkmem = (lzo_voidp) xmalloc(LZO1X_1_MEM_COMPRESS);
    if (in == NULL || out == NULL || wrkmem == NULL)
    {
        printf("out of memory\n");
        return 3;
    }

/*
 * Step 3: prepare the input block that will get compressed.
 *         We just fill it with zeros in this example program,
 *         but you would use your real-world data here.
 */
    in_len = IN_LEN;
    lzo_memset(in,0,in_len);

/*
 * Step 4: compress from 'in' to 'out' with LZO1X-1
 */
    r = lzo1x_1_compress(in,in_len,out,&out_len,wrkmem);
    if (r == LZO_E_OK)
        printf("compressed %lu bytes into %lu bytes\n",
            (unsigned long) in_len, (unsigned long) out_len);
    else
    {
        /* this should NEVER happen */
        printf("internal error - compression failed: %d\n", r);
        return 2;
    }
    /* check for an incompressible block */
    if (out_len >= in_len)
    {
        printf("This block contains incompressible data.\n");
        return 0;
    }

    lzo_free(wrkmem);
    lzo_free(out);
    lzo_free(in);
    printf("Simple compression test passed.\n");
    return 0;
}
mein problem liegt beim lzo_memset() (beim step 3)
ich versteh nicht, wwas es genau machen soll, und dadurch auch nicht, wie ich meine sachen zum kompressieren darein bekomme

hier noch die "doku": http://www.oberhumer.com/opensource/lzo/lzodoc.php

Re: LZO

Verfasst: Do Mär 10, 2011 9:19 pm
von MoonGuy
gucky hat geschrieben:ok
hier ein beispiel:

edit by Xin: FullQuote des Codes entfernt

mein problem liegt beim lzo_memset() (beim step 3)
ich versteh nicht, wwas es genau machen soll, und dadurch auch nicht, wie ich meine sachen zum kompressieren darein bekomme

hier noch die "doku": http://www.oberhumer.com/opensource/lzo/lzodoc.php
Falls das so agiert, wie ein normaler memset, brauche ich gar nicht in die Doku zu schauen. Setzt alle Bytes innerhalb des "gepointeten" Bereiches auf den Parameter 2. In diesem Fall der Wert 0. Also wird das ganze initialisiert mit 0.

Re: LZO

Verfasst: Do Mär 10, 2011 10:41 pm
von Dirty Oerti
We just fill it with zeros in this example program,
but you would use your real-world data here.
Da steht es doch :)
Anstatt dieses memset musst du also deine Daten in "in" bekommen :)