Attachment #480490: WebP implementation for bug #600919

View | Details | Raw Unified | Return to bug 600919
Collapse All | Expand All

(-)a/browser/components/BrowserComponents.manifest (+3 lines)
Line     Link Here 
 Lines 15-30   contract @mozilla.org/uriloader/content- Link Here 
15
contract @mozilla.org/uriloader/content-handler;1?type=text/plain {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
15
contract @mozilla.org/uriloader/content-handler;1?type=text/plain {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
16
contract @mozilla.org/uriloader/content-handler;1?type=image/gif {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
16
contract @mozilla.org/uriloader/content-handler;1?type=image/gif {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
17
contract @mozilla.org/uriloader/content-handler;1?type=image/jpeg {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
17
contract @mozilla.org/uriloader/content-handler;1?type=image/jpeg {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
18
contract @mozilla.org/uriloader/content-handler;1?type=image/jpg {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
18
contract @mozilla.org/uriloader/content-handler;1?type=image/jpg {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
19
contract @mozilla.org/uriloader/content-handler;1?type=image/png {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
19
contract @mozilla.org/uriloader/content-handler;1?type=image/png {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
20
contract @mozilla.org/uriloader/content-handler;1?type=image/bmp {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
20
contract @mozilla.org/uriloader/content-handler;1?type=image/bmp {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
21
contract @mozilla.org/uriloader/content-handler;1?type=image/x-icon {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
21
contract @mozilla.org/uriloader/content-handler;1?type=image/x-icon {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
22
contract @mozilla.org/uriloader/content-handler;1?type=image/vnd.microsoft.icon {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
22
contract @mozilla.org/uriloader/content-handler;1?type=image/vnd.microsoft.icon {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
23
#ifdef MOZ_WEBM
24
contract @mozilla.org/uriloader/content-handler;1?type=image/webp {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
25
#endif
23
contract @mozilla.org/uriloader/content-handler;1?type=application/http-index-format {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
26
contract @mozilla.org/uriloader/content-handler;1?type=application/http-index-format {5d0ce354-df01-421a-83fb-7ead0990c24e} application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
24
category command-line-handler m-browser @mozilla.org/browser/clh;1 application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
27
category command-line-handler m-browser @mozilla.org/browser/clh;1 application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
25
category command-line-handler x-default @mozilla.org/browser/final-clh;1 application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
28
category command-line-handler x-default @mozilla.org/browser/final-clh;1 application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
26
category command-line-validator b-browser @mozilla.org/browser/clh;1 application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
29
category command-line-validator b-browser @mozilla.org/browser/clh;1 application={ec8030f7-c20a-464f-9b0e-13a3a9e97384}
27
30
28
# nsBrowserGlue.js
31
# nsBrowserGlue.js
29
component {eab9012e-5f74-4cbc-b2b5-a590235513cc} nsBrowserGlue.js
32
component {eab9012e-5f74-4cbc-b2b5-a590235513cc} nsBrowserGlue.js
30
contract @mozilla.org/browser/browserglue;1 {eab9012e-5f74-4cbc-b2b5-a590235513cc}
33
contract @mozilla.org/browser/browserglue;1 {eab9012e-5f74-4cbc-b2b5-a590235513cc}
(-)a/modules/libpr0n/build/nsImageModule.cpp (+3 lines)
Line     Link Here 
 Lines 139-154   static const mozilla::Module::CategoryEn Link Here 
139
  { "Gecko-Content-Viewers", "image/jpg", "@mozilla.org/content/document-loader-factory;1" },
139
  { "Gecko-Content-Viewers", "image/jpg", "@mozilla.org/content/document-loader-factory;1" },
140
  { "Gecko-Content-Viewers", "image/x-icon", "@mozilla.org/content/document-loader-factory;1" },
140
  { "Gecko-Content-Viewers", "image/x-icon", "@mozilla.org/content/document-loader-factory;1" },
141
  { "Gecko-Content-Viewers", "image/vnd.microsoft.icon", "@mozilla.org/content/document-loader-factory;1" },
141
  { "Gecko-Content-Viewers", "image/vnd.microsoft.icon", "@mozilla.org/content/document-loader-factory;1" },
142
  { "Gecko-Content-Viewers", "image/bmp", "@mozilla.org/content/document-loader-factory;1" },
142
  { "Gecko-Content-Viewers", "image/bmp", "@mozilla.org/content/document-loader-factory;1" },
143
  { "Gecko-Content-Viewers", "image/x-ms-bmp", "@mozilla.org/content/document-loader-factory;1" },
143
  { "Gecko-Content-Viewers", "image/x-ms-bmp", "@mozilla.org/content/document-loader-factory;1" },
144
  { "Gecko-Content-Viewers", "image/icon", "@mozilla.org/content/document-loader-factory;1" },
144
  { "Gecko-Content-Viewers", "image/icon", "@mozilla.org/content/document-loader-factory;1" },
145
  { "Gecko-Content-Viewers", "image/png", "@mozilla.org/content/document-loader-factory;1" },
145
  { "Gecko-Content-Viewers", "image/png", "@mozilla.org/content/document-loader-factory;1" },
146
  { "Gecko-Content-Viewers", "image/x-png", "@mozilla.org/content/document-loader-factory;1" },
146
  { "Gecko-Content-Viewers", "image/x-png", "@mozilla.org/content/document-loader-factory;1" },
147
#ifdef MOZ_WEBM
148
  { "Gecko-Content-Viewers", "image/webp", "@mozilla.org/content/document-loader-factory;1" },
149
#endif
147
  { "content-sniffing-services", "@mozilla.org/image/loader;1", "@mozilla.org/image/loader;1" },
150
  { "content-sniffing-services", "@mozilla.org/image/loader;1", "@mozilla.org/image/loader;1" },
148
  { NULL }
151
  { NULL }
149
};
152
};
150
153
151
static nsresult
154
static nsresult
152
imglib_Initialize()
155
imglib_Initialize()
153
{
156
{
154
  // Hack: We need the gfx module to be initialized because we use gfxPlatform
157
  // Hack: We need the gfx module to be initialized because we use gfxPlatform
(-)a/modules/libpr0n/decoders/Makefile.in (+1 lines)
Line     Link Here 
 Lines 46-61   MODULE = imgdecoders Link Here 
46
LIBRARY_NAME = imgdecoders_s
46
LIBRARY_NAME = imgdecoders_s
47
FORCE_STATIC_LIB = 1
47
FORCE_STATIC_LIB = 1
48
MODULE_NAME = nsDecodersModule
48
MODULE_NAME = nsDecodersModule
49
LIBXUL_LIBRARY  = 1
49
LIBXUL_LIBRARY  = 1
50
50
51
51
52
CPPSRCS = nsPNGDecoder.cpp nsJPEGDecoder.cpp nsGIFDecoder2.cpp \
52
CPPSRCS = nsPNGDecoder.cpp nsJPEGDecoder.cpp nsGIFDecoder2.cpp \
53
          nsBMPDecoder.cpp nsICODecoder.cpp nsIconDecoder.cpp \
53
          nsBMPDecoder.cpp nsICODecoder.cpp nsIconDecoder.cpp \
54
          nsWebPDecoder.cpp \
54
          $(NULL)
55
          $(NULL)
55
56
56
CSRCS   = iccjpeg.c \
57
CSRCS   = iccjpeg.c \
57
          $(NULL)
58
          $(NULL)
58
59
59
# Decoders need RasterImage.h
60
# Decoders need RasterImage.h
60
LOCAL_INCLUDES += -I$(topsrcdir)/modules/libpr0n/src/
61
LOCAL_INCLUDES += -I$(topsrcdir)/modules/libpr0n/src/
61
62
(-)a/modules/libpr0n/decoders/nsWebPDecoder.cpp (+285 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 * ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is WebP Decoder.
16
 *
17
 * The Initial Developer of the Original Code is Google Inc.
18
 * Portions created by the Initial Developer are Copyright (C) 2010
19
 * the Initial Developer. All Rights Reserved.
20
 *
21
 * Contributor(s):
22
 *   Aaron Kaluszka <ask@swva.net>
23
 *
24
 * Alternatively, the contents of this file may be used under the terms of
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 * of those above. If you wish to allow use of your version of this file only
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 * use your version of this file under the terms of the MPL, indicate your
31
 * decision by deleting the provisions above and replace them with the notice
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
36
 * ***** END LICENSE BLOCK ***** */
37
38
#include "nsWebPDecoder.h"
39
40
#include "nsIInputStream.h"
41
#include "RasterImage.h"
42
#include "imgIContainerObserver.h"
43
44
#include "prlog.h"
45
46
namespace mozilla {
47
namespace imagelib {
48
49
#ifdef PR_LOGGING
50
PRLogModuleInfo *gWebPLog = PR_NewLogModule("WebPDecoder");
51
#endif
52
53
nsWebPDecoder::nsWebPDecoder() :
54
  mWidth(-1),
55
  mHeight(-1),
56
  mPos(0),
57
  mData(nsnull),
58
  mIter(nsnull)
59
{
60
  if (!sInitDone) {
61
    // Initialize look-up tables for YUV to RGB conversion
62
    for (PRInt32 i = 0; i < 256; ++i)
63
    {
64
      sVToR[i] = ( 89858 * (i - 128) + RGB_HALF) >> RGB_FRAC;
65
      sUToG[i] =  -22014 * (i - 128) + RGB_HALF;
66
      sVToG[i] =  -45773 * (i - 128);
67
      sUToB[i] = (113618 * (i - 128) + RGB_HALF) >> RGB_FRAC;
68
    }
69
    for (PRInt32 i = RGB_RANGE_MIN; i < RGB_RANGE_MAX; ++i) {
70
      const PRInt32 j = ((i - 16) * 76283 + RGB_HALF) >> RGB_FRAC;
71
      sClip[i - RGB_RANGE_MIN] = (j < 0) ? 0 : (j > 255) ? 255 : j;
72
    }
73
    sInitDone = PR_TRUE;
74
  }
75
}
76
77
nsWebPDecoder::~nsWebPDecoder()
78
{
79
  if (mData)
80
    free(mData);
81
}
82
83
void nsWebPDecoder::InitInternal()
84
{
85
  // Initialize libvpx
86
  if (vpx_codec_dec_init(&mDec, &vpx_codec_vp8_dx_algo, NULL, 0) != VPX_CODEC_OK) {
87
    PostDecoderError(NS_ERROR_FAILURE);
88
    return;
89
  }
90
91
  mPPCfg.post_proc_flag = VP8_NOFILTERING;
92
  vpx_codec_control(&mDec, VP8_SET_POSTPROC, &mPPCfg);
93
}
94
95
void
96
nsWebPDecoder::WriteInternal(const char *aBuffer, PRUint32 aCount)
97
{
98
  NS_ABORT_IF_FALSE(!HasError(), "Shouldn't call WriteInternal after error!");
99
100
  // aCount = 0 means EOF, mWidth set means image has been processed
101
  if (!aCount || mWidth != -1)
102
    return;
103
104
  // RIFF layout is:
105
  // Offset  Data
106
  // 0...3   "RIFF" 4-byte tag
107
  // 4...7   Size of image data (including metadata) starting at offset 8
108
  // 8...11  "WEBP" Form-type signature
109
  // 12..15  "VP8 " 4-byte tag describing the raw video format used
110
  // 16..19  Size of the raw WebP image data, starting at offset 20
111
  // 20....  The WebP bytes
112
  // There can be extra chunks after the "VP8 " chunk (ICMT, ICOP, ...)
113
  // All 32-bits sizes are in little-endian order.
114
  // Note: chunk data must be padded to multiple of 2 in size
115
  if (mPos < RIFF_HEADER_LENGTH) {
116
    PRUint32 toCopy = RIFF_HEADER_LENGTH - mPos;
117
    if (toCopy > aCount)
118
      toCopy = aCount;
119
    memcpy(mHeaderData + mPos, aBuffer, toCopy);
120
    mPos += toCopy;
121
    aCount -= toCopy;
122
    aBuffer += toCopy;
123
  }
124
125
  if (mPos == RIFF_HEADER_LENGTH) {
126
    if (memcmp(mHeaderData,      "RIFF", 4)) {
127
      PostDataError(); // wrong image file signature
128
      return;
129
	}
130
    if (memcmp(mHeaderData +  8, "WEBP", 4)) {
131
      PostDataError(); // wrong image file signature
132
      return;
133
	}
134
    if (memcmp(mHeaderData + 12, "VP8 ", 4)) {
135
      PostDataError(); // invalid compression format
136
      return;
137
	}
138
    mDataLength = LITTLE_TO_NATIVE32(*(PRUint32*)(mHeaderData + 16));
139
    if ((mDataLength > LITTLE_TO_NATIVE32(*(PRUint32*)(mHeaderData + 4)) + 8) || (mDataLength & 1)) {
140
      PostDataError(); // inconsistent size information
141
      return;
142
	}
143
	mData = (PRUint8*)moz_malloc(mDataLength);
144
	if (!mData) {
145
      PostDecoderError(NS_ERROR_OUT_OF_MEMORY);
146
      return;
147
    }
148
  }
149
  
150
  // XXX Currently no progressive decoding support, so grab all image data
151
  if (aCount && mPos >= RIFF_HEADER_LENGTH && mPos < RIFF_HEADER_LENGTH + mDataLength) {
152
    PRUint32 toCopy = RIFF_HEADER_LENGTH + mDataLength - mPos;
153
    if (toCopy > aCount)
154
      toCopy = aCount;
155
    memcpy(mData + mPos - RIFF_HEADER_LENGTH, aBuffer, toCopy);
156
    mPos += toCopy;
157
    aCount -= toCopy;
158
    aBuffer += toCopy;
159
  }
160
161
  if (mPos == RIFF_HEADER_LENGTH + mDataLength - 1) {
162
    // Avoid full decode for size query
163
    if (IsSizeDecode()) {
164
	  vpx_codec_stream_info_t streamInfo;
165
      if (vpx_codec_peek_stream_info(&vpx_codec_vp8_dx_algo, mData, mDataLength, &streamInfo) != VPX_CODEC_OK) {
166
        PostDataError();
167
        return;
168
      }
169
170
      mWidth = streamInfo.w;
171
      mHeight = streamInfo.h;
172
      PR_LOG(gWebPLog, PR_LOG_DEBUG, ("WebP image is %lix%lix.\n", mWidth, mHeight));
173
      // Post our size to the superclass
174
      PostSize(mWidth, mHeight);
175
      return;
176
    }
177
178
    // Decode data with libvpx
179
	if (vpx_codec_decode(&mDec, mData, mDataLength, NULL, 0) != VPX_CODEC_OK) {
180
      PostDataError();
181
      return;
182
    }
183
184
    // Get image frame from libvpx
185
    vpx_image_t* const imageFrame = vpx_codec_get_frame(&mDec, &mIter);
186
    if (!imageFrame) {
187
      PostDataError();
188
      return;
189
    }
190
191
    mWidth = imageFrame->d_w;
192
    mHeight = imageFrame->d_h;
193
    PR_LOG(gWebPLog, PR_LOG_DEBUG, ("WebP image is %lix%lix.\n", mWidth, mHeight));
194
    // Post our size to the superclass
195
    PostSize(mWidth, mHeight);
196
197
    PRUint32 imageLength;
198
    PRUint32* imageData;
199
    nsresult rv = mImage->AppendFrame(0, 0, mWidth, mHeight, gfxASurface::ImageFormatARGB32, 
200
                                      (PRUint8**)&imageData, &imageLength);
201
    if (NS_FAILED(rv) || !imageData) {
202
      PostDecoderError(NS_ERROR_FAILURE);
203
      return;
204
    }
205
206
    // Tell the superclass we're starting a frame
207
    PostFrameStart();
208
209
    // Get YUV data from decoder
210
    PRUint8* YSrc = imageFrame->planes[0];
211
    PRUint8* USrc = imageFrame->planes[1];
212
    PRUint8* VSrc = imageFrame->planes[2];
213
    PRUint32* Dst = imageData;
214
    PRUint32 YStride = imageFrame->stride[0];
215
    PRUint32 UStride = imageFrame->stride[1];
216
    PRUint32 VStride = imageFrame->stride[2];
217
218
    // Generate ARGB image from YUV data (with height upsampling of chroma data)
219
    for (PRInt32 y = 0; y < (mHeight >> 1); ++y)
220
    {
221
      YUV420toARGBLine(Dst, YSrc, USrc, VSrc);
222
	  YSrc += YStride;
223
      YUV420toARGBLine(Dst, YSrc, USrc, VSrc);
224
	  YSrc += YStride;
225
	  USrc += UStride;
226
	  VSrc += VStride;
227
    }
228
    if(mHeight & 1) // Bottom row (if image has odd height)
229
      YUV420toARGBLine(Dst, YSrc, USrc, VSrc);
230
231
    // Invalidate
232
    nsIntRect r(0, 0, mWidth, mHeight);
233
    PostInvalidation(r);
234
  }
235
}
236
237
void
238
nsWebPDecoder::FinishInternal()
239
{
240
  // We shouldn't be called in error cases
241
  NS_ABORT_IF_FALSE(!HasError(), "Can't call FinishInternal on error!");
242
243
  vpx_codec_destroy(&mDec);
244
245
  // We should never make multiple frames
246
  NS_ABORT_IF_FALSE(GetFrameCount() <= 1, "Multiple WebP frames?");
247
248
  // Send notifications if appropriate
249
  if (!IsSizeDecode() && (GetFrameCount() == 1)) {
250
      PostFrameStop();
251
      PostDecodeDone();
252
  }
253
}
254
255
// Converts YUV to RGB and writes into a 32 bit pixel in endian-neutral fashion
256
inline void
257
nsWebPDecoder::SetPixel(PRUint32*& aDst, PRUint8 aY, PRUint8 aU, PRUint8 aV, PRUint8 aAlpha = 0xFF)
258
{
259
  *aDst++ = GFX_PACKED_PIXEL(aAlpha, 
260
    sClip[aY + sVToR[aV] - RGB_RANGE_MIN], 
261
    sClip[aY + ((sVToG[aV] + sUToG[aU]) >> RGB_FRAC) - RGB_RANGE_MIN], 
262
    sClip[aY + sUToB[aU] - RGB_RANGE_MIN]);
263
}
264
265
// Generate ARGB row from an YUV row (with width upsampling of chroma data)
266
void 
267
nsWebPDecoder::YUV420toARGBLine(PRUint32*& aDst, PRUint8* aYSrc, PRUint8* aUSrc, PRUint8* aVSrc)
268
{
269
  for (PRInt32 x = 0; x < (mWidth >> 1); ++x) {
270
    SetPixel(aDst, *aYSrc++, *aUSrc,   *aVSrc  );
271
    SetPixel(aDst, *aYSrc++, *aUSrc++, *aVSrc++);
272
  }
273
  if (mWidth & 1) // Right-most pixel (if image has odd width)
274
    SetPixel(aDst, *aYSrc++, *aUSrc++, *aVSrc++);
275
}
276
277
PRBool nsWebPDecoder::sInitDone = PR_FALSE;
278
PRInt16 nsWebPDecoder::sVToR[256];
279
PRInt16 nsWebPDecoder::sUToB[256];
280
PRInt32 nsWebPDecoder::sVToG[256];
281
PRInt32 nsWebPDecoder::sUToG[256];
282
PRUint8 nsWebPDecoder::sClip[RGB_RANGE_MAX - RGB_RANGE_MIN];
283
284
} // namespace imagelib
285
} // namespace mozilla
(-)a/modules/libpr0n/decoders/nsWebPDecoder.h (+121 lines)
Line     Link Here 
Line 0    Link Here 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2
 * ***** BEGIN LICENSE BLOCK *****
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4
 *
5
 * The contents of this file are subject to the Mozilla Public License Version
6
 * 1.1 (the "License"); you may not use this file except in compliance with
7
 * the License. You may obtain a copy of the License at
8
 * http://www.mozilla.org/MPL/
9
 *
10
 * Software distributed under the License is distributed on an "AS IS" basis,
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
 * for the specific language governing rights and limitations under the
13
 * License.
14
 *
15
 * The Original Code is WebP Decoder.
16
 *
17
 * The Initial Developer of the Original Code is Google Inc.
18
 * Portions created by the Initial Developer are Copyright (C) 2010
19
 * the Initial Developer. All Rights Reserved.
20
 *
21
 * Contributor(s):
22
 *   Aaron Kaluszka <ask@swva.net>
23
 *
24
 * Alternatively, the contents of this file may be used under the terms of
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
28
 * of those above. If you wish to allow use of your version of this file only
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
30
 * use your version of this file under the terms of the MPL, indicate your
31
 * decision by deleting the provisions above and replace them with the notice
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
33
 * the provisions above, a recipient may use your version of this file under
34
 * the terms of any one of the MPL, the GPL or the LGPL.
35
 *
36
 * ***** END LICENSE BLOCK ***** */
37
38
#ifndef nsWebMDecoder_h__
39
#define nsWebMDecoder_h__
40
41
#include "Decoder.h"
42
#include "nsAutoPtr.h"
43
#include "imgIDecoderObserver.h"
44
#include "vpx/vpx_decoder.h"
45
#include "vpx/vp8dx.h"
46
47
namespace mozilla {
48
namespace imagelib {
49
50
class nsWebPDecoder : public Decoder
51
{
52
public:
53
  nsWebPDecoder();
54
  virtual ~nsWebPDecoder();
55
56
  virtual void InitInternal();
57
  virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);
58
  virtual void FinishInternal();
59
60
  enum {
61
    RIFF_HEADER_LENGTH = 20,
62
63
    RGB_FRAC = 16,
64
    RGB_HALF = (1 << RGB_FRAC) / 2,
65
    RGB_RANGE_MIN = -227,
66
    RGB_RANGE_MAX = 256 + 226
67
  };
68
69
  // Static look-up tables for YUV to RGB conversion
70
  static PRInt16 sVToR[256];
71
  static PRInt16 sUToB[256];
72
  static PRInt32 sVToG[256];
73
  static PRInt32 sUToG[256];
74
  static PRUint8 sClip[RGB_RANGE_MAX - RGB_RANGE_MIN];
75
76
  static PRBool sInitDone; // Are static members initialized?
77
78
private:
79
  /** Converts YUV to RGB and writes into a 32 bit pixel in endian neutral fashion
80
   * The exact naming is Y'CbCr, following the ITU-R BT.601 standard.
81
   * More information at: http://en.wikipedia.org/wiki/YCbCr
82
   * @param aDst pointer to pixel to be set, will be incremented to point to the next pixel
83
   * @param aY Y value
84
   * @param aU U value
85
   * @param aV V value
86
   */
87
  inline void SetPixel(PRUint32*& aDst, PRUint8 aY, PRUint8 aU, PRUint8 aV, PRUint8 aAlpha);
88
89
  /** Generate ARGB row from an YUV row (with width upsampling of chroma data)
90
   * @param aDst pointer to row of pixels to be set, will be incremented to point to the next row
91
   * @param aYSrc pointer to row of Y pixels
92
   * @param aUsrc pointer to row of V pixels
93
   * @param aVSrc pointer to row of U pixels
94
   */
95
  void YUV420toARGBLine(PRUint32*& aDst, PRUint8* aYSrc, PRUint8* aUSrc, PRUint8* aVSrc);
96
97
#if defined WORDS_BIGENDIAN || defined IS_BIG_ENDIAN
98
#define LITTLE_TO_NATIVE32(x) (((((PRUint32) x)        & 0xFF) << 24) | \
99
                              (((((PRUint32) x) >>  8) & 0xFF) << 16) | \
100
                              (((((PRUint32) x) >> 16) & 0xFF) <<  8) | \
101
                                (((PRUint32) x) >> 24))
102
#else
103
#define LITTLE_TO_NATIVE32(x) x
104
#endif
105
106
  PRUint32 mWidth;
107
  PRUint32 mHeight;
108
  PRUint32 mPos;  // Current processing position in incoming data
109
  PRUint8  mHeaderData[RIFF_HEADER_LENGTH];  // Image header data
110
  PRUint8 *mData;  // Pointer to WebP-encoded data
111
  PRUint32 mDataLength;  // Length of WebP-encoded data
112
113
  vpx_codec_ctx_t mDec;  // libvpx decoder
114
  vp8_postproc_cfg_t mPPCfg; // libvpx configuration
115
  vpx_codec_iter_t mIter;  // libvpx iterator
116
};
117
118
} // namespace imagelib
119
} // namespace mozilla
120
121
#endif // nsWebPDecoder_h__
(-)a/modules/libpr0n/src/Image.cpp (+6 lines)
Line     Link Here 
 Lines 92-107   Image::GetDecoderType(const char *aMimeT Link Here 
92
    rv = eDecoderType_ico;
92
    rv = eDecoderType_ico;
93
  else if (!strcmp(aMimeType, "image/vnd.microsoft.icon"))
93
  else if (!strcmp(aMimeType, "image/vnd.microsoft.icon"))
94
    rv = eDecoderType_ico;
94
    rv = eDecoderType_ico;
95
95
96
  // Icon
96
  // Icon
97
  else if (!strcmp(aMimeType, "image/icon"))
97
  else if (!strcmp(aMimeType, "image/icon"))
98
    rv = eDecoderType_icon;
98
    rv = eDecoderType_icon;
99
99
100
#ifdef MOZ_WEBM
101
  // WebP
102
  else if (!strcmp(aMimeType, "image/webp"))
103
    rv = eDecoderType_webp;
104
#endif
105
100
  return rv;
106
  return rv;
101
}
107
}
102
108
103
void
109
void
104
Image::IncrementAnimationConsumers()
110
Image::IncrementAnimationConsumers()
105
{
111
{
106
  mAnimationConsumers++;
112
  mAnimationConsumers++;
107
  EvaluateAnimation();
113
  EvaluateAnimation();
(-)a/modules/libpr0n/src/Image.h (+5 lines)
Line     Link Here 
 Lines 98-114   public: Link Here 
98
  // Mimetype translation
98
  // Mimetype translation
99
  enum eDecoderType {
99
  enum eDecoderType {
100
    eDecoderType_png     = 0,
100
    eDecoderType_png     = 0,
101
    eDecoderType_gif     = 1,
101
    eDecoderType_gif     = 1,
102
    eDecoderType_jpeg    = 2,
102
    eDecoderType_jpeg    = 2,
103
    eDecoderType_bmp     = 3,
103
    eDecoderType_bmp     = 3,
104
    eDecoderType_ico     = 4,
104
    eDecoderType_ico     = 4,
105
    eDecoderType_icon    = 5,
105
    eDecoderType_icon    = 5,
106
#ifdef MOZ_WEBM
107
    eDecoderType_webp    = 6,
108
    eDecoderType_unknown = 7
109
#else
106
    eDecoderType_unknown = 6
110
    eDecoderType_unknown = 6
111
#endif
107
  };
112
  };
108
  static eDecoderType GetDecoderType(const char *aMimeType);
113
  static eDecoderType GetDecoderType(const char *aMimeType);
109
114
110
  void IncrementAnimationConsumers();
115
  void IncrementAnimationConsumers();
111
  void DecrementAnimationConsumers();
116
  void DecrementAnimationConsumers();
112
#ifdef DEBUG
117
#ifdef DEBUG
113
  PRUint32 GetAnimationConsumers() { return mAnimationConsumers; }
118
  PRUint32 GetAnimationConsumers() { return mAnimationConsumers; }
114
#endif
119
#endif
(-)a/modules/libpr0n/src/RasterImage.cpp (+8 lines)
Line     Link Here 
 Lines 59-74    Link Here 
59
#include "ImageLogging.h"
59
#include "ImageLogging.h"
60
60
61
#include "nsPNGDecoder.h"
61
#include "nsPNGDecoder.h"
62
#include "nsGIFDecoder2.h"
62
#include "nsGIFDecoder2.h"
63
#include "nsJPEGDecoder.h"
63
#include "nsJPEGDecoder.h"
64
#include "nsBMPDecoder.h"
64
#include "nsBMPDecoder.h"
65
#include "nsICODecoder.h"
65
#include "nsICODecoder.h"
66
#include "nsIconDecoder.h"
66
#include "nsIconDecoder.h"
67
#ifdef MOZ_WEBM
68
#include "nsWebPDecoder.h"
69
#endif
67
70
68
#include "gfxContext.h"
71
#include "gfxContext.h"
69
72
70
using namespace mozilla::imagelib;
73
using namespace mozilla::imagelib;
71
74
72
/* Accounting for compressed data */
75
/* Accounting for compressed data */
73
#if defined(PR_LOGGING)
76
#if defined(PR_LOGGING)
74
static PRLogModuleInfo *gCompressedImageAccountingLog = PR_NewLogModule ("CompressedImageAccounting");
77
static PRLogModuleInfo *gCompressedImageAccountingLog = PR_NewLogModule ("CompressedImageAccounting");
 Lines 2138-2153   RasterImage::InitDecoder(bool aDoSizeDec Link Here 
2138
      mDecoder = new nsBMPDecoder();
2141
      mDecoder = new nsBMPDecoder();
2139
      break;
2142
      break;
2140
    case eDecoderType_ico:
2143
    case eDecoderType_ico:
2141
      mDecoder = new nsICODecoder();
2144
      mDecoder = new nsICODecoder();
2142
      break;
2145
      break;
2143
    case eDecoderType_icon:
2146
    case eDecoderType_icon:
2144
      mDecoder = new nsIconDecoder();
2147
      mDecoder = new nsIconDecoder();
2145
      break;
2148
      break;
2149
#ifdef MOZ_WEBM
2150
    case eDecoderType_webp:
2151
      mDecoder = new nsWebPDecoder();
2152
      break;
2153
#endif
2146
    default:
2154
    default:
2147
      NS_ABORT_IF_FALSE(0, "Shouldn't get here!");
2155
      NS_ABORT_IF_FALSE(0, "Shouldn't get here!");
2148
  }
2156
  }
2149
2157
2150
  // Initialize the decoder
2158
  // Initialize the decoder
2151
  nsCOMPtr<imgIDecoderObserver> observer(do_QueryReferent(mObserver));
2159
  nsCOMPtr<imgIDecoderObserver> observer(do_QueryReferent(mObserver));
2152
  mDecoder->SetSizeDecode(aDoSizeDecode);
2160
  mDecoder->SetSizeDecode(aDoSizeDecode);
2153
  mDecoder->Init(this, observer);
2161
  mDecoder->Init(this, observer);
(-)a/netwerk/mime/nsMimeTypes.h (+1 lines)
Line     Link Here 
 Lines 116-131    Link Here 
116
#define IMAGE_XBM3                          "image/xbm"
116
#define IMAGE_XBM3                          "image/xbm"
117
#define IMAGE_ART                           "image/x-jg"
117
#define IMAGE_ART                           "image/x-jg"
118
#define IMAGE_TIFF                          "image/tiff"
118
#define IMAGE_TIFF                          "image/tiff"
119
#define IMAGE_BMP                           "image/bmp"
119
#define IMAGE_BMP                           "image/bmp"
120
#define IMAGE_ICO                           "image/x-icon"
120
#define IMAGE_ICO                           "image/x-icon"
121
#define IMAGE_MNG                           "video/x-mng"
121
#define IMAGE_MNG                           "video/x-mng"
122
#define IMAGE_JNG                           "image/x-jng"
122
#define IMAGE_JNG                           "image/x-jng"
123
#define IMAGE_SVG_XML                       "image/svg+xml"
123
#define IMAGE_SVG_XML                       "image/svg+xml"
124
#define IMAGE_WEBP                          "image/webp"
124
125
125
#define MESSAGE_EXTERNAL_BODY               "message/external-body"
126
#define MESSAGE_EXTERNAL_BODY               "message/external-body"
126
#define MESSAGE_NEWS                        "message/news"
127
#define MESSAGE_NEWS                        "message/news"
127
#define MESSAGE_RFC822                      "message/rfc822"
128
#define MESSAGE_RFC822                      "message/rfc822"
128
129
129
#define MULTIPART_ALTERNATIVE               "multipart/alternative"
130
#define MULTIPART_ALTERNATIVE               "multipart/alternative"
130
#define MULTIPART_APPLEDOUBLE               "multipart/appledouble"
131
#define MULTIPART_APPLEDOUBLE               "multipart/appledouble"
131
#define MULTIPART_DIGEST                    "multipart/digest"
132
#define MULTIPART_DIGEST                    "multipart/digest"
(-)a/uriloader/exthandler/nsExternalHelperAppService.cpp (+4 lines)
Line     Link Here 
 Lines 509-524   static nsDefaultMimeTypeEntry defaultMim Link Here 
509
  { TEXT_XML, "xml" },
509
  { TEXT_XML, "xml" },
510
  { APPLICATION_RDF, "rdf" },
510
  { APPLICATION_RDF, "rdf" },
511
  { TEXT_XUL, "xul" },
511
  { TEXT_XUL, "xul" },
512
  { IMAGE_PNG, "png" },
512
  { IMAGE_PNG, "png" },
513
  // -- end extensions used during startup
513
  // -- end extensions used during startup
514
  { TEXT_CSS, "css" },
514
  { TEXT_CSS, "css" },
515
  { IMAGE_JPG, "jpeg" },
515
  { IMAGE_JPG, "jpeg" },
516
  { IMAGE_JPG, "jpg" },
516
  { IMAGE_JPG, "jpg" },
517
#ifdef MOZ_WEBM
518
  { IMAGE_WEBP, "webp" },
519
#endif
517
  { TEXT_HTML, "html" },
520
  { TEXT_HTML, "html" },
518
  { TEXT_HTML, "htm" },
521
  { TEXT_HTML, "htm" },
519
  { APPLICATION_XPINSTALL, "xpi" },
522
  { APPLICATION_XPINSTALL, "xpi" },
520
  { "application/xhtml+xml", "xhtml" },
523
  { "application/xhtml+xml", "xhtml" },
521
  { "application/xhtml+xml", "xht" },
524
  { "application/xhtml+xml", "xht" },
522
  { TEXT_PLAIN, "txt" }
525
  { TEXT_PLAIN, "txt" }
523
};
526
};
524
527
 Lines 577-592   static nsExtraMimeTypeEntry extraMimeEnt Link Here 
577
  { TEXT_XUL, "xul", "XML-Based User Interface Language" },
580
  { TEXT_XUL, "xul", "XML-Based User Interface Language" },
578
  { TEXT_XML, "xml,xsl,xbl", "Extensible Markup Language" },
581
  { TEXT_XML, "xml,xsl,xbl", "Extensible Markup Language" },
579
  { TEXT_CSS, "css", "Style Sheet" },
582
  { TEXT_CSS, "css", "Style Sheet" },
580
  { VIDEO_OGG, "ogv", "Ogg Video" },
583
  { VIDEO_OGG, "ogv", "Ogg Video" },
581
  { VIDEO_OGG, "ogg", "Ogg Video" },
584
  { VIDEO_OGG, "ogg", "Ogg Video" },
582
  { APPLICATION_OGG, "ogg", "Ogg Video"},
585
  { APPLICATION_OGG, "ogg", "Ogg Video"},
583
  { AUDIO_OGG, "oga", "Ogg Audio" },
586
  { AUDIO_OGG, "oga", "Ogg Audio" },
584
#ifdef MOZ_WEBM
587
#ifdef MOZ_WEBM
588
  { IMAGE_WEBP, "webp", "WebP Image" },
585
  { VIDEO_WEBM, "webm", "Web Media Video" },
589
  { VIDEO_WEBM, "webm", "Web Media Video" },
586
  { AUDIO_WEBM, "webm", "Web Media Audio" },
590
  { AUDIO_WEBM, "webm", "Web Media Audio" },
587
#endif
591
#endif
588
  { VIDEO_RAW, "yuv", "Raw YUV Video" },
592
  { VIDEO_RAW, "yuv", "Raw YUV Video" },
589
  { AUDIO_WAV, "wav", "Waveform Audio" },
593
  { AUDIO_WAV, "wav", "Waveform Audio" },
590
};
594
};
591
595
592
#undef MAC_TYPE
596
#undef MAC_TYPE

Return to bug 600919