Skip to content

Commit

Permalink
JPEG output support
Browse files Browse the repository at this point in the history
  • Loading branch information
apangin committed Sep 20, 2017
1 parent 4854dde commit 4d2d16f
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/one/webp/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ private static int parseParams(String[] args, Params params) {
case "-png":
params.png(true);
break;
case "-jpeg":
params.jpeg(true);
break;
}
}
return i;
Expand Down
13 changes: 12 additions & 1 deletion src/one/webp/Params.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class Params {
private boolean lossless;
private boolean multithreaded;
private boolean png;
private boolean jpeg;

public Params quality(int quality) {
check(quality >= 0 && quality <= 100);
Expand Down Expand Up @@ -70,6 +71,11 @@ public Params png(boolean png) {
return this;
}

public Params jpeg(boolean jpeg) {
this.jpeg = jpeg;
return this;
}

public int quality() {
return quality;
}
Expand Down Expand Up @@ -102,6 +108,10 @@ public boolean png() {
return png;
}

public boolean jpeg() {
return jpeg;
}

// See struct Params in onewebp.h
long longValue() {
return (long) maxWidth
Expand All @@ -111,7 +121,8 @@ long longValue() {
| (useJpegScaling ? 1L << 48 : 0)
| (lossless ? 1L << 49 : 0)
| (multithreaded ? 1L << 50 : 0)
| (png ? 1L << 51 : 0);
| (png ? 1L << 51 : 0)
| (jpeg ? 1L << 52 : 0);
}

private void check(boolean condition) {
Expand Down
3 changes: 3 additions & 0 deletions src/one/webp/native/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ static int parse_params(int argc, char** argv, Params* params) {
params->multithreaded = 1;
} else if (strcmp(arg, "-png") == 0) {
params->png = 1;
} else if (strcmp(arg, "-jpeg") == 0) {
params->jpeg = 1;
}
}
return i;
Expand All @@ -68,6 +70,7 @@ static void show_usage() {
" -l : Lossless compression\n"
" -mt : Multithreaded encoding\n"
" -png : PNG output\n"
" -jpeg : JPEG output\n"
"\n");
}

Expand Down
16 changes: 16 additions & 0 deletions src/one/webp/native/onewebp.c
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,20 @@ int decompress_image(unsigned char* src, unsigned long srcSize, RawImage* rawIma
}
}

int compress_jpeg(unsigned char* dst, unsigned long dstSize, RawImage* rawImage, Params params) {
tjhandle handle = tjInitCompress();

int err = tjCompress2(handle, rawImage->argb, rawImage->width, 0, rawImage->height, TJPF_BGRX,
&dst, &dstSize, TJSAMP_420, params.quality, TJFLAG_NOREALLOC);
if (err) {
tjDestroy(handle);
return ERR_COMPRESS;
}

tjDestroy(handle);
return (int)dstSize;
}

int compress_png(unsigned char* dst, unsigned long dstSize, RawImage* rawImage) {
png_image png = { NULL };
png.version = PNG_IMAGE_VERSION;
Expand Down Expand Up @@ -230,6 +244,8 @@ int convert_image(unsigned char* src, unsigned long srcSize,

if (params.png) {
result = compress_png(dst, dstSize, &rawImage);
} else if (params.jpeg) {
result = compress_jpeg(dst, dstSize, &rawImage, params);
} else {
result = compress_webp(dst, dstSize, &rawImage, params);
}
Expand Down
1 change: 1 addition & 0 deletions src/one/webp/native/onewebp.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ typedef struct {
unsigned int lossless : 1;
unsigned int multithreaded : 1;
unsigned int png : 1;
unsigned int jpeg : 1;
} Params;

typedef struct {
Expand Down

0 comments on commit 4d2d16f

Please sign in to comment.