-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add WebP support #233
Add WebP support #233
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# - Find WebP | ||
# Find the WebP libraries | ||
# | ||
# This module defines the following variables: | ||
# WEBP_FOUND - 1 if WEBP_INCLUDE_DIR & WEBP_LIBRARY are found, 0 otherwise | ||
# WEBP_INCLUDE_DIR - where to find webp/encode.h, etc. | ||
# WEBP_LIBRARY - the libwebp library | ||
|
||
find_path( WEBP_INCLUDE_DIR | ||
NAMES webp/encode.h | ||
PATH_SUFFIXES /usr/include /include | ||
DOC "The libwebp include directory" ) | ||
|
||
find_library( WEBP_LIBRARY | ||
NAMES libwebp.so | ||
PATHS /usr/lib /lib | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And same deal here with |
||
DOC "The libwebp library" ) | ||
|
||
if( WEBP_INCLUDE_DIR AND WEBP_LIBRARY ) | ||
set( WEBP_FOUND 1 ) | ||
else() | ||
set( WEBP_FOUND 0 ) | ||
endif() | ||
|
||
mark_as_advanced( WEBP_INCLUDE_DIR WEBP_LIBRARY ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,6 +271,32 @@ void ARGBImage::writeBMP( std::ostream& streamout ) { | |
delete[] imageData; | ||
} | ||
|
||
void ARGBImage::writeWEBP( std::ostream& streamout, int quality ) { | ||
// assume 4 channels | ||
if (channels != 4) { | ||
throw new std::runtime_error("WebP tried to save image with more than 4 channels"); | ||
} | ||
|
||
size_t size; | ||
uint8_t* out; | ||
if (quality == 10) { | ||
// encode lossless at highest quality | ||
size = WebPEncodeLosslessRGBA(data, width, height, width * 4, &out); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, there is more advanced interface for lossless encoding: struct WebPConfig {
int lossless; // Lossless encoding (0=lossy(default), 1=lossless).
float quality; // between 0 and 100. For lossy, 0 gives the smallest
// size and 100 the largest. For lossless, this
// parameter is the amount of effort put into the
// compression: 0 is the fastest but gives larger
// files compared to the slowest, but best, 100.
int method; // quality/speed trade-off (0=fast, 6=slower-better) It allows us to specify encoding speed for webp in lossless mode. I am not sure if we should use this or just stick to default prefubs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw this as well, but I think we have no good reason to use other settings, unless the user can change them; but that would require more switches, which I think would introduce unnecessary complexity, which is also why I think re-using |
||
} | ||
else { | ||
// otherwise, encode lossy | ||
size = WebPEncodeRGBA(data, width, height, width * 4, quality * 10.0f, &out); | ||
} | ||
|
||
if (size == 0) { | ||
throw new std::runtime_error("Failed to encode webp image"); | ||
} | ||
else { | ||
streamout.write((const char*)out, size); | ||
WebPFree(out); | ||
} | ||
} | ||
|
||
bool ARGBImage::intersect( XRRCrtcInfo* a, glm::vec4 b ) { | ||
if (a->x < b.x + b.z && | ||
a->x + a->width > b.x && | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably also a good idea to search for
/usr/local/include
? I am not sure though, just thinking.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm new to cmake, so I used the same paths as in the other
Find*.cmake
files. If we used/usr/local/
here, I feel like it'd also have to be changed for the other ones, which I think is a topic for another PR.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a cmake veteran either :D
If
/local/
paths are not used in otherFind*.cmake
files, we should really not be bothered.