Commit Graph

648 Commits

Author SHA1 Message Date
Noel Chromium
27519bc2b6 add WebPPictureImportRGBX() and WebPPictureImportBGRX()
When importing BGRA or RGBA data for encoding, provide variants of
the WEBPImportPicture API for RGBX and BRGX data meaning the alpha
channel should be ignored.

Author: noel@chromium.org
from Chromium patch: https://chromiumcodereview.appspot.com/10496016/

Change-Id: I15fcaa4160c69a2b5549394204b6e6d7a1c5d333
2012-06-05 00:26:17 -07:00
Pascal Massimino
437999fb77 introduce a generic WebPPictureHasTransparency() function
VP8-lossy will now avoid writing an ALPH chunk if the
alpha values are trivial.

+ changed DumpPicture() accordingly in cwebp
+ prevented the -d option to be active with lossless
 (DumpPicture wouldn't work).

Change-Id: I34fdb108a2b6207e93fa6cd00b1d2509a8e1dc4b
2012-06-04 16:17:55 -07:00
Pascal Massimino
d2b6c6c03b cosmetic fixes after Idaba281a
Change-Id: I275a3dee5696fe1a3e2db0976f8241f2044be512
2012-06-04 13:19:28 -07:00
Pascal Massimino
b4e6645c61 Merge "add colorspace for premultiplied alpha" 2012-06-04 07:56:37 -07:00
Pascal Massimino
48f827574e add colorspace for premultiplied alpha
The new modes are
       MODE_rgbA
       MODE_bgrA
       MODE_Argb
       MODE_rgbA_4444
It's binary incompatible, since the enums changed.

While at it, i removed the now unneeded KeepAlpha methods.
-> Saved ~12k of code!

* made explicit mention that alpha_plane is persistent,
so we have access to the full alpha plane data at all time.
Incremental decoding of alpha was planned for, but not
implemented. So better not dragged this constaint for now
and make the code easier until we revisit that.

Change-Id: Idaba281a6ca819965ca062d1c23329f36d90c7ff
2012-06-04 07:50:41 -07:00
Vikas Arora
069f903a08 Change in lossless bit-stream.
Change the lossless signature to 0x2f
Add 1 bit indicator for 'droppable (or trivial) alpha)'.
Add 3 bit lossless version (for future extension like yuv support).
Change the sub-resolution information to 3 bits implying range [2 .. 9]

Change-Id: Ic7b8c069240bbcd326cf5d5d4cd2dde8667851e2
2012-06-04 12:47:01 +05:30
pascal massimino
5f7bb3f53a Merge "WebPReportProgress: use non-encoder specific params" 2012-05-31 13:02:30 -07:00
James Zern
f18281ffa0 WebPReportProgress: use non-encoder specific params
Take picture and percent value storage location instead of VP8Encoder.
This will allow reuse by the lossless encoder.

Change-Id: Ic49dbc800cc3e2df60d20f4ebac277f68ed6031b
2012-05-31 11:28:48 -07:00
Urvang Joshi
9ef3228301 Add support for raw lossless bitstream in decoder.
Previously, it used to assume any raw bitstream is a VP8 one.

Also,
- Factor out VP8CheckSignature() & VP8LCheckSignature().
- Use a local var for *data_ptr in ParseVP8Header() for
readability.

Change-Id: I0fa8aa177dad7865e00c8898f7e7ce76a9db19d5
2012-05-31 14:03:17 +05:30
Vikas Arora
7cbee29afa Fix bug: InitIo reseting fancy_upsampling flag.
frame's InitIo should not reset fancy_upsampling flag.
This flag (fancy_upsampling) is set via CustomSetup -> WebPIoInitFromOptions
and frame's InitIo() is resetting it to 0.

Change-Id: I64b54cdfba43799c0a5aa8e384575af5d6331674
2012-05-30 14:46:22 +05:30
James Zern
880fd98ca1 vwebp: fix exit w/freeglut
GLUT_ACTION_CONTINUE_EXECUTION is required to allow glutMainLoop to
return.

Change-Id: I8eb7e657a52d6923858959b7b03447a7ddb53ca0
2012-05-25 15:06:21 -07:00
Pascal Massimino
1875d926e7 trap two unchecked error conditions
CostModelBuild() and TrackBackwards() returns weren't checked

+ code clean-up
+ de-inline VP8LBackwardRefs non-critical methods
+ shuffle the .h around to group things together
+ extract some constants as #define's
+ fixed the "if (!(cc_init = ...)) {...}" constructs
+ removed some unneeded VP8L prefixes

Change-Id: Ic634cb87bc6b2033242d3e8e8731fab4c134f327
2012-05-25 02:52:44 -07:00
Pascal Massimino
87b4a908a5 no need to have mux.h as noinst clause in enc/
Change-Id: I93c65838f33d01170fc63340650edeeee753786f
2012-05-24 15:05:19 -07:00
James Zern
88f41ec6ec doc: fix bit alignment in VP8X chunk
Change-Id: I7eaa7be48213642e3eceaaac95ad00952e085330
2012-05-24 12:33:48 -07:00
Pascal Massimino
52f5a4eff0 Merge "fix bug with lossy-alpha output stride" 2012-05-24 08:56:44 -07:00
Pascal Massimino
3bde22d768 fix bug with lossy-alpha output stride
dec->width_ != final_width in case of Bundle transform!

thanks to Pepijn for spotting the problem

Change-Id: I08b451a32097dcbf23b73deabc8cc6a2d59f0119
2012-05-24 08:54:02 -07:00
Pascal Massimino
42d61b6def update the spec for the lossy-alpha compression methods.
No further experiments are to be expected, so this is quite the
final format so far, pending supplemental feedbacks.

Change-Id: I2a3de025c90b7bb5fdd8792b2b2ccdc2e3753f56
2012-05-24 07:22:52 -07:00
Urvang Joshi
e75dc80516 Move some more defines to format_constants.h
Also remove some duplicate const/defines.

Change-Id: I0ec48866b874f546022d72e938fb65669b0b3211
2012-05-24 17:46:01 +05:30
Urvang Joshi
c13f663261 Move consts to internal header format_constants.h
Change-Id: Ic6180c16d0b4245680738992925e4608c593fbe8
2012-05-24 15:02:02 +05:30
Pascal Massimino
7f2dfc92dc use a bit-set transforms_seen_ instead of looping
may be useful later for instance to bypass some code
if we know we don't use the Bundle+ColorMap transform.

Change-Id: I9dc70d18165b2363ad9ede763684ef3d8eba5903
2012-05-24 02:04:23 -07:00
Pascal Massimino
18da1f53fc modulate alpha-compression effort according to config.method
we vary linearly lossless-method between 0 and 6,
and lossless-quality between 50 and 100, so that encoding
speed can go from 'quite fast' to 'rather slow'.
Impact on size is moderate, but visible.

Change-Id: I0b7917e7170eb50258afb1a4e248028cd9e9207d
2012-05-24 01:54:12 -07:00
pascal massimino
f5f2fff657 Merge "Alpha flag fix for lossless." 2012-05-24 01:11:07 -07:00
Urvang Joshi
c975c44ea5 Alpha flag fix for lossless.
- Make sure alpha flag is set in case of a lossless file with VP8X chunk.
  The semantic of ALPHA_FLAG changes with this: it means the images
  contain alpha (rather than ALPH chunk in particular).
- Update the mux container spec to add 1-line description of alpha
  flag.
- Rename "HasLosslessImages()" to "MuxHasLosslessImages()", and other
  similar function renames.
- Rename FeatureFlags to WebPFeatureFlags
- Elaborated a comment for a special case.
- A misc comment fix.

Change-Id: If212ccf4338c125b4c71c10bf281a51b3ba7ff45
2012-05-24 11:35:12 +05:30
James Zern
4f067fb254 Merge "Android: only build dec_neon with NEON support" 2012-05-23 22:26:03 -07:00
James Zern
255c66b48f Android: only build dec_neon with NEON support
Defining LOCAL_ARM_NEON = true can result in neon instructions being
used in portions unprotected by the cpu check.
This changes defines a WEBP_USE_NEON/WEBP_ANDROID_NEON pair similar to
the SSE2 code and MSVC.

Change-Id: Ifac010b06e42c73d5aca529baa2198c6796674bd
2012-05-23 22:21:10 -07:00
Pascal Massimino
8f9117a9f0 cosmetics: signature fixes
Change-Id: Id0e1026d43c0a6928dd740c88117df638bfb6db6
2012-05-23 12:45:05 -07:00
Pascal Massimino
39bf5d6497 use header-less lossless bitstream for alpha channel
This saves ~26 bytes of headers.
* introduce new VP8LDecodeAlphaImageStream() for decoding
* use VP8LEncodeStream() for encoding
* refactor code a bit

still TODO: make the alpha-quality/enc-method user-configurable

Change-Id: I23e599bebe335cfb5868e746e076c3358ef12e71
2012-05-23 08:01:44 -07:00
Pascal Massimino
75d7f3b222 Merge "make input data be 'const' for VP8LInverseTransform()" 2012-05-23 07:54:12 -07:00
Pascal Massimino
9a721c6d24 make input data be 'const' for VP8LInverseTransform()
Change-Id: I5b5b1e29bca6c42704df141b21632a0d0fcb07cf
2012-05-23 07:21:53 -07:00
Vikas Arora
9fc64edc21 Disallow re-use of same transformation.
Limit the overall number of transformations to 4 and disallow any
duplicate transform for decoding an image.

Change-Id: Ic4b0ecd553db96702e117fd073617237d95e45c0
2012-05-23 17:04:57 +05:30
Pascal Massimino
98ec717f1e use a function pointer for ProcessRows()
this allows later customization of data output method.
No perf diff observed, even if ProcessRows is no longer inlined.

Change-Id: I6933a3612a9cf6c108cf2776dfde0ae80c6c07c0
2012-05-23 02:00:14 -07:00
Pascal Massimino
f7ae5e370a cosmetics: join line
Change-Id: Ib27ed202fff439b94431360c8b0654d88962fb9a
2012-05-23 01:56:29 -07:00
Pascal Massimino
140b89a323 factor out buffer alloc in AllocateARGBBuffers()
+ small opportunistic fixes:
  * allow NULL decoded_data to be passed to DecodeStream
    and clarity (with assert()) when to do so
  * AllocateAndInitRescaler() was already setting error status,
    as it should. No need to do it at caller's site

Change-Id: I30867e596564a7f459a0d1ddbf6f5d312414b7fd
2012-05-23 01:53:57 -07:00
Urvang Joshi
a107dfa806 Rectify WebPParseOptionalChunks().
Now it stops at either VP8/VP8L chunk.

Change-Id: Iadac4fa47396b61b9b720b8b7b19138c89df24cc
2012-05-23 13:59:52 +05:30
Vikas Arora
237eab6764 Add two more color-spaces for lossless decoding.
Added color-spaces (RGBA_4444 and RGB_565), required for Android device
to lossless decoding.

Change-Id: I229832edd4deca59e066f463e7454f77457c5bcd
2012-05-23 12:10:13 +05:30
Pascal Massimino
27f417ab66 fix orthographic typo
Change-Id: I4f62e9c125ef3bc1ab75871e6725551f1c89f5e8
2012-05-22 13:20:57 -07:00
Pascal Massimino
489ec335a1 add VP8LEncodeStream() to compress lossless image stream
* RIFF header is omitted
* rename NewVP8LEncoder and DeleteVP8Encoder
* change the signature to take a "const WebPPicture*"
  (it was non-const just because we were setting some error potentially)
* made the pic_ field const in VP8LEncoder too.
* trap the bitwriter::error_ too
* simplify some signatures to take WebPPicture* instead
  of unneeded VP8LEncoder*

VP8LEncodeStream() will be called directly to compress alpha channel
header-less.

Change-Id: Ibceef63d2b3fbc412f0dffc38dc05c2dee6b6bbf
2012-05-22 03:15:58 -07:00
Pascal Massimino
fa8bc3dbca make WebPEncodingSetError() take a const picture
This is a border-case situation: the picture is not const, because
we're change its error status. But taking it non-const forces
the caller to carry a non-const picture all around the code just
in case (0.00001% of the time?) something bad happen.
This pretty much the same as making all objects non-const because
we'll eventually call delete or free() on them, which is quite a
non-const operation. Well... Better allow constness enforcement for
the remaining 99.9999% of the code.

Change-Id: I9b93892a189a50feaec1a3a518ebf488eb6ff22f
2012-05-22 02:51:38 -07:00
Pascal Massimino
638528cd1e bitstream update for lossy alpha compression
now, we only use 2 bits for the filtering method, and 2 bits
for the compression method.
There's two additional bits which are INFORMATIVE, to specify
whether the source has been pre-processed (level reduction)
during compression. This can be used at decompression time
for some post-processing (see DequantizeLevels()).

New relevant spec excerpt:

     0                   1                   2                   3
     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |                      ChunkHeader('ALPH')                      |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
    |Rsv| P | F | C |     Alpha Bitstream...                        |
    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Compression method (C): 2 bits

: The compression method used:

  * `0`: No compression.
  * `1`: Backward reference counts encoded with arithmetic encoder.

Filtering method (F): 2 bits

: The filtering method used:

  * `0`: None.
  * `1`: Horizontal filter.
  * `2`: Vertical filter.
  * `3`: Gradient filter.

Pre-processing (P): 2 bits

: These INFORMATIVE bits are used to signal the pre-processing that has
been performed during compression. The decoder can use this information to
e.g. dither the values or smooth the gradients prior to display.

  * `0`: no pre-processing
  * `1`: level reduction

Decoders are not required to use this information in any specified way.

Reserved (Rsv): 2 bits

: SHOULD be `0`.

Alpha bitstream: _Chunk Size_ - `1` bytes

: Encoded alpha bitstream.

This optional chunk contains encoded alpha data for a single tile.
Either **ALL or NONE** of the tiles must contain this chunk.

The alpha channel data is losslessly stored as raw data (when
compression method is '0') or compressed using the lossless format
(when the compression method is '1').

Change-Id: Ied8f5fb922707a953e6a2b601c69c73e552dda6b
2012-05-22 02:36:22 -07:00
Pascal Massimino
d73e63a726 add DequantizeLevels() placeholder
will be called by alpha post-processing, although doing nothing for now.
Gradient smoothing would be nice-to-have here. Patch welcome!

Change-Id: I534cde866bdc75da22d0f0a6d1373c90e21366f3
2012-05-22 02:28:19 -07:00
Pascal Massimino
ec122e0986 remove arch-dependent rand()
let's use our own simple pseudo-random number generator

Change-Id: I7b4a190cdf4d338b1fae5ef3622ebd82c6e19274
2012-05-22 00:17:04 -07:00
Pascal Massimino
d40e7653db fix alignment
Change-Id: Ieb36de1bcf8c624024f8a3d5a238a2b508d4bb51
2012-05-21 14:31:16 -07:00
Pascal Massimino
1dd6a8b65e Merge "remove tcoder, switch alpha-plane compression to lossless" 2012-05-21 06:38:45 -07:00
Pascal Massimino
3e863dda61 remove tcoder, switch alpha-plane compression to lossless
* Method #1 is now calling the lossless encoder on the alpha plane.
Format is not final, it's just a first draft. We need ad-hoc functions.
* removed now useless utils/alpha.*
* added utils/quant_levels.h instead
* removed the TCoder code altogether

Change-Id: I636840b6129a43171b74860e0a0fc5bb1bcffc6a
2012-05-21 06:24:48 -07:00
Urvang Joshi
8d77dc29e1 Add support for lossless in mux:
- Separate out 'CHUNK_INDEX' from 'TAG_ID' (this is to help with the
  situation where two different tags - "VP8 " and "VP8L" can have the
  same TAG_ID -> IMAGE_ID).
- Some internal methods now take 'CHUNK_INDEX' param instea of 'TAG_ID'
  as appropriate.
- Add kChunks[] entry for lossless.
- Rename WebPMuxImage.vp8_ --> WebPMuxImage.img_
- SetImage() and AddFrame/Tile() infer whether the bitstream is a
  lossless one based on LOSSLESS_MAGIC_BYTE. The correct tag is stored
  based on this.

Also, handle the case when GetVP8Info/GetVP8LInfo() fails.

Change-Id: I6b3bc9555cedb791b43f743b5a7770958864bb05
2012-05-21 13:54:18 +05:30
Vikas Arora
831bd13168 Make tile size a function of encoding method.
Higher method implies more encoding effort (CPU) achieved with
smaller tile sizes (lower histo_bits).

Change-Id: Ic39c8d882c87835f74fde41172afb002ac3fd1c3
2012-05-18 12:16:39 +05:30
James Zern
778c52284b Merge "remove some variable shadowing" 2012-05-17 14:03:10 -07:00
Vikas Arora
817c9dce61 Few more HuffmanTreeToken conversions.
Change-Id: I932b5368d279f83c462c7d916978dab3e81d7709
2012-05-16 12:15:52 +05:30
James Zern
37a77a6bf4 remove some variable shadowing
Change-Id: I4348253ec6b50639095b22c4745dc26da0904466
2012-05-15 14:04:24 -07:00
pascal massimino
89c07c9660 Merge "normalize example header includes" 2012-05-15 13:50:27 -07:00