scroggo | 19b9153 | 2016-10-24 09:03:26 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Copyright (C) 2015 Google Inc. All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions and the following disclaimer. |
| 16 | * 2. Redistributions in binary form must reproduce the above copyright |
| 17 | * notice, this list of conditions and the following disclaimer in the |
| 18 | * documentation and/or other materials provided with the distribution. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 21 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 24 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 25 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 26 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 27 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 28 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | #ifndef SkCodecAnimation_DEFINED |
| 34 | #define SkCodecAnimation_DEFINED |
| 35 | |
| 36 | #include "SkCodec.h" |
| 37 | #include "SkRect.h" |
| 38 | |
| 39 | class SkCodecAnimation { |
| 40 | public: |
| 41 | |
| 42 | // GIF and WebP support animation. The explanation below is in terms of GIF, |
| 43 | // but the same constants are used for WebP, too. |
| 44 | // GIFs have an optional 16-bit unsigned loop count that describes how an |
| 45 | // animated GIF should be cycled. If the loop count is absent, the animation |
| 46 | // cycles once; if it is 0, the animation cycles infinitely; otherwise the |
| 47 | // animation plays n + 1 cycles (where n is the specified loop count). If the |
| 48 | // GIF decoder defaults to kAnimationLoopOnce in the absence of any loop count |
| 49 | // and translates an explicit "0" loop count to kAnimationLoopInfinite, then we |
| 50 | // get a couple of nice side effects: |
| 51 | // * By making kAnimationLoopOnce be 0, we allow the animation cycling code to |
| 52 | // avoid special-casing it, and simply treat all non-negative loop counts |
| 53 | // identically. |
| 54 | // * By making the other two constants negative, we avoid conflicts with any |
| 55 | // real loop count values. |
| 56 | static const int kAnimationLoopOnce = 0; |
| 57 | static const int kAnimationLoopInfinite = -1; |
| 58 | static const int kAnimationNone = -2; |
| 59 | |
| 60 | /** |
| 61 | * This specifies how the next frame is based on this frame. |
| 62 | * |
| 63 | * Names are based on the GIF 89a spec. |
| 64 | * |
| 65 | * The numbers correspond to values in a GIF. |
| 66 | */ |
| 67 | enum DisposalMethod { |
| 68 | /** |
| 69 | * The next frame should be drawn on top of this one. |
| 70 | * |
| 71 | * In a GIF, a value of 0 (not specified) is also treated as Keep. |
| 72 | */ |
| 73 | Keep_DisposalMethod = 1, |
| 74 | |
| 75 | /** |
| 76 | * Similar to Keep, except the area inside this frame's rectangle |
| 77 | * should be cleared to the BackGround color (transparent) before |
| 78 | * drawing the next frame. |
| 79 | */ |
| 80 | RestoreBGColor_DisposalMethod = 2, |
| 81 | |
| 82 | /** |
| 83 | * The next frame should be drawn on top of the previous frame - i.e. |
| 84 | * disregarding this one. |
| 85 | * |
| 86 | * In a GIF, a value of 4 is also treated as RestorePrevious. |
| 87 | */ |
| 88 | RestorePrevious_DisposalMethod = 3, |
| 89 | }; |
| 90 | |
| 91 | private: |
| 92 | SkCodecAnimation(); |
| 93 | }; |
| 94 | #endif // SkCodecAnimation_DEFINED |