~ubuntu-branches/ubuntu/saucy/libjpeg-turbo/saucy-security

« back to all changes in this revision

Viewing changes to java/org/libjpegturbo/turbojpeg/TJTransformer.java

  • Committer: Package Import Robot
  • Author(s): Fathi Boudra
  • Date: 2013-07-28 16:52:51 UTC
  • mfrom: (1.1.3) (9.1.1 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130728165251-7vg6wszhm941kdej
Tags: 1.3.0-0ubuntu1
* New upstream release.
  - drop debian/patches/branch-updates.diff
  - refresh tjunittest.patch (now renamed to install-tjunittest.patch)
* Update debian/control:
  - add myself to Uploaders.
* Update debian/copyright:
  - add RSA Data Security copyright (md5).
* Update debian/libturbojpeg.install:
  - install libturbojpeg.so.0* (needed by tjunittest and tjbench).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright (C)2011 D. R. Commander.  All Rights Reserved.
 
2
 * Copyright (C)2011, 2013 D. R. Commander.  All Rights Reserved.
3
3
 *
4
4
 * Redistribution and use in source and binary forms, with or without
5
5
 * modification, are permitted provided that the following conditions are met:
73
73
   * JPEG image structure to another without altering the values of the
74
74
   * coefficients.  While this is typically faster than decompressing the
75
75
   * image, transforming it, and re-compressing it, lossless transforms are not
76
 
   * free.  Each lossless transform requires reading and Huffman decoding all
77
 
   * of the coefficients in the source image, regardless of the size of the
78
 
   * destination image.  Thus, this method provides a means of generating
79
 
   * multiple transformed images from the same source or of applying multiple
80
 
   * transformations simultaneously, in order to eliminate the need to read the
81
 
   * source coefficients multiple times.
 
76
   * free.  Each lossless transform requires reading and performing Huffman
 
77
   * decoding on all of the coefficients in the source image, regardless of the
 
78
   * size of the destination image.  Thus, this method provides a means of
 
79
   * generating multiple transformed images from the same source or of applying
 
80
   * multiple transformations simultaneously, in order to eliminate the need to
 
81
   * read the source coefficients multiple times.
82
82
   *
83
83
   * @param dstBufs an array of image buffers.  <code>dstbufs[i]</code> will
84
84
   * receive a JPEG image that has been transformed using the parameters in
85
85
   * <code>transforms[i]</code>.  Use {@link TJ#bufSize} to determine the
86
 
   * maximum size for each buffer based on the cropped width and height.
 
86
   * maximum size for each buffer based on the transformed or cropped width and
 
87
   * height.
87
88
   *
88
89
   * @param transforms an array of {@link TJTransform} instances, each of
89
90
   * which specifies the transform parameters and/or cropping region for the
92
93
   * @param flags the bitwise OR of one or more of {@link TJ TJ.FLAG_*}
93
94
   */
94
95
  public void transform(byte[][] dstBufs, TJTransform[] transforms,
95
 
    int flags) throws Exception {
96
 
    if(jpegBuf == null) throw new Exception("JPEG buffer not initialized");
 
96
                        int flags) throws Exception {
 
97
    if (jpegBuf == null)
 
98
      throw new Exception("JPEG buffer not initialized");
97
99
    transformedSizes = transform(jpegBuf, jpegBufSize, dstBufs, transforms,
98
 
      flags);
 
100
                                 flags);
99
101
  }
100
 
  
 
102
 
101
103
  /**
102
104
   * Losslessly transform the JPEG image associated with this transformer
103
105
   * instance and return an array of {@link TJDecompressor} instances, each of
115
117
  public TJDecompressor[] transform(TJTransform[] transforms, int flags)
116
118
    throws Exception {
117
119
    byte[][] dstBufs = new byte[transforms.length][];
118
 
    if(jpegWidth < 1 || jpegHeight < 1)
 
120
    if (jpegWidth < 1 || jpegHeight < 1)
119
121
      throw new Exception("JPEG buffer not initialized");
120
 
    for(int i = 0; i < transforms.length; i++) {
 
122
    for (int i = 0; i < transforms.length; i++) {
121
123
      int w = jpegWidth, h = jpegHeight;
122
 
      if((transforms[i].options & TJTransform.OPT_CROP) != 0) {
123
 
        if(transforms[i].width != 0) w = transforms[i].width;
124
 
        if(transforms[i].height != 0) h = transforms[i].height;
 
124
      if ((transforms[i].options & TJTransform.OPT_CROP) != 0) {
 
125
        if (transforms[i].width != 0) w = transforms[i].width;
 
126
        if (transforms[i].height != 0) h = transforms[i].height;
125
127
      }
126
128
      dstBufs[i] = new byte[TJ.bufSize(w, h, jpegSubsamp)];
127
129
    }
128
130
    TJDecompressor[] tjd = new TJDecompressor[transforms.length];
129
131
    transform(dstBufs, transforms, flags);
130
 
    for(int i = 0; i < transforms.length; i++)
 
132
    for (int i = 0; i < transforms.length; i++)
131
133
      tjd[i] = new TJDecompressor(dstBufs[i], transformedSizes[i]);
132
134
    return tjd;
133
135
  }
134
 
  
 
136
 
135
137
  /**
136
138
   * Returns an array containing the sizes of the transformed JPEG images from
137
139
   * the most recent call to {@link #transform transform()}.
140
142
   * the most recent call to {@link #transform transform()}
141
143
   */
142
144
  public int[] getTransformedSizes() throws Exception {
143
 
    if(transformedSizes == null)
 
145
    if (transformedSizes == null)
144
146
      throw new Exception("No image has been transformed yet");
145
147
    return transformedSizes;
146
148
  }