File: libmjpeg.h

package info (click to toggle)
libquicktime 2%3A1.2.4-17
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,832 kB
  • sloc: ansic: 55,312; sh: 10,976; makefile: 473; sed: 16
file content (168 lines) | stat: -rw-r--r-- 5,205 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*******************************************************************************
 libmjpeg.h

 libquicktime - A library for reading and writing quicktime/avi/mp4 files.
 http://libquicktime.sourceforge.net

 Copyright (C) 2002 Heroine Virtual Ltd.
 Copyright (C) 2002-2011 Members of the libquicktime project.

 This library is free software; you can redistribute it and/or modify it under
 the terms of the GNU Lesser General Public License as published by the Free
 Software Foundation; either version 2.1 of the License, or (at your option)
 any later version.

 This library is distributed in the hope that it will be useful, but WITHOUT
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 details.

 You should have received a copy of the GNU Lesser General Public License along
 with this library; if not, write to the Free Software Foundation, Inc., 51
 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*******************************************************************************/ 
 
#ifndef LIBMJPEG_H
#define LIBMJPEG_H

/* use a thread to run compressors / decompressors */
// #define USE_THREAD 0

#ifdef __cplusplus
extern "C" {
#endif

#include <stdio.h>
#include <jpeglib.h>
#include <setjmp.h>

#define MAXFIELDS 2
#define QUICKTIME_MJPA_MARKSIZE 40
#define QUICKTIME_JPEG_TAG 0x6d6a7067



  struct mjpeg_error_mgr {
  struct jpeg_error_mgr pub;	/* "public" fields */
  jmp_buf setjmp_buffer;	/* for return to caller */
    };

  typedef struct mjpeg_error_mgr* mjpeg_error_ptr;

  // The compressor structure is shared between decompressors and compressors
  typedef struct
    {
    void *mjpeg;
    //    int instance;
    unsigned char *output_buffer;    /* Buffer for MJPEG output */
    long output_size;     /* Size of image stored in buffer */
    long output_allocated;    /* Allocated size of output buffer */
    struct jpeg_decompress_struct jpeg_decompress;
    struct jpeg_compress_struct jpeg_compress;
    struct mjpeg_error_mgr jpeg_error;
    int error;
    // Pointer to uncompressed YUV rows
    // [3 planes][downsampled rows][downsampled pixels]
    unsigned char **rows[3];
    /* Temp rows for each MCU */
    unsigned char **mcu_rows[3];
    /* Height of the field (padded value) */
    int field_h; 

    /* Output heights of the fields (can be different for both fields) */
    int field_heights[MAXFIELDS];
    
    } mjpeg_compressor;

  typedef struct
    {
    // Dimensions of user frame buffer
    int output_w;
    int output_h;
    // Dimensions for encoder frame buffer
    int coded_w, coded_w_uv, coded_h;
    int fields;
    int quality;
    int use_float;
    // Color model of compressed data.
    int jpeg_color_model;
    // Error in compression process
    int error;

    mjpeg_compressor * compressor;
    mjpeg_compressor * decompressor;

    // Temp frame for interlacing
    // [3 planes][downsampled rows][downsampled pixels]
    unsigned char *temp_data;
    unsigned char **temp_rows[3];
    //	unsigned char *y_argument, *u_argument, *v_argument;

    // Buffer passed to user
    // This can contain one progressive field or two fields with headers
    unsigned char *output_data;
    long output_size;
    long output_allocated;
    // Offset to field2 in output_data
    long output_field2;
    // Buffer passed from user
    unsigned char *input_data;
    long input_size;
    // Offset to field2 in input_data
    long input_field2;
    int rowspan, rowspan_uv;

    // Bottom first needs special treatment
    int bottom_first;
        
    } mjpeg_t;





  // Entry points
  mjpeg_t* mjpeg_new(int w, int h, int fields, int cmodel);
  void mjpeg_delete(mjpeg_t *mjpeg);

  void mjpeg_set_quality(mjpeg_t *mjpeg, int quality);
  void mjpeg_set_float(mjpeg_t *mjpeg, int use_float);
  // This is useful when producing realtime NTSC output for a JPEG board.
  void mjpeg_set_rowspan(mjpeg_t *mjpeg, int rowspan, int rowspan_uv);


  int mjpeg_get_fields(mjpeg_t *mjpeg);

  int mjpeg_decompress(mjpeg_t *mjpeg, 
                       unsigned char *buffer, 
                       long buffer_len,
                       long input_field2);

  void mjpeg_get_frame(mjpeg_t * mjpeg, uint8_t ** row_pointers);


  int mjpeg_compress(mjpeg_t *mjpeg, 
                     unsigned char **row_pointers);

  // Get buffer information after compressing
  unsigned char* mjpeg_output_buffer(mjpeg_t *mjpeg);
  long mjpeg_output_field2(mjpeg_t *mjpeg);
  long mjpeg_output_size(mjpeg_t *mjpeg);

  // Calculate marker contents and insert them into a buffer.
  // Reallocates the buffer if it isn't big enough so make sure it's big enough
  // when passing VFrames.
  void mjpeg_insert_quicktime_markers(unsigned char **buffer, 
                                      long *buffer_size, 
                                      long *buffer_allocated,
                                      int fields,
                                      long *field2_offset);

  // Get the second field offset from the markers
  long mjpeg_get_quicktime_field2(unsigned char *buffer, long buffer_size);

#ifdef __cplusplus
}
#endif

#endif