Giter Club home page Giter Club logo

mattes / epeg Goto Github PK

View Code? Open in Web Editor NEW
258.0 17.0 45.0 318 KB

Insanely fast JPEG/ JPG thumbnail scaling with the minimum fuss and CPU overhead. It makes use of libjpeg features of being able to load an image by only decoding the DCT coefficients needed to reconstruct an image of the size desired.

License: Other

Shell 1.30% C 86.29% Makefile 2.33% M4 3.11% CMake 6.96%
epeg thumbnails libjpeg jpeg jpg dct-coefficients epeg-library enlightenment

epeg's People

Contributors

francois-random avatar gustavlarson avatar kraj avatar manuelstofer avatar mattes avatar mscdex avatar pkrnjevic avatar starshipjc avatar vlad-butnaru-sv avatar wezm avatar z38 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

epeg's Issues

Documentation: add example code for using jna

com.sun.jna is an excellent library for calling C from java. I've used this with epeg to great success.

For example:

public interface EpegLibrary extends Library {
    Pointer epeg_file_open(String fileName);
    Pointer epeg_memory_open(Memory memory, int len);
    void epeg_size_get(Pointer image, int[] width, int[] height);
    void epeg_decode_size_set(Pointer image, int width, int height);
    void epeg_quality_set(Pointer image, int quality);
    void epeg_memory_output_set(Pointer image, PointerByReference output, LongByReference size);
    int epeg_encode(Pointer image);
    void epeg_close(Pointer image);
}

private final EpegLibrary epeg = Native.loadLibrary("epeg", EpegLibrary.class);

// this is an unfortunate hack, I hope someone can figure out a better version
private static class ExposingFree extends Memory {
	public static void exposedFree(Pointer p) {
		free(Pointer.nativeValue(p));
	}
}

public byte[] thumb(String fileName, int targetBigDim, int targetLittleDim, int qualityOutOf100) {
	Pointer image = epeg.epeg_file_open(fileName);
	return thumb(image, targetBigDim, targetLittleDim, qualityOutOf100);
}

public byte[] thumb(byte[] source, int targetBigDim, int targetLittleDim, int qualityOutOf100) {
	Memory buf = new Memory(source.length);
	buf.write(0, source, 0, source.length);
	Pointer image = epeg.epeg_memory_open(buf, source.length);
	byte[] result = thumb(image, targetBigDim, targetLittleDim, qualityOutOf100);
	// would free memory here, but it apparently just gets GC'd
	return result;
}

private byte[] thumb(Pointer image, int targetBigDim, int targetLittleDim, int qualityOutOf100) {
	if (image == null)
		return null;
	int[] width = new int[1];
	int[] height = new int[1];
	epeg.epeg_size_get(image, width, height);
	while ((width[0] >= targetBigDim * 2 && height[0] >= targetBigDim * 2) || (width[0] >= targetLittleDim * 2 || height[0] >= targetLittleDim * 2)) {
		width[0] /= 2;
		height[0] /= 2;
	}
	epeg.epeg_decode_size_set(image, width[0], height[0]);
	epeg.epeg_quality_set(image, qualityOutOf100);
	PointerByReference m = new PointerByReference();
	LongByReference sizeMem = new LongByReference();
	sizeMem.setValue(0);
	epeg.epeg_memory_output_set(image, m, sizeMem);
	int encodeStatus = epeg.epeg_encode(image);
	try {
        if (encodeStatus != 0) {
            throw new RuntimeException("epeg_encode: Error encoding, error=" + encodeStatus);
        }
        long size = sizeMem.getValue();
        if (size == 0) {
            throw new RuntimeException("epeg: Size was 0");
        }
        if (size > Integer.MAX_VALUE) {
            throw new RuntimeException("epeg: Size was > 2GB");
        }
        Pointer pointer = m.getValue();
        try {
            byte[] bytes = pointer.getByteArray(0, (int)size);
            return bytes;
        } finally {
            ExposingFree.exposedFree(pointer);
        }
    } finally {
        epeg.epeg_close(image);
    }
}

Add a function call to get the epeg library version

