Skip to content

Commit f11a739

Browse files
committed
var-ious improvements
1 parent b513b60 commit f11a739

File tree

14 files changed

+254
-163
lines changed

14 files changed

+254
-163
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20250504111736
1+
20250724191407
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20250504111736
1+
20250724191407
-88 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/src/javajs/api/GenericCifDataParser.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@
77
public interface GenericCifDataParser {
88

99
static final int NONE = -1;
10-
11-
String fullTrim(String str);
10+
static final int EMPTY = -2;
1211

1312
Map<String, Object> getAllCifData();
1413

14+
Map<String, Object> getAllCifDataType(String[] types);
15+
1516
boolean getData() throws Exception;
1617

1718
String getColumnName(int i);

sources/net.sf.j2s.java.core/src/javajs/img/ImageEncoder.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ public abstract class ImageEncoder implements GenericImageEncoder {
8080
protected int width = -1;
8181
protected int height = -1;
8282
protected int quality = -1;
83+
protected int dpi = -1;
84+
8385
protected String date;
8486
protected boolean logging;
8587
protected boolean doClose = true;
@@ -103,6 +105,9 @@ public boolean createImage(String type, OC out, Map<String, Object> params)
103105
setParams(params);
104106
generate();
105107
close(); // GIF will override this and not close
108+
params.put("qualityActual", Integer.valueOf(quality));
109+
if (dpi > 0)
110+
params.put("DPI", Integer.valueOf(dpi));
106111
return doClose;
107112
}
108113

sources/net.sf.j2s.java.core/src/javajs/img/Jpg64Encoder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public class Jpg64Encoder extends JpgEncoder {
4545

4646
@Override
4747
protected void setParams(Map<String, Object> params) {
48-
defaultQuality = 75;
48+
defaultQuality = 75; // assuming this is for the web; only 30% of the size relative to 100
4949
outTemp = (OC) params.remove("outputChannelTemp");
5050
super.setParams(params);
5151
}

sources/net.sf.j2s.java.core/src/javajs/img/JpgEncoder.java

Lines changed: 59 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import java.io.IOException;
3737
import java.util.Map;
3838

39-
import javajs.img.ImageEncoder;
4039
import javajs.util.AU;
4140
import javajs.util.OC;
4241

@@ -65,7 +64,7 @@ public class JpgEncoder extends ImageEncoder {
6564
private JpegObj jpegObj;
6665
private Huffman huf;
6766
private DCT dct;
68-
protected int defaultQuality = 100;
67+
protected int defaultQuality = 100; // set to 75 for Base64
6968
private String applicationTag;
7069

7170
public JpgEncoder() {
@@ -74,11 +73,19 @@ public JpgEncoder() {
7473

7574
@Override
7675
protected void setParams(Map<String, Object> params) {
77-
if (quality <= 0)
78-
quality = (params.containsKey("qualityJPG") ? ((Integer) params.get("qualityJPG")).intValue() : defaultQuality);
7976
jpegObj = new JpegObj();
8077
jpegObj.comment = (String) params.get("comment");
8178
applicationTag = (String) params.get("jpgAppTag");
79+
dpi = 300;
80+
if (quality <= 0)
81+
quality = (params.containsKey("qualityJPG") ? ((Integer) params.get("qualityJPG")).intValue() : -1);
82+
if (quality >= 90) {
83+
// 96, 100, 200, 300, 600, etc.
84+
dpi = quality;
85+
quality = -1;
86+
}
87+
if (quality < 0)
88+
quality = defaultQuality;
8289
}
8390

8491
@Override
@@ -186,24 +193,33 @@ private void writeCompressedData(JpegObj jpegObj, DCT dct, Huffman huf) {
186193
private static byte[] eoi = { (byte) 0xFF, (byte) 0xD9 };
187194

188195
private static byte[] jfif = new byte[] {
189-
/* JFIF[0] =*/(byte) 0xff,
190-
/* JFIF[1] =*/(byte) 0xe0,
191-
/* JFIF[2] =*/0,
192-
/* JFIF[3] =*/16,
193-
/* JFIF[4] =*/(byte) 0x4a, //'J'
196+
// application use marker
197+
/* JFIF[0] =*/(byte) 0xff,
198+
/* JFIF[1] =*/(byte) 0xe0,
199+
// APP0 field size; starting at [2]
200+
/* JFIF[2] =*/0,
201+
/* JFIF[3] =*/16,
202+
203+
/* JFIF[4] =*/(byte) 0x4a, //'J'
194204
/* JFIF[5] =*/(byte) 0x46, //'F'
195205
/* JFIF[6] =*/(byte) 0x49, //'I'
196206
/* JFIF[7] =*/(byte) 0x46, //'F'
197207
/* JFIF[8] =*/0,
208+
198209
/* JFIF[9] =*/1,
199210
/* JFIF[10] =*/0,
200-
/* JFIF[11] =*/0,
201-
/* JFIF[12] =*/0,
202-
/* JFIF[13] =*/1,
203-
/* JFIF[14] =*/0,
204-
/* JFIF[15] =*/1,
205-
/* JFIF[16] =*/0,
206-
/* JFIF[17] =*/0 };
211+
212+
// quality (5 bytes) and thumbnail (2 bytes) follow; not included here
213+
};
214+
215+
216+
// BYTE Identifier[5]; /* 06h "JFIF" (zero terminated) Id String */
217+
// BYTE Version[2]; /* 07h JFIF Format Revision */
218+
// BYTE Units; /* 09h Units used for Resolution */
219+
// BYTE Xdensity[2]; /* 0Ah Horizontal Resolution */
220+
// BYTE Ydensity[2]; /* 0Ch Vertical Resolution */
221+
// BYTE XThumbnail; /* 0Eh Horizontal Pixel Count */
222+
// BYTE YThumbnail; /* 0Fh Vertical Pixel Count */
207223

208224
private static byte[] soi = { (byte) 0xFF, (byte) 0xD8 };
209225

@@ -217,6 +233,9 @@ private String writeHeaders(JpegObj jpegObj, DCT dct) {
217233
// The order of the following headers is quite inconsequential.
218234
// the JFIF header
219235
writeArray(jfif);
236+
237+
writeDensities();
238+
writeThumbNailSize();
220239

221240
// Comment Header
222241
String comment = null;
@@ -287,6 +306,30 @@ private String writeHeaders(JpegObj jpegObj, DCT dct) {
287306
return comment;
288307
}
289308

309+
private void writeDensities() {
310+
// Units, Xdensity, and Ydensity identify the unit of measurement
311+
// used to describe the image resolution.
312+
// Units may be 01h for dots per inch,
313+
// 02h for dots per centimeter,
314+
// or 00h for none (use measurement as pixel aspect ratio).
315+
// Xdensity and Ydensity are the horizontal and vertical resolution
316+
// of the image data, respectively.
317+
// If the Units field value is 00h, the Xdensity and Ydensity fields
318+
// will contain the pixel aspect ratio (Xdensity : Ydensity)
319+
// rather than the image resolution.
320+
// Because non-square pixels are discouraged for portability
321+
// reasons, the Xdensity and Ydensity values normally
322+
// equal 1 when the Units value is 0.
323+
324+
out.writeByteAsInt(1);
325+
out.writeShort((short) dpi);
326+
out.writeShort((short) dpi);
327+
}
328+
329+
private void writeThumbNailSize() {
330+
writeArray(new byte[2]);
331+
}
332+
290333
private void writeString(String s, byte id) {
291334
int len = s.length();
292335
int i0 = 0;

0 commit comments

Comments
 (0)