"Fossies" - the Fresh Open Source Software Archive

Member "quicktime4linux-2.3/libmjpeg.h" (3 Feb 2008, 6123 Bytes) of package /linux/privat/old/quicktime4linux-2.3-src.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  * This library is free software; you can redistribute it and/or modify it
    3  * under the terms of the GNU Lesser General Public License as published
    4  * by the Free Software Foundation; either version 2 of the License, or
    5  * (at your option) any later version.
    6  * 
    7  * This library is distributed in the hope that it will be useful, but
    8  * WITHOUT ANY WARRANTY; without even the implied warranty of
    9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   10  * Lesser General Public License for more details.
   11  * 
   12  * You should have received a copy of the GNU Lesser General Public
   13  * License along with this library; if not, write to the Free Software
   14  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 
   15  * USA
   16  */
   17  
   18  #ifndef LIBMJPEG_H
   19 #define LIBMJPEG_H
   20 
   21 
   22 /* Motion JPEG library */
   23 
   24 
   25 
   26 #ifdef __cplusplus
   27 extern "C" {
   28 #endif
   29 
   30 
   31 
   32 #include <stdio.h>
   33 #include "jpeglib.h"
   34 #include <png.h>              /* Need setjmp.h as included by png.h */
   35 #include "pthread.h"
   36 #include <setjmp.h>
   37 
   38 #define MAXFIELDS 2
   39 #define QUICKTIME_MJPA_MARKSIZE 40
   40 #define QUICKTIME_JPEG_TAG 0x6d6a7067
   41 
   42 
   43 struct mjpeg_error_mgr {
   44   struct jpeg_error_mgr pub;    /* "public" fields */
   45   jmp_buf setjmp_buffer;    /* for return to caller */
   46 };
   47 
   48 typedef struct mjpeg_error_mgr* mjpeg_error_ptr;
   49 
   50 #ifndef __alpha__
   51 typedef struct
   52 {
   53 } mjpeg_lml_hdr;
   54 
   55 typedef struct
   56 {
   57 } mjpeg_dc10_hdr;
   58 #endif
   59 
   60 
   61 // The compressor structure is shared between decompressors and compressors
   62 typedef struct
   63 {
   64     void *mjpeg;
   65     int instance;
   66     unsigned char *output_buffer;    /* Buffer for MJPEG output */
   67     long output_size;     /* Size of image stored in buffer */
   68     long output_allocated;    /* Allocated size of output buffer */
   69     struct jpeg_decompress_struct jpeg_decompress;
   70     struct jpeg_compress_struct jpeg_compress;
   71     struct mjpeg_error_mgr jpeg_error;
   72     pthread_t tid;   /* ID of thread */
   73     pthread_mutex_t input_lock, output_lock;
   74     int done;     /* Flag to end */
   75     int error;
   76 // Pointer to uncompressed YUV rows
   77 // [3 planes][downsampled rows][downsampled pixels]
   78     unsigned char **rows[3];
   79 /* Temp rows for each MCU */
   80     unsigned char **mcu_rows[3];
   81 /* Height of the field */
   82     int field_h; 
   83     int coded_field_h; 
   84 } mjpeg_compressor;
   85 
   86 typedef struct
   87 {
   88 // Dimensions of user frame buffer
   89     int output_w;
   90     int output_h;
   91 // Dimensions for encoder frame buffer
   92     int coded_w, coded_h;
   93     int fields;
   94     int quality;
   95     int use_float;
   96     int kludge;
   97     int cpus;
   98 // Color model of user interface.
   99     int color_model;
  100 // Color model of compressed data.  Since MJPA streams use 4:2:0
  101     int jpeg_color_model;
  102 // To save on colormodel permutations, we flag grayscale separately and
  103 // just set U and V to 0x80.
  104     int greyscale;
  105 // Error in compression process
  106     int error;
  107 
  108     mjpeg_compressor *compressors[MAXFIELDS];
  109     mjpeg_compressor *decompressors[MAXFIELDS];
  110 
  111 // Temp frame for interlacing
  112 // [3 planes][downsampled rows][downsampled pixels]
  113     unsigned char *temp_data;
  114     unsigned char **temp_rows[3];
  115     unsigned char **row_argument, *y_argument, *u_argument, *v_argument;
  116 
  117 // Buffer passed to user
  118 // This can contain one progressive field or two fields with headers
  119     unsigned char *output_data;
  120     long output_size;
  121     long output_allocated;
  122 // Offset to field2 in output_data
  123     long output_field2;
  124 // Buffer passed from user
  125     unsigned char *input_data;
  126     long input_size;
  127 // Offset to field2 in input_data
  128     long input_field2;
  129     int deinterlace;
  130     int rowspan;
  131 
  132 // Workarounds for thread unsafe libraries
  133     pthread_mutex_t decompress_init;
  134     int decompress_initialized;
  135 } mjpeg_t;
  136 
  137 
  138 
  139 
  140 
  141 // Entry points
  142 mjpeg_t* mjpeg_new(int w, 
  143     int h, 
  144     int fields);
  145 void mjpeg_delete(mjpeg_t *mjpeg);
  146 
  147 void mjpeg_set_quality(mjpeg_t *mjpeg, int quality);
  148 void mjpeg_set_float(mjpeg_t *mjpeg, int use_float);
  149 // This is useful when producing realtime NTSC output for a JPEG board.
  150 void mjpeg_set_deinterlace(mjpeg_t *mjpeg, int value);
  151 void mjpeg_set_cpus(mjpeg_t *mjpeg, int cpus);
  152 void mjpeg_set_rowspan(mjpeg_t *mjpeg, int rowspan);
  153 
  154 
  155 int mjpeg_get_fields(mjpeg_t *mjpeg);
  156 
  157 int mjpeg_decompress(mjpeg_t *mjpeg, 
  158     unsigned char *buffer, 
  159     long buffer_len,
  160     long input_field2,  
  161     unsigned char **row_pointers, 
  162     unsigned char *y_plane, 
  163     unsigned char *u_plane, 
  164     unsigned char *v_plane,
  165     int color_model,
  166     int cpus);
  167 
  168 int mjpeg_compress(mjpeg_t *mjpeg, 
  169     unsigned char **row_pointers, 
  170     unsigned char *y_plane, 
  171     unsigned char *u_plane, 
  172     unsigned char *v_plane,
  173     int color_model,
  174     int cpus);
  175 
  176 // Get buffer information after compressing
  177 unsigned char* mjpeg_output_buffer(mjpeg_t *mjpeg);
  178 // Called by decoder
  179 long mjpeg_output_field2(mjpeg_t *mjpeg);
  180 // Called before inserting markers by user
  181 long mjpeg_output_size(mjpeg_t *mjpeg);
  182 // Called before inserting markers by user
  183 long mjpeg_output_allocated(mjpeg_t *mjpeg);
  184 // Called after inserting markers by user to increase the size
  185 void mjpeg_set_output_size(mjpeg_t *mjpeg, long output_size);
  186 
  187 // Retrieve width and height from a buffer of JPEG data
  188 void mjpeg_video_size(unsigned char *data, long data_size, int *w, int *h);
  189 
  190 
  191 
  192 // Calculate marker contents and insert them into a buffer.
  193 // Reallocates the buffer if it isn't big enough so make sure it's big enough
  194 // when passing VFrames.
  195 // field2_offset is set to -1 if the markers already exist or the field offset
  196 // if markers don't already exist.
  197 void mjpeg_insert_quicktime_markers(unsigned char **buffer, 
  198     long *buffer_size, 
  199     long *buffer_allocated,
  200     int fields,
  201     long *field2_offset);
  202 void mjpeg_insert_avi_markers(unsigned char **buffer, 
  203     long *buffer_size, 
  204     long *buffer_allocated,
  205     int fields,
  206     long *field2_offset);
  207 
  208 // Get the second field offset from the markers
  209 long mjpeg_get_buz_field2(unsigned char *buffer, long buffer_size);
  210 long mjpeg_get_lml33_field2(unsigned char *buffer, long buffer_size);
  211 long mjpeg_get_quicktime_field2(unsigned char *buffer, long buffer_size);
  212 // Field dominance is retrieved for the jpeg decoder.  AVI stores field
  213 // dominance in each field.
  214 long mjpeg_get_avi_field2(unsigned char *buffer, 
  215     long buffer_size,
  216     int *field_dominance);
  217 long mjpeg_get_field2(unsigned char *buffer, long buffer_size);
  218 
  219 #ifdef __cplusplus
  220 }
  221 #endif
  222 
  223 #endif