This would allow a program to verify, among other things, that it's using an epeg version that doesn't have the "result > 64K bug" fixed in 0.9.2. It should be a real shared library call so a java program (using jna or jni) can call it.

_epeg_encode more-or-less closes the image. Why?

Just before returning, _epeg_encode runs the following code which makes it impossible to run any other encode or decode operations without first reopening the image.

   done:
   if ((im->in.f) || (im->in.mem.data != NULL)) jpeg_destroy_decompress(&(im->in.jinfo));
   if ((im->in.f) && (im->in.file)) fclose(im->in.f);
   if (dst_mgr)
     {
	if (dst_mgr->buf) free(dst_mgr->buf);
	free(dst_mgr);
	im->out.jinfo.dest = NULL;
     }
   jpeg_destroy_compress(&(im->out.jinfo));
   if ((im->out.f) && (im->out.file)) fclose(im->out.f); 
   im->in.f = NULL;
   im->out.f = NULL;

Is there a good reason for this aggressive cleanup? It seems like the dst_mgr cleanup and the closing of the output file is really all that should happen here. All the rest of the cleanup should be handled by epeg_close. I think I'm going to try changing this in my fork. Thoughts?

epeg: cannot open

Hello,
I just try to use epeg, but the only messsage I got is : "epeg: cannot open xx.jpg"

I compiled it on an updated raspbian on my raspberry pi, I didn't notice any error during the make process.

When I run the command with -v argument :
$ epeg -v -m 10 url.jpeg tt.jpg
max_dimension = 10
input_file = url.jpeg
output_file = tt.jpg
epeg: cannot open url.jpeg

the file url.jpeg is readable by any user.
Any idea where the problem is ?

sincerely yours

EXIF rotation

Hi, this utility is really neat but it seems to fail to respect the EXIF rotation information. Is there anything about it that could be done?

tag releases

When there's a point at which this repository is stable and includes notable improvements over the old Enlightenment release, could you tag a new release for package managers like Homebrew to use? Thanks!

epeg fails when called with full path

i cloned the repository on arch linux and configured / installed it with autogen.sh + make + sudo make install and have the issue that it haves differently towards the way i call the binary:

[ladiko@io ~]$ cd ~/epeg/src/bin/
[ladiko@io bin]$ which epeg
/usr/local/bin/epeg
[ladiko@io bin]$ ./epeg
Usage: /home/ladiko/epeg/src/bin/.libs/lt-epeg [options] input.jpg thumb.jpg
 -v,  --verbose
 -w,  --width=<width>[%]   set thumbnail width [% of input]
 -h,  --height=<height>[%] set thumbnail height [% of input]
 -p,  --preserve            preserve aspect if only one of width and height given
 -m,  --max=<maximum>       reduce max(w,h) to maximum, with aspect preserved
 -i,  --inset               cover at least the specified size (no upscaling or cropping)
 -c,  --comment=<comment>   put a comment in thumbnail
 -q,  --quality=<quality>   set thumbnail quality (1-100)
[ladiko@io bin]$ epeg
Usage: epeg [options] input.jpg thumb.jpg
 -v,  --verbose
 -w,  --width=<width>[%]   set thumbnail width [% of input]
 -h,  --height=<heigth>[%] set thumbnail heigth [% of input]
 -m,  --max=<maximum>       reduce max(w,h) to maximum, with aspect preserved
 -c,  --comment=<comment>   put a comment in thumbnail
[ladiko@io bin]$ /usr/local/bin/epeg
mkdir: cannot create directory ‘/usr/local/bin/.libs’: Permission denied
/usr/bin/ld: cannot open output file /usr/local/bin/.libs/24404-lt-epeg: No such file or directory
collect2: error: ld returned 1 exit status

Use the lib in MCUs without libexif

Hi @mattes
I want to use this library in my project which is an embedded projects , can I use this without libexif?
Also I need jconfig.h and jmorecfg.h and config.h , where can I get those , ( i've downloaded jconfig.h and jmorecfg.h but not sure about the configuration , do I need to do some changes? )

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.