home *** CD-ROM | disk | FTP | other *** search
/ Geek 6 / Geek-006.iso / linux / video / xmovie-1.5.3.tar.gz / xmovie-1.5.3.tar / xmovie-1.5.3 / quicktime / atom.c next >
C/C++ Source or Header  |  2000-11-29  |  3KB  |  137 lines

  1. #include <ctype.h>
  2. #include "quicktime.h"
  3.  
  4.  
  5.  
  6.  
  7.  
  8. int quicktime_atom_reset(quicktime_atom_t *atom)
  9. {
  10.     atom->end = 0;
  11.     atom->type[0] = atom->type[1] = atom->type[2] = atom->type[3] = 0;
  12.     return 0;
  13. }
  14.  
  15. int quicktime_atom_read_header(quicktime_t *file, quicktime_atom_t *atom)
  16. {
  17.     char header[10];
  18.     int result;
  19.     long size2;
  20.  
  21.     atom->start = quicktime_position(file);
  22.  
  23.     quicktime_atom_reset(atom);
  24.  
  25.     if(!quicktime_read_data(file, header, HEADER_LENGTH)) return 1;
  26.     result = quicktime_atom_read_type(header, atom->type);
  27.     atom->size = quicktime_atom_read_size(header);
  28.     atom->end = atom->start + atom->size;
  29.  
  30. /* Skip placeholder atom */
  31.     if(quicktime_match_32(atom->type, "wide"))
  32.     {
  33.         atom->start = quicktime_position(file);
  34.         quicktime_atom_reset(atom);
  35.         if(!quicktime_read_data(file, header, HEADER_LENGTH)) return 1;
  36.         result = quicktime_atom_read_type(header, atom->type);
  37.         atom->size -= 8;
  38.         if(!atom->size)
  39.         {
  40. /* Wrapper ended.  Get new atom size */
  41.             atom->size = quicktime_atom_read_size(header);
  42.         }
  43.         atom->end = atom->start + atom->size;
  44.     }
  45.     else
  46. /* Get extended size */
  47.     if(atom->size == 1)
  48.     {
  49.         if(!quicktime_read_data(file, header, HEADER_LENGTH)) return 1;
  50.         atom->size = quicktime_atom_read_size64(header);
  51.     }
  52.  
  53. /*printf("%c%c%c%c\n", atom->type[0], atom->type[1], atom->type[2], atom->type[3]); */
  54.     return result;
  55. }
  56.  
  57. void quicktime_atom_write_header(quicktime_t *file, quicktime_atom_t *atom, char *text)
  58. {
  59.     atom->start = quicktime_position(file);
  60.     quicktime_write_int32(file, 0);
  61.     quicktime_write_char32(file, text);
  62. }
  63.  
  64. void quicktime_atom_write_footer(quicktime_t *file, quicktime_atom_t *atom)
  65. {
  66.     atom->end = quicktime_position(file);
  67.     quicktime_set_position(file, atom->start);
  68.     quicktime_write_int32(file, atom->end - atom->start);
  69.     quicktime_set_position(file, atom->end);
  70. }
  71.  
  72. int quicktime_atom_is(quicktime_atom_t *atom, char *type)
  73. {
  74.     if(atom->type[0] == type[0] &&
  75.         atom->type[1] == type[1] &&
  76.         atom->type[2] == type[2] &&
  77.         atom->type[3] == type[3])
  78.     return 1;
  79.     else
  80.     return 0;
  81. }
  82.  
  83. long quicktime_atom_read_size(char *data)
  84. {
  85.     unsigned long result;
  86.     unsigned long a, b, c, d;
  87.     
  88.     a = (unsigned char)data[0];
  89.     b = (unsigned char)data[1];
  90.     c = (unsigned char)data[2];
  91.     d = (unsigned char)data[3];
  92.  
  93.     result = (a<<24) | (b<<16) | (c<<8) | d;
  94.     if(result < HEADER_LENGTH) result = HEADER_LENGTH;
  95.     return (long)result;
  96. }
  97.  
  98. long quicktime_atom_read_size64(char *data)
  99. {
  100.     unsigned long result;
  101.     unsigned long a, b, c, d, e, f, g, h;
  102.     
  103.     a = (unsigned char)data[0];
  104.     b = (unsigned char)data[1];
  105.     c = (unsigned char)data[2];
  106.     d = (unsigned char)data[3];
  107.     e = (unsigned char)data[0];
  108.     f = (unsigned char)data[1];
  109.     g = (unsigned char)data[2];
  110.     h = (unsigned char)data[3];
  111.  
  112.     result = (a<<56) | (b<<48) | (c<<40) | (d<<32) | (e<<24) | (f<<16) | (g<<8) | h;
  113.     if(result < HEADER_LENGTH) result = HEADER_LENGTH;
  114.     return (long)result;
  115. }
  116.  
  117. int quicktime_atom_read_type(char *data, char *type)
  118. {
  119.     type[0] = data[4];
  120.     type[1] = data[5];
  121.     type[2] = data[6];
  122.     type[3] = data[7];
  123.  
  124. /*printf("%c%c%c%c ", type[0], type[1], type[2], type[3]); */
  125. /* need this for quicktime_check_sig */
  126.     if(isalpha(type[0]) && isalpha(type[1]) && isalpha(type[2]) && isalpha(type[3]))
  127.     return 0;
  128.     else
  129.     return 1;
  130. }
  131.  
  132. int quicktime_atom_skip(quicktime_t *file, quicktime_atom_t *atom)
  133. {
  134.     return quicktime_set_position(file, atom->end);
  135. /*    return fseek(file->stream, atom->end, SEEK_SET); */
  136. }
  137.