Using Reggae to encode jpeg image
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Hello.

    I'm learning how to use Reggae framework to decoding and encoding images, I have read jpeg files successfully, but I can't figure how to create a jpeg image from a rgb array. I have read documentation on MorphOS library, but Muxer and Encoding sections are empty, and there are very few examples about encoding streams with Reggae.

    I have tried to create a memory stream with argb values of my image as first step to create a JPEG image, but it returns a null object, what is the process to create a JPEG using Reggae?
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »08.07.14 - 19:35
    Profile Visit Website
  • MorphOS Developer
    geit
    Posts: 1054 from 2004/9/23
    This one should work:

    Code:

    ULONG Image_Save( STRPTR name, APTR imagedata, ULONG width, ULONG height )
    {
    ULONG result = MSG_ERROR_NOERROR;
    Object *streamobj, *rawvideoobj, *codecobj, *outputobj;
    QUAD slen = width * height * 4;

    debug( SOURCENAME ": Image_ImageSave() - '%s' %08lx (%ld/%ld)n", name, imagedata, width, height );

    if( ( streamobj = NewObject( NULL, "memory.stream", MMA_StreamHandle, (IPTR) imagedata,
    MMA_StreamLength, (IPTR) &slen,
    MMA_MediaType , MMT_PICTURE,
    TAG_DONE ) ) ) {
    if( ( rawvideoobj = NewObject( NULL, "rawvideo.filter", MMA_Video_Width , width,
    MMA_Video_Height, height,
    TAG_DONE ) ) ) {
    MediaSetPort( rawvideoobj, 1, MMA_Port_Format, MMFC_VIDEO_ARGB32 );
    if( MediaConnectTagList( streamobj, 0, rawvideoobj, 0, NULL ) ) {
    if( ( codecobj = MediaBuildFromArgsTagList( "png", rawvideoobj, 1, NULL ) ) ) {
    if( ( outputobj = NewObject( NULL, "file.output", MMA_TaskPriority, 0,
    MMA_StreamName, (ULONG) name,
    //MMA_ErrorCode, &reggae_error,
    TAG_DONE ) ) ) {
    if( MediaConnectTagList( codecobj, 1, outputobj, 0, NULL ) ) {
    DoMethod( outputobj, MMM_SignalAtEnd, (IPTR) FindTask( NULL ), SIGBREAKB_CTRL_C );
    DoMethod( outputobj, MMM_Play );
    Wait( SIGBREAKF_CTRL_C );
    }
    DisposeObject( outputobj );
    }
    DisposeObject( codecobj );
    }
    }
    DisposeObject( rawvideoobj );
    }
    DisposeObject( streamobj );
    }
    debug( SOURCENAME ": Image_ImageSave() - %ldn", result );

    return( result );
    }
  • »08.07.14 - 21:07
    Profile
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    I didn't defined MMA_MediaType when creating a memory stream, but It returns null even with MMA_MediaType defined.

    Is there anything wrong on this code?

    Code:

    QUAD stream_length = width*height*4;
    UBYTE *Buffer;
    Buffer = (UBYTE*)MediaAllocVec(stream_length);
    Object *stream;
    if (stream = NewObject(NULL, "memory.stream",
    MMA_StreamHandle, (IPTR)Buffer,
    MMA_StreamLength, (IPTR)&stream_length,
    MMA_MediaType, MMT_PICTURE,
    TAG_END))
    {
    printf("memory.stream: %in",stream);

    DisposeObject(stream);
    }
    MediaFreeVec(Buffer);
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »09.07.14 - 20:09
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    pegasos-sigi2
    Posts: 265 from 2006/8/31
    Take a look:

    VOID load_picture_odt(APTR buffer,LONG size,struct obj_liste *b)
    {
    Object *source, *player;
    ULONG width;
    ULONG height;
    struct RastPort rp;
    struct BitMap *bm2;
    unsigned char *pic1;
    QUAD stream_length = (QUAD)size;



    if ((MultimediaBase = OpenLibrary("multimedia/multimedia.class", 52)))
    {
    if ((PictureOutputBase = OpenLibrary("multimedia/picture.output", 51)))
    {

    source = MediaNewObjectTags(
    MMA_StreamHandle, (LONG)buffer,
    MMA_StreamLength, (LONG)&stream_length,
    MMA_StreamType, (LONG)"memory.stream",
    MMA_MediaType, MMT_PICTURE,
    TAG_END);

    player = NewObject(NULL, "picture.output", TAG_END);


    if(MediaConnectTagList(source, 0, player, 0, NULL))
    {
    get(player,MMA_Video_Height,&height);
    get(player,MMA_Video_Width,&width);
    bm2 = AllocBitMap(width,height,32,BMF_MINPLANES|BMF_CLEAR,NULL);
    InitRastPort(&rp);
    rp.BitMap = bm2;
    set(player,MMA_Video_RastPort,&rp);
    DoMethod(player,MMM_Play);


    pic1 = (unsigned char *)AllocVec(sizeof(unsigned char *) * (int)width * (int)height * 4,MEMF_ANY | MEMF_CLEAR);
    if (pic1)
    {
    ReadPixelArray(pic1, 0, 0,
    (int)width*4,
    &rp,
    0,
    0,
    (int)width,
    (int)height,
    RECTFMT_ARGB);


    b->buffer = pic1;
    b->width = (int)width;
    b->height = (int)height;
    b->XML = NULL;
    strcpy(b->name,"picture");
    }



    FreeBitMap(bm2);
    }

    if(player) DisposeObject(player);
    if(source) DisposeObject(source);


    CloseLibrary(PictureOutputBase);
    }
    CloseLibrary(MultimediaBase);
    }


    }















    Quote:

    BalrogSoft wrote:
    I didn't defined MMA_MediaType when creating a memory stream, but It returns null even with MMA_MediaType defined.

    Is there anything wrong on this code?

    Code:

    QUAD stream_length = width*height*4;
    UBYTE *Buffer;
    Buffer = (UBYTE*)MediaAllocVec(stream_length);
    Object *stream;
    if (stream = NewObject(NULL, "memory.stream",
    MMA_StreamHandle, (IPTR)Buffer,
    MMA_StreamLength, (IPTR)&stream_length,
    MMA_MediaType, MMT_PICTURE,
    TAG_END))
    {
    printf("memory.stream: %in",stream);

    DisposeObject(stream);
    }
    MediaFreeVec(Buffer);



    Spreedy - The spreedsheet editor of MorphOS
    Calimero - Do you know about the new DTP Program for MorphOS ?
  • »09.07.14 - 22:42
    Profile
  • MorphOS Developer
    zukow
    Posts: 648 from 2005/2/9
    From: Poland
    it's my internal reggae tool using during reggae development
    it has loading/writing/metadata support.

    http://brain.umcs.lublin.pl/~rzookol/download/progressive_tester/

    compile with -noixemul
  • »10.07.14 - 08:14
    Profile Visit Website
  • Order of the Butterfly
    Order of the Butterfly
    BalrogSoft
    Posts: 171 from 2006/10/6
    From: Spain
    Thanks guys, those examples were very helpful, it works perfectly now.
    Balrog Software - AmigaSkool.net
    Mac Mini - MorphOS 3.8 - G4 1.5Ghz - Ati 9200 64 Mb
    Efika - MorphOS 3.6 - Ati 9200 64Mb - 80 Gb HD
    Amiga 1200D - OS 3.9 - Blizzard 603e/240mh
  • »12.07.14 - 10:28
    Profile Visit Website