2
* Copyright (C)2011 D. R. Commander. All Rights Reserved.
2
* Copyright (C)2011, 2013 D. R. Commander. All Rights Reserved.
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.
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
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_*}
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 {
98
throw new Exception("JPEG buffer not initialized");
97
99
transformedSizes = transform(jpegBuf, jpegBufSize, dstBufs, transforms,
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;
126
128
dstBufs[i] = new byte[TJ.bufSize(w, h, jpegSubsamp)];
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]);
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()}
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;