JPEG in QT & SGI movies

JPEG in QT & SGI movies

Post by Marco Bertin » Thu, 30 Jul 1998 04:00:00



Hi to Everybody !
 I'm having a problem with JPEG compression in QuickTime and SGI .mv
movie files.
When I try to translate a movie frame buffer to a RGB buffer using the
following source code:
-----
short ***
FrameToRGBBuffer(buf,size,width,height)
     unsigned char *buf;
     size_t size;    
     int width,height;
{
  short ***imgbuf;
  int x,y,z,i,depth;

  depth=size/(width*height);

  switch(depth){
  case 4:
    depth=3;

    imgbuf = (short ***)malloc(depth*sizeof(short **));
    for(z=0;z<depth;z++){
      imgbuf[z] = (short **)malloc(height*sizeof(short *));
      for(y=0;y<height;y++){
        imgbuf[z][y] = (short *)malloc(width*sizeof(short));
      }
    }
    i=0;
    for(y=0;y<height;y++){
      for(x=0;x<width;x++){
        imgbuf[0][y][x]=(short)buf[i+3];
        imgbuf[1][y][x]=(short)buf[i+2];
        imgbuf[2][y][x]=(short)buf[i+1];
        i+=4;
      }
    }
    return(imgbuf);

  case 3:
    imgbuf = (short ***)malloc(depth*sizeof(short **));
    for(z=0;z<depth;z++){
      imgbuf[z] = (short **)malloc(height*sizeof(short *));
      for(y=0;y<height;y++){
        imgbuf[z][y] = (short *)malloc(width*sizeof(short));
      }
    }
    i=0;
    for(y=0;y<height;y++){
      for(x=0;x<width;x++){
        imgbuf[0][y][x]=(short)buf[i+2];
        imgbuf[1][y][x]=(short)buf[i+1];
        imgbuf[2][y][x]=(short)buf[i];
        i+=3;
      }
    }
    return(imgbuf);

  case 1:
    imgbuf = (short ***)malloc(1*sizeof(short **));
    imgbuf[0] = (short **)malloc(height*sizeof(short *));
    for(y=0;y<height;y++){
      imgbuf[0][y] = (short *)malloc(width*sizeof(short));
    }
    i=0;
    for(y=0;y<height;y++){
      for(x=0;x<width;x++){
        imgbuf[0][y][x]=(short)buf[i];
        i++;
      }
    }
    return(imgbuf);

  default: printf("Error : there are %d color planes\n",depth);
    return(NULL);
  }

  return(imgbuf);

Quote:}

------------

I don't succed in the conversion, because the function calculates 2
color planes using the:

 depth=size/(width*height);

Where size=dmImageFrameSize(params);

In fact I've tried with a MVC2 movie, and everything works right;
converting the movie to JPEG qt or SGI .mv (using dmconvert) the frame
size is halfed; the movieplayer shows the movies correctly.
I think that it is due to a different image packing format but I cannot
find which one is used.
Is there anyone who can help me with more info or sample code ?

Thank you,
 Marco Bertini

--
| Marco Bertini -  http://dsi.ing.unifi.it/~bertini
| Dipartimento Sistemi & Informatica
| Universita' di Firenze - Ingegneria elettronica
| IAPR - IC Member - http://imago.ing.unibs.it/~iapricgb/

 
 
 

JPEG in QT & SGI movies

Post by Eric J. Grav » Thu, 30 Jul 1998 04:00:00



>Hi to Everybody !
> I'm having a problem with JPEG compression in QuickTime and SGI .mv
>movie files.
>------------

>I don't succed in the conversion, because the function calculates 2
>color planes using the:

> depth=size/(width*height);

>Where size=dmImageFrameSize(params);

>In fact I've tried with a MVC2 movie, and everything works right;
>converting the movie to JPEG qt or SGI .mv (using dmconvert) the frame
>size is halfed; the movieplayer shows the movies correctly.
>I think that it is due to a different image packing format but I cannot
>find which one is used.
>Is there anyone who can help me with more info or sample code ?

You are presumably using the params you obtained from mvGetParams(imgtrack).

You are in fact seeing the correct behavior, because the colorspace of
your JPEG-compressed image track is YUV (YCrCb 4:2:2), which is an
average of 2 bytes per pixel.  (1 byte of luma per pixel; 1 byte of Cr
per 2 pixels; 1 byte of Cb per 2 pixels, or a total of 4 bytes per two
pixels).

I assume that you are using mvReadFrames or mvRenderMovieToImageBuffer.
In that case, the ReadFrames or Render call is probably giving you a
buffer in the XBGR or RGBA or RGBX colorspace. In that case, the params that
you pass to dmImageFrameSize should reflect the format you are *reading*
or *rendering* to, not the format in which the compressed data natively
lives.

So, you should do something like:

tParams = mvGetTrackParams( imgrtrack );
dmParamsCopyAllElems( tParams, renderParams );
dmParamsSetEnum( renderParams, DM_IMAGE_PACKING, DM_IMAGE_PACKING_XBGR );
size = dmImageFrameSize( renderParams );

*NOT*: size = dmIamgeFrameSize( mvGetParams( imgtrack ) );

Please see man mvReadFrames and/or mvRenderMovieToImageBuffer.

-eric

--

 
 
 

1. problem with SGI -> QT movies

Someone here is trying to use the 'makemoov' program from the Quicktime
Movie Exchange Toolkit Version 1.0 to convert SGI RGB images into QT.
The problem is that the images are skewed on the Mac. They seem somehow
"stretched" horizontally, and also offset in the frame so that the image
is clipped at the right margin and "wraps around" to the left margin.

We have tried changing the various 'makemoov' options, without any luck,
so I'm hoping that someone here might have seen this problem and solved
it already.

Thanks for any help.

Mark Sandrock
--
Univ. of Illinois at Urbana-Champaign   "I can find my biography in every
Chemical Sciences Computing Services     fable that I read."
505 S. Mathews Ave., Urbana, IL 61801               --Ralph Waldo Emerson

2. Vector Graphics Library

3. Making QT movies from JPEG files

4. Out of focus image

5. QT movies work on NT but not SGI

6. ATTN: Paint Shop Pro 6 File Format Specification

7. converting QT Mac movies to Windows movies ?

8. A place 2 learn!!!!!!!!!

9. Wanted: SGI's JPEG movie format

10. Jurassic Park movie & SGI

11. Re(2): Jurassic Park movie & SGI

12. SGI rgb to OMF / OMF to SGI movie and AIFF

13. mv2mpeg: SGI-movie to MPEG converter at ftp.sgi.com