~ubuntu-branches/ubuntu/vivid/ghostscript/vivid-updates

« back to all changes in this revision

Viewing changes to openjpeg/libopenjpeg/cidx_manager.c

  • Committer: Package Import Robot
  • Author(s): Till Kamppeter
  • Date: 2014-05-02 15:48:44 UTC
  • mfrom: (1.1.43)
  • Revision ID: package-import@ubuntu.com-20140502154844-c401rxx0cce8gm0q
Tags: 9.14~dfsg-0ubuntu1
* New upstream release
   - Ghostscript 9.14
   - pdfwrite now uses the same color management engine as Ghostscript
     rendering devices (by default LCMS2). This provides much better
     control over color conversion and color management generally, but
     will result in some small color differences when compared to the
     old system.
     It is no longer necessary to specify UseCIEColor (and we very much
     encourage you not to do this) or the ProcessColorModel if you want
     to convert a PDF file to a specific color space, simply set the
     ColorConversionStrategy appropriately.
     We do not expect any major problems to arise with this new code,
     but for the duration of this release a new switch -dPDFUseOldCMS
     is available which will restore the old color management. See:
     Color Conversion and Management
     Please note that due to constraints of the PDF/A-1 specification,
     the new color management does not yet apply when producing PDF/A
     files.
   - A new device 'eps2write' has been added which allows for the
     creation of EPS files using the ps2write device instead of the old
     (deprecated and removed) pswrite device. This produces
     considerably better quality EPS files than the old epswrite device
     which is now also deprecated and will be removed in a future
     release.
   - ps2write now has a feature to allow customisation of the output
     for specific devices. Please see PSDocOptions and PSPageOptions
     described in ps2ps2.htm Additional Distiller Params
   - Ghostscript now reduces memory usage when processing PDF files
     that use transparency and output is to display devices such as
     Windows display or x11 (i.e. devices that are strictly full
     framebuffer devices), and to high level vector devices that cannot
     reproduce the PDF transparency model, such as the ps2write device
     or pdfwrite when 'flattening' to PDF 1.3 or earlier
     (-dCompatibilityLevel=1.3). This uses banding (clist) files to
     render the transparent areas in bands to reduce memory use, and
     unlike the existing page level banding, this is hidden from the
     target device.
   - Ghostscript can now collect information for pages in temp files
     (in Ghostscript's clist format), then render and output pages for
     the job in arbitrary order, including normal, reverse, odd, even,
     or any order or subset of the pages. This is controlled with the
     --saved-page=___ option. (Note that this only applies to rendering
     devices, and not high level devices such as pdfwrite and
     ps2write.) See: Deferred Page Rendering
   - The Ghostscript device architecture has been extended so that,
     when rendering bands into multiple threads, it is now possible to
     perform post-processing in multiple threads, such as downscale,
     post-render halftoning, or compression. Previously, post
     processing was only possible in the single main thread. This can
     improve performance significantly.
   - Ghostscript has a new "pwgraster" output device for PWG Raster
     output
   - The CUPS device now has improved support for PPD-less printing
   - Plus the usual round of bug fixes, compatibility changes, and
     incremental improvements.
* debian/patches/020140502-0ccf329-fix-fpng-device-build-handle-shared-zlib.patch:
  Fix fpng device build handle for shared zlib (Upstream bug #695113).
* debian/patches/020130903-5ae4180-ps-interpreter-dont-interpolate-imagemask-data-for-high-level-devices.patch,
  debian/patches/020131023-ad3e3ed-handle-type-0-font-in-annotation.patch,
  debian/patches/020131127-87a7fd8-cups-pwg-raster-output-ppd-less-support.patch,
  debian/patches/020131218-5ddd13e-ps2write-dont-emit-a-page-size-change-if-the-last-request-failed.patch,
  debian/patches/020131219-d997bc4-pwgraster-output-device.patch,
  debian/patches/020140313-095ae57-ps2write-fix-missing-beginresource-comment-for-fontfile-objects.patch,
  debian/patches/020140313-5d6b18a-set-correct-portrait-landscape-orientation-on-pcl-5ce.patch,
  debian/patches/020140313-6498483-ps2write-fix-a-dsc-comment.patch,
  debian/patches/020140428-f4584b0-skip-unsupported-font-files.patch:
  Removed patches backported from upstream.
* debian/patches/020140324-b780ff0-protection-against-pxl-segfault-with-image-data-without-colorspace-info.patch,
  debian/patches/020140331-4b44b41-pxlcolor-support-jpeg-in-output.patch,
  debian/patches/020140331-41ab485-pxl-transform-deep-images-with-icc-transform-to-emit-high-level-images.patch,
  debian/patches/1002_pxl-make-dicctransform-default.patch: Refreshed with
  quilt.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 * POSSIBILITY OF SUCH DAMAGE.
30
30
 */
31
31
 
32
 
#include <stdio.h>
33
 
#include <stdlib.h>
34
32
#include "opj_includes.h"
35
33
 
36
34
 
41
39
 * @param[in] clen length of j2k codestream
42
40
 * @param[in] cio  file output handle
43
41
 */
44
 
void write_cptr(int coff, int clen, opj_cio_t *cio);
45
 
 
46
 
 
47
 
/* 
48
 
 * Write main header index table (box)
49
 
 *
50
 
 * @param[in] coff offset of j2k codestream
51
 
 * @param[in] cstr_info codestream information
52
 
 * @param[in] cio  file output handle
53
 
 * @return         length of mainmhix box
54
 
 */
55
 
int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio);
56
 
 
57
 
 
58
 
/* 
59
 
 * Check if EPH option is used
60
 
 *
61
 
 * @param[in] coff    offset of j2k codestream
62
 
 * @param[in] markers marker information
63
 
 * @param[in] marknum number of markers
64
 
 * @param[in] cio     file output handle
65
 
 * @return            true if EPH is used
66
 
 */
67
 
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio);
68
 
 
69
 
 
70
 
int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen)
 
42
 
 
43
void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
 
44
              opj_event_mgr_t * p_manager );
 
45
 
 
46
 
 
47
 
 
48
 
 
49
 
 
50
int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
 
51
              opj_event_mgr_t * p_manager )
71
52
{
72
 
  int len, i, lenp;
 
53
  int i;
 
54
  OPJ_OFF_T lenp;
 
55
  OPJ_UINT32 len;
73
56
  opj_jp2_box_t *box;
74
57
  int num_box = 0;
75
 
  opj_bool  EPHused;
76
 
  (void)image; /* unused ? */
 
58
  OPJ_BOOL  EPHused;
 
59
  OPJ_BYTE l_data_header [4];
77
60
 
78
61
  lenp = -1;
79
62
  box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
81
64
  for (i=0;i<2;i++){
82
65
  
83
66
    if(i)
84
 
      cio_seek( cio, lenp);
85
 
 
86
 
    lenp = cio_tell( cio);
87
 
 
88
 
    cio_skip( cio, 4);              /* L [at the end] */
89
 
    cio_write( cio, JPIP_CIDX, 4);  /* CIDX           */
90
 
    write_cptr( offset, cstr_info.codestream_size, cio);
91
 
 
92
 
    write_manf( i, num_box, box, cio);
 
67
      opj_stream_seek(cio,lenp,p_manager);
 
68
 
 
69
 
 
70
    lenp = opj_stream_tell (cio);
 
71
 
 
72
    opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
 
73
 
 
74
    opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
 
75
    opj_stream_write_data(cio,l_data_header,4,p_manager);
 
76
 
 
77
    opj_write_cptr( offset, cstr_info.codestream_size, cio,p_manager);
 
78
 
 
79
    opj_write_manf( i, num_box, box, cio,p_manager);
93
80
    
94
81
    num_box = 0;
95
 
    box[num_box].length = write_mainmhix( offset, cstr_info, cio);
 
82
    box[num_box].length = opj_write_mainmhix( offset, cstr_info, cio,p_manager);
96
83
    box[num_box].type = JPIP_MHIX;
97
84
    num_box++;
98
85
 
99
 
    box[num_box].length = write_tpix( offset, cstr_info, j2klen, cio);
 
86
    box[num_box].length = opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
100
87
    box[num_box].type = JPIP_TPIX;
101
88
    num_box++;
102
89
      
103
 
    box[num_box].length = write_thix( offset, cstr_info, cio);
 
90
    box[num_box].length = opj_write_thix( offset, cstr_info, cio, p_manager);
104
91
    box[num_box].type = JPIP_THIX;
105
92
    num_box++;
106
93
 
107
 
    EPHused = check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio);
 
94
    EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager);
108
95
      
109
 
    box[num_box].length = write_ppix( offset, cstr_info, EPHused, j2klen, cio);
 
96
    box[num_box].length = opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
110
97
    box[num_box].type = JPIP_PPIX;
111
98
    num_box++;
112
99
    
113
 
    box[num_box].length = write_phix( offset, cstr_info, EPHused, j2klen, cio);
 
100
    box[num_box].length = opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
114
101
    box[num_box].type = JPIP_PHIX;
115
102
    num_box++;
116
103
      
117
 
    len = cio_tell( cio)-lenp;
118
 
    cio_seek( cio, lenp);
119
 
    cio_write( cio, len, 4);        /* L             */
120
 
    cio_seek( cio, lenp+len);
 
104
    len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
 
105
    opj_stream_seek(cio, lenp,p_manager);
 
106
    opj_write_bytes(l_data_header,len,4);/* L  */
 
107
    opj_stream_write_data(cio,l_data_header,4,p_manager);
 
108
    opj_stream_seek(cio, lenp+len,p_manager);
121
109
  }
122
110
 
123
111
  opj_free( box);
125
113
  return len;
126
114
}
127
115
 
128
 
void write_cptr(int coff, int clen, opj_cio_t *cio)
 
116
 
 
117
 
 
118
void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
 
119
              opj_event_mgr_t * p_manager )
129
120
{
130
 
  int len, lenp;
131
 
 
132
 
  lenp = cio_tell( cio);
133
 
  cio_skip( cio, 4);               /* L [at the end]     */
134
 
  cio_write( cio, JPIP_CPTR, 4);   /* T                  */
135
 
  cio_write( cio, 0, 2);           /* DR  A PRECISER !!  */
136
 
  cio_write( cio, 0, 2);           /* CONT               */
137
 
  cio_write( cio, coff, 8);    /* COFF A PRECISER !! */
138
 
  cio_write( cio, clen, 8);    /* CLEN               */
139
 
  len = cio_tell( cio) - lenp;
140
 
  cio_seek( cio, lenp);
141
 
  cio_write( cio, len, 4);         /* L                  */
142
 
  cio_seek( cio, lenp+len);
 
121
  OPJ_BYTE l_data_header [3*8];
 
122
  OPJ_UINT32 len;
 
123
  OPJ_OFF_T lenp;
 
124
 
 
125
 
 
126
  lenp = opj_stream_tell(cio);
 
127
  opj_stream_skip( cio, 4, p_manager);               /* L [at the end]     */
 
128
  opj_write_bytes( l_data_header, JPIP_CPTR, 4);   /* T                  */
 
129
  opj_write_bytes( l_data_header+4, 0, 2);           /* DR  A PRECISER !!  */
 
130
  opj_write_bytes( l_data_header+6, 0, 2);           /* CONT               */
 
131
  opj_write_bytes( l_data_header+8, coff, 8);    /* COFF A PRECISER !! */
 
132
  opj_write_bytes( l_data_header+16, clen, 8);    /* CLEN               */
 
133
  opj_stream_write_data(cio,l_data_header,3*8,p_manager);
 
134
 
 
135
  len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
 
136
  opj_stream_seek(cio,lenp,p_manager);
 
137
  opj_write_bytes(l_data_header, len, 4);         /* L                  */
 
138
  opj_stream_write_data(cio,l_data_header,4,p_manager);
 
139
  opj_stream_seek(cio, lenp+len,p_manager);
 
140
 
143
141
}
144
142
 
145
 
void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio)
 
143
 
 
144
 
 
145
void opj_write_manf(int second, 
 
146
                    int v, 
 
147
                    opj_jp2_box_t *box, 
 
148
                    opj_stream_private_t *cio,
 
149
                    opj_event_mgr_t * p_manager )
146
150
{
147
 
  int len, lenp, i;
 
151
  OPJ_BYTE l_data_header [4];
 
152
  int i;
 
153
  OPJ_UINT32 len;
 
154
  OPJ_OFF_T lenp;
148
155
  
149
 
  lenp = cio_tell( cio); 
150
 
  cio_skip( cio, 4);                         /* L [at the end]                    */
151
 
  cio_write( cio, JPIP_MANF,4);              /* T                                 */
 
156
  lenp = opj_stream_tell(cio);
 
157
  opj_stream_skip( cio, 4, p_manager);             /* L [at the end]     */
 
158
  opj_write_bytes( l_data_header, JPIP_MANF, 4);   /* T                  */
 
159
  opj_stream_write_data(cio,l_data_header,4,p_manager);
152
160
 
153
161
  if (second){                          /* Write only during the second pass */
154
162
    for( i=0; i<v; i++){
155
 
      cio_write( cio, box[i].length, 4);  /* Box length                     */ 
156
 
      cio_write( cio, box[i].type, 4); /* Box type                       */
 
163
      opj_write_bytes( l_data_header, box[i].length, 4); /* Box length                     */
 
164
      opj_stream_write_data(cio,l_data_header,4,p_manager);
 
165
      opj_write_bytes( l_data_header, box[i].type, 4); /* Box type                       */
 
166
      opj_stream_write_data(cio,l_data_header,4,p_manager);
157
167
    }
158
168
  }
159
169
 
160
 
  len = cio_tell( cio) - lenp;
161
 
  cio_seek( cio, lenp);
162
 
  cio_write( cio, len, 4);                   /* L                                 */
163
 
  cio_seek( cio, lenp+len);
 
170
  len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
 
171
  opj_stream_seek(cio,lenp,p_manager);
 
172
  opj_write_bytes(l_data_header, len, 4);/* L                                 */
 
173
  opj_stream_write_data(cio,l_data_header,4,p_manager);
 
174
  opj_stream_seek(cio,lenp+len,p_manager);
164
175
}
165
176
 
166
 
int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
 
177
 
 
178
int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
 
179
              opj_event_mgr_t * p_manager )
167
180
{
 
181
  OPJ_BYTE l_data_header [8];
168
182
  int i;
169
 
  int len, lenp;
 
183
  OPJ_UINT32 len;
 
184
  OPJ_OFF_T lenp;
170
185
  
171
 
  lenp = cio_tell( cio);
172
 
  cio_skip( cio, 4);                               /* L [at the end]                    */
173
 
  cio_write( cio, JPIP_MHIX, 4);                   /* MHIX                              */
 
186
  lenp = opj_stream_tell (cio);
 
187
  opj_stream_skip(cio, 4, p_manager);               /* L [at the end]                    */
 
188
  opj_write_bytes(l_data_header,JPIP_MHIX,4);       /* MHIX                              */
 
189
  opj_stream_write_data(cio,l_data_header,4,p_manager);
174
190
 
175
 
  cio_write( cio, cstr_info.main_head_end-cstr_info.main_head_start+1, 8);        /* TLEN                              */
 
191
  opj_write_bytes(l_data_header, cstr_info.main_head_end-cstr_info.main_head_start+1, 8);        /* TLEN                              */
 
192
  opj_stream_write_data(cio,l_data_header,8,p_manager);
176
193
 
177
194
  for(i = 1; i < cstr_info.marknum; i++){    /* Marker restricted to 1 apparition, skip SOC marker */
178
 
    cio_write( cio, cstr_info.marker[i].type, 2);
179
 
    cio_write( cio, 0, 2);
180
 
    cio_write( cio, cstr_info.marker[i].pos-coff, 8);
181
 
    cio_write( cio, cstr_info.marker[i].len, 2);
 
195
    opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
 
196
    opj_write_bytes( l_data_header+2, 0, 2);
 
197
    opj_stream_write_data(cio,l_data_header,4,p_manager);
 
198
    opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8);
 
199
    opj_stream_write_data(cio,l_data_header,8,p_manager);
 
200
    opj_write_bytes( l_data_header, cstr_info.marker[i].len, 2);
 
201
    opj_stream_write_data(cio,l_data_header,2,p_manager);
182
202
  }
183
203
 
184
 
  len = cio_tell( cio) - lenp;
185
 
  cio_seek( cio, lenp);
186
 
  cio_write( cio, len, 4);        /* L           */
187
 
  cio_seek( cio, lenp+len);
 
204
  len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
 
205
  opj_stream_seek(cio, lenp,p_manager);
 
206
  opj_write_bytes(l_data_header,len,4);/* L  */
 
207
  opj_stream_write_data(cio,l_data_header,4,p_manager);
 
208
  opj_stream_seek(cio, lenp+len,p_manager);
188
209
  
189
210
  return len;
190
211
}
191
212
 
192
 
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio)
 
213
OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
 
214
              opj_event_mgr_t * p_manager )
193
215
{
194
 
  opj_bool EPHused = OPJ_FALSE;
 
216
  OPJ_BYTE l_data_header [4];
 
217
  OPJ_BOOL EPHused = OPJ_FALSE;
195
218
  int i=0;
196
 
  int org_pos;
 
219
  OPJ_OFF_T org_pos;
197
220
  unsigned int Scod;
198
221
 
199
 
  for(i = 0; i < marknum; i++){
200
 
    if( markers[i].type == J2K_MS_COD){
201
 
      org_pos = cio_tell( cio);
202
 
      cio_seek( cio, coff+markers[i].pos+2);
203
 
      
204
 
      Scod = cio_read( cio, 1);
 
222
  for(i = 0; i < marknum; i++)
 
223
    {
 
224
    if( markers[i].type == J2K_MS_COD)
 
225
      {
 
226
      org_pos = opj_stream_tell(cio);
 
227
      opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
 
228
 
 
229
      opj_stream_read_data(cio,l_data_header,1,p_manager);
 
230
      opj_read_bytes(l_data_header,&Scod,1);
205
231
      if( ((Scod >> 2) & 1))
206
 
        EPHused = OPJ_TRUE;
207
 
      cio_seek( cio, org_pos);
 
232
        EPHused = OPJ_TRUE;
 
233
      opj_stream_seek( cio, org_pos, p_manager);
208
234
 
209
235
      break;
210
 
    }
211
 
  }    
 
236
      }
 
237
    }    
212
238
  return EPHused;
213
239
}