MNG/JNG decoder. Not in build.

This commit is contained in:
tor%cs.brown.edu 2001-05-21 14:27:45 +00:00
parent a110a92bba
commit 4ca27180ba
7 changed files with 991 additions and 0 deletions

View File

@ -0,0 +1,38 @@
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Tim Rowley.
# Portions created by Tim Rowley are
# Copyright (C) 2001 Tim Rowley. Rights Reserved.
#
# Contributor(s):
# Tim Rowley <tor@cs.brown.edu>
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = imgmng
LIBRARY_NAME = imgmng
IS_COMPONENT = 1
CPPSRCS = nsMNGDecoder.cpp nsMNGFactory.cpp imgContainerMNG.cpp
EXTRA_DSO_LDOPTS = $(MNG_LIBS) $(JPEG_LIBS) $(ZLIB_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1,562 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Tim Rowley.
* Portions created by Tim Rowley are
* Copyright (C) 2001 Tim Rowley. Rights Reserved.
*
* Contributor(s):
* Tim Rowley <tor@cs.brown.edu>
*/
#include "imgContainerMNG.h"
#include "nsIServiceManager.h"
#include "nsIInterfaceRequestor.h"
#include "gfxIImageFrame.h"
#include "nsIImage.h"
#include "nsIInputStream.h"
#include "imgIDecoderObserver.h"
#include "nsMemory.h"
static void il_mng_timeout_func(nsITimer *timer, void *data);
NS_IMPL_ISUPPORTS1(imgContainerMNG, imgIContainer)
//////////////////////////////////////////////////////////////////////////////
imgContainerMNG::imgContainerMNG() :
mObserver(0),
mDecoder(0),
mAnimationMode(0),
mFrozen(PR_FALSE)
{
NS_INIT_ISUPPORTS();
}
//////////////////////////////////////////////////////////////////////////////
imgContainerMNG::~imgContainerMNG()
{
if (mTimer) {
mTimer->Cancel();
mTimer = nsnull;
}
mng_display_freeze(mHandle);
mng_cleanup(&mHandle);
if (alpha)
nsMemory::Free(alpha);
if (image)
nsMemory::Free(image);
if (mBuffer)
nsMemory::Free(mBuffer);
mFrame = 0;
}
//****************************************************************************
/* void init (in nscoord aWidth, in nscoord aHeight, in imgIContainerObserver aObserver); */
NS_IMETHODIMP
imgContainerMNG::Init(nscoord aWidth,
nscoord aHeight,
imgIContainerObserver *aObserver)
{
if (aWidth <= 0 || aHeight <= 0) {
NS_WARNING("error - negative image size\n");
return NS_ERROR_FAILURE;
}
mSize.SizeTo(aWidth, aHeight);
mObserver = getter_AddRefs(NS_GetWeakReference(aObserver));
return NS_OK;
}
//****************************************************************************
/* readonly attribute gfx_format preferredAlphaChannelFormat; */
NS_IMETHODIMP
imgContainerMNG::GetPreferredAlphaChannelFormat(gfx_format *aFormat)
{
/* default.. platform's should probably overwrite this */
*aFormat = gfxIFormats::RGB_A8;
return NS_OK;
}
//****************************************************************************
/* readonly attribute nscoord width; */
NS_IMETHODIMP
imgContainerMNG::GetWidth(nscoord *aWidth)
{
*aWidth = mSize.width;
return NS_OK;
}
//****************************************************************************
/* readonly attribute nscoord height; */
NS_IMETHODIMP
imgContainerMNG::GetHeight(nscoord *aHeight)
{
*aHeight = mSize.height;
return NS_OK;
}
//****************************************************************************
/* readonly attribute gfxIImageFrame currentFrame; */
NS_IMETHODIMP
imgContainerMNG::GetCurrentFrame(gfxIImageFrame * *aCurrentFrame)
{
return mFrame->QueryInterface(NS_GET_IID(gfxIImageFrame),
(void**)aCurrentFrame);
}
//****************************************************************************
/* readonly attribute unsigned long numFrames; */
NS_IMETHODIMP
imgContainerMNG::GetNumFrames(PRUint32 *aNumFrames)
{
*aNumFrames = 1;
return NS_OK;
}
//****************************************************************************
/* gfxIImageFrame getFrameAt (in unsigned long index); */
NS_IMETHODIMP
imgContainerMNG::GetFrameAt(PRUint32 index, gfxIImageFrame **_retval)
{
return GetCurrentFrame(_retval);
}
//****************************************************************************
/* void appendFrame (in gfxIImageFrame item); */
NS_IMETHODIMP
imgContainerMNG::AppendFrame(gfxIImageFrame *item)
{
mFrame = item;
return NS_OK;
}
//****************************************************************************
/* void removeFrame (in gfxIImageFrame item); */
NS_IMETHODIMP
imgContainerMNG::RemoveFrame(gfxIImageFrame *item)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//****************************************************************************
/* void endFrameDecode (in gfxIImageFrame item, in unsigned long timeout); */
NS_IMETHODIMP
imgContainerMNG::EndFrameDecode(PRUint32 aFrameNum, PRUint32 aTimeout)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//****************************************************************************
/* void decodingComplete (); */
NS_IMETHODIMP
imgContainerMNG::DecodingComplete(void)
{
return NS_OK;
}
//****************************************************************************
/* nsIEnumerator enumerate (); */
NS_IMETHODIMP
imgContainerMNG::Enumerate(nsIEnumerator **_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
/* void clear (); */
NS_IMETHODIMP
imgContainerMNG::Clear()
{
mFrame = 0;
return NS_OK;
}
//****************************************************************************
/* void startAnimation () */
NS_IMETHODIMP
imgContainerMNG::StartAnimation()
{
if (mFrozen) {
mFrozen = PR_FALSE;
il_mng_timeout_func(0, (void *)mHandle);
}
return NS_OK;
}
//****************************************************************************
/* void stopAnimation (); */
NS_IMETHODIMP
imgContainerMNG::StopAnimation()
{
if (!mTimer)
return NS_OK;
else {
mTimer->Cancel();
mTimer = nsnull;
mFrozen = PR_TRUE;
}
return NS_OK;
}
//****************************************************************************
/* attribute long loopCount; */
NS_IMETHODIMP
imgContainerMNG::GetLoopCount(PRInt32 *aLoopCount)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
imgContainerMNG::SetLoopCount(PRInt32 aLoopCount)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//****************************************************************************
NS_IMETHODIMP
imgContainerMNG::GetAnimationMode(PRUint16 *aAnimationMode)
{
if (!aAnimationMode)
return NS_ERROR_NULL_POINTER;
*aAnimationMode = mAnimationMode;
return NS_OK;
}
NS_IMETHODIMP
imgContainerMNG::SetAnimationMode(PRUint16 aAnimationMode)
{
mAnimationMode = aAnimationMode;
return NS_OK;
}
// -------------------------------------------------------------------
// -------------------------------------------------------------------
// -------------------------------------------------------------------
#define EXTRACT_CONTAINER \
imgContainerMNG *container = (imgContainerMNG *)mng_get_userdata(handle)
//===========================================================
// Callbacks for libmng
//===========================================================
static mng_bool
il_mng_openstream(mng_handle handle)
{
return MNG_TRUE;
}
static mng_bool
il_mng_closestream(mng_handle handle)
{
return MNG_TRUE;
}
static mng_bool
il_mng_readdata(mng_handle handle, mng_ptr buf,
mng_uint32 size, mng_uint32 *stored)
{
EXTRACT_CONTAINER;
size = PR_MIN(size, container->mBufferEnd - container->mBufferPtr);
memcpy(buf, container->mBuffer + container->mBufferPtr, size);
container->mBufferPtr += size;
*stored = size;
return MNG_TRUE;
}
static mng_bool
il_mng_processheader(mng_handle handle, mng_uint32 width, mng_uint32 height)
{
EXTRACT_CONTAINER;
gfx_format format;
switch (mng_get_alphadepth(handle)) {
case 0:
format = gfxIFormats::RGB;
mng_set_canvasstyle(handle, MNG_CANVAS_RGB8);
break;
case 1:
format = gfxIFormats::RGB_A8;
mng_set_canvasstyle(handle, MNG_CANVAS_RGB8_A8);
break;
default:
format = gfxIFormats::RGB_A8;
mng_set_canvasstyle(handle, MNG_CANVAS_RGB8_A8);
break;
}
#ifdef XP_PC
format += 1;
#endif
nsMNGDecoder* decoder = container->mDecoder;
if (decoder->mObserver)
decoder->mObserver->OnStartDecode(nsnull, nsnull);
if(decoder->mImageContainer)
decoder->mImageContainer->Init(width,
height,
decoder->mObserver);
if (decoder->mObserver)
decoder->mObserver->OnStartContainer(nsnull,
nsnull,
decoder->mImageContainer);
// initalize the frame and append it to the container
decoder->mImageFrame = do_CreateInstance("@mozilla.org/gfx/image/frame;2");
decoder->mImageFrame->Init(0, 0, width, height, format);
decoder->mImageContainer->AppendFrame(decoder->mImageFrame);
if (decoder->mObserver)
decoder->mObserver->OnStartFrame(nsnull, nsnull, decoder->mImageFrame);
container->mFrame->GetImageBytesPerRow(&container->mByteWidth);
container->mFrame->GetAlphaBytesPerRow(&container->mByteWidthAlpha);
if ((format!=gfxIFormats::RGB) && (format!=gfxIFormats::BGR)) {
container->alpha =
(unsigned char*)nsMemory::Alloc(container->mByteWidthAlpha*height);
memset(container->alpha, 0, container->mByteWidthAlpha*height);
} else
container->alpha = 0;
container->image =
(unsigned char*)nsMemory::Alloc(container->mByteWidth*height);
memset(container->image, 0, container->mByteWidth*height);
return MNG_TRUE;
}
static mng_ptr
il_mng_getcanvasline(mng_handle handle, mng_uint32 iLine)
{
EXTRACT_CONTAINER;
return container->image+container->mByteWidth*iLine;
}
static mng_ptr
il_mng_getalphaline(mng_handle handle, mng_uint32 iLine)
{
EXTRACT_CONTAINER;
return container->alpha+container->mByteWidthAlpha*iLine;
}
static mng_bool
il_mng_refresh(mng_handle handle,
mng_uint32 left, mng_uint32 top,
mng_uint32 width, mng_uint32 height)
{
EXTRACT_CONTAINER;
PRUint32 bpr, abpr;
container->mFrame->GetImageBytesPerRow(&bpr);
container->mFrame->GetAlphaBytesPerRow(&abpr);
// stupid Mac code that shouldn't be in the image decoders...
#ifdef XP_MAC
nscoord width;
container->mFrame->GetWidth(&width);
PRUint32 iwidth = width;
PRUint8 *buf = nsMemory::Alloc(bpr);
#endif
for (mng_uint32 y=top; y<top+height; y++) {
#ifdef XP_MAC
PRUint8 *cptr = buf;
PRUint8 *row = container->iamge+y*container->mByteWidth;
for (PRUint32 x=0; x<iwidth; x++) {
*cptr++ = 0;
*cptr++ = *row++;
*cptr++ = *row++;
*cptr++ = *row++;
}
container->mFrame->SetImageData(buf, bpr, bpr*y);
#else
container->mFrame->SetImageData(container->image +
y*container->mByteWidth,
container->mByteWidth,
bpr*y);
#endif
if (container->alpha)
container->mFrame->SetAlphaData(container->alpha +
y*container->mByteWidthAlpha,
container->mByteWidthAlpha,
abpr*y);
}
nsRect r(left, top, width, height);
nsCOMPtr<imgIDecoderObserver>
ob(do_QueryReferent(container->mObserver));
if (ob)
ob->OnDataAvailable(nsnull, nsnull, container->mFrame, &r);
nsCOMPtr<imgIContainerObserver>
observer(do_QueryReferent(container->mObserver));
if (observer) {
nsRect dirtyRect;
container->mFrame->GetRect(dirtyRect);
// do notification to FE to draw this frame
observer->FrameChanged(container, nsnull, container->mFrame, &dirtyRect);
}
return MNG_TRUE;
}
static mng_uint32
il_mng_gettickcount(mng_handle handle)
{
return PR_IntervalToMilliseconds(PR_IntervalNow());
}
static void
il_mng_timeout_func(nsITimer *timer, void *data)
{
mng_handle handle = (mng_handle)data;
EXTRACT_CONTAINER;
if (container->mTimer) {
container->mTimer->Cancel();
container->mTimer = 0;
}
int ret = mng_display_resume(handle);
if (ret == MNG_NEEDMOREDATA)
container->mResumeNeeded = PR_TRUE;
}
static mng_bool
il_mng_settimer(mng_handle handle, mng_uint32 msec)
{
EXTRACT_CONTAINER;
container->mTimer = do_CreateInstance("@mozilla.org/timer;1");
container->mTimer->Init(il_mng_timeout_func, (void *)handle, msec);
return MNG_TRUE;
}
static mng_ptr
il_mng_alloc(mng_size_t size)
{
void *ptr = nsMemory::Alloc(size);
memset(ptr, 0, size);
return ptr;
}
static void
il_mng_free(mng_ptr ptr, mng_size_t size)
{
nsMemory::Free(ptr);
}
/* -----------------------------
* Setup an mng_struct for decoding.
*/
void
imgContainerMNG::InitMNG(nsMNGDecoder *decoder)
{
mDecoder = decoder;
// init data members
image = alpha = 0;
mBufferPtr = mBufferEnd = 0;
mBuffer = 0;
mResumeNeeded = PR_FALSE;
mTimer = 0;
// pass mng container as user data
mHandle = mng_initialize(this, il_mng_alloc, il_mng_free, NULL);
////////////
// Gamma correction - gross hack, but it's what mozilla's PNG
// decoder does and nobody has complained yet (except
// for me, but the bug is in eternal limbo)
double LUT_exponent, CRT_exponent = 2.2, display_exponent;
/* set up gamma correction for Mac, Unix and (Win32 and everything else)
* using educated guesses for display-system exponents; do preferences
* later */
#if defined(XP_MAC)
LUT_exponent = 1.8 / 2.61;
#elif defined(XP_UNIX)
# if defined(__sgi)
LUT_exponent = 1.0 / 1.7; /* typical default for SGI console */
# elif defined(NeXT)
LUT_exponent = 1.0 / 2.2; /* typical default for NeXT cube */
# else
LUT_exponent = 1.0; /* default for most other Unix workstations */
# endif
#else
LUT_exponent = 1.0; /* virtually all PCs and most other systems */
#endif
display_exponent = LUT_exponent * CRT_exponent;
mng_set_dfltimggamma(mHandle, 0.45455);
mng_set_displaygamma(mHandle, display_exponent);
////////////
mng_setcb_openstream(mHandle, il_mng_openstream);
mng_setcb_closestream(mHandle, il_mng_closestream);
mng_setcb_readdata(mHandle, il_mng_readdata);
mng_setcb_processheader(mHandle, il_mng_processheader);
mng_setcb_getcanvasline(mHandle, il_mng_getcanvasline);
mng_setcb_getalphaline(mHandle, il_mng_getalphaline);
mng_setcb_refresh(mHandle, il_mng_refresh);
mng_setcb_gettickcount(mHandle, il_mng_gettickcount);
mng_setcb_settimer(mHandle, il_mng_settimer);
mng_setcb_memalloc(mHandle, il_mng_alloc);
mng_setcb_memfree(mHandle, il_mng_free);
mng_set_suspensionmode(mHandle, MNG_TRUE);
if (mng_readdisplay(mHandle) == MNG_NEEDMOREDATA)
mResumeNeeded = PR_TRUE;
}
/* ----------------------------------------------------------
* Process data arriving from the stream for the MNG decoder.
*/
void
imgContainerMNG::WriteMNG(nsIInputStream *inStr,
PRInt32 count,
PRUint32 *_retval)
{
mBuffer = (PRUint8 *) nsMemory::Realloc(mBuffer, mBufferEnd+count);
inStr->Read((char *)mBuffer+mBufferEnd, count, _retval);
mBufferEnd += count;
if (mResumeNeeded) {
mResumeNeeded = PR_FALSE;
int ret = mng_display_resume(mHandle);
if (ret == MNG_NEEDMOREDATA)
mResumeNeeded = PR_TRUE;
}
}

View File

@ -0,0 +1,86 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Tim Rowley.
* Portions created by Tim Rowley are
* Copyright (C) 2001 Tim Rowley. Rights Reserved.
*
* Contributor(s):
* Tim Rowley <tor@cs.brown.edu>
*/
#ifndef _imgContainerMNG_h_
#define _imgContainerMNG_h_
#include "imgIContainerObserver.h"
#include "imgIContainer.h"
#include "nsSize.h"
#include "nsSupportsArray.h"
#include "nsCOMPtr.h"
#include "nsITimer.h"
#include "nsITimerCallback.h"
#include "imgIDecoderObserver.h"
#include "gfxIImageFrame.h"
#include "nsWeakReference.h"
#include "nsIInputStream.h"
#include "nsMNGDecoder.h"
#include "libmng.h"
#define NS_MNGCONTAINER_CID \
{ /* 7fc64c50-1dd2-11b2-85fe-997f8a1263d6 */ \
0x7fc64c50, \
0x1dd2, \
0x11b2, \
{0x85, 0xfe, 0x99, 0x7f, 0x8a, 0x12, 0x63, 0xd6} \
}
class imgContainerMNG : public imgIContainer
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGICONTAINER
imgContainerMNG();
virtual ~imgContainerMNG();
void WriteMNG(nsIInputStream *inStr, PRInt32 count, PRUint32 *_retval);
void InitMNG(nsMNGDecoder *decoder);
nsWeakPtr mObserver;
nsMNGDecoder *mDecoder;
nsCOMPtr<gfxIImageFrame> mFrame;
nsSize mSize;
PRUint16 mAnimationMode;
// Unfortunately we need to keep a copy of the image because partial
// reads in necko aren't guaranteed to work (darin 5/11/2001).
// Brute force for now, keeping the entire stream around.
PRUint8 *mBuffer; // copy of image stream
PRUint32 mBufferEnd; // size
PRUint32 mBufferPtr; // libmng current read location
PRUint8 *image; // full image buffer
PRUint8 *alpha; // full alpha buffer
mng_handle mHandle; // libmng handle
// PRUint32 mWidth; // width (for offset calcs)
// PRUint32 mHeight;
PRUint32 mByteWidth, mByteWidthAlpha;
nsCOMPtr<nsITimer> mTimer;
PRPackedBool mResumeNeeded; // display_resume call needed?
PRPackedBool mFrozen; // animation frozen?
};
#endif

View File

@ -0,0 +1,53 @@
#!nmake
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Tim Rowley.
# Portions created by Tim Rowley are
# Copyright (C) 2001 Tim Rowley. Rights Reserved.
#
# Contributor(s):
# Tim Rowley <tor@cs.brown.edu>
DEPTH=..\..\..\..
include <$(DEPTH)/config/config.mak>
MODULE = imgmng
LIBRARY_NAME = imgmng
DLL = $(OBJDIR)\$(LIBRARY_NAME).dll
MAKE_OBJ_TYPE = DLL
OBJS = \
.\$(OBJDIR)\nsMNGDecoder.obj \
.\$(OBJDIR)\imgContainerMNG.obj \
.\$(OBJDIR)\nsMNGFactory.obj \
$(NULL)
LLIBS=\
$(LIBNSPR) \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\mng.lib \
$(DIST)\lib\jpeg3250.lib \
$(DIST)\lib\zlib.lib \
$(DIST)\lib\gkgfxwin.lib \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(LIBRARY_NAME).lib $(DIST)\lib
clobber::
rm -f $(DIST)\bin\components\$(LIBRARY_NAME).dll
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib

View File

@ -0,0 +1,144 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Tim Rowley.
* Portions created by Tim Rowley are
* Copyright (C) 2001 Tim Rowley. Rights Reserved.
*
* Contributor(s):
* Tim Rowley <tor@cs.brown.edu>
*/
#include "nsMNGDecoder.h"
#include "nsIInputStream.h"
#include "nsIServiceManager.h"
#include "imgContainerMNG.h"
//////////////////////////////////////////////////////////////////////////////
// MNG Decoder Implementation
NS_IMPL_ISUPPORTS2(nsMNGDecoder, imgIDecoder, nsIOutputStream);
nsMNGDecoder::nsMNGDecoder()
{
NS_INIT_ISUPPORTS();
}
nsMNGDecoder::~nsMNGDecoder()
{
}
//////////////////////////////////////////////////////////////////////////////
//* imgIDecoder methods **/
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// void init (in imgIRequest aRequest); */
NS_IMETHODIMP
nsMNGDecoder::Init(imgIRequest *aRequest)
{
if(!aRequest) return NS_ERROR_FAILURE;
mImageRequest = aRequest;
mObserver =
do_QueryInterface(aRequest); // we're holding 2 strong refs to the request
if(!mObserver) return NS_ERROR_FAILURE;
mImageContainer =
do_CreateInstance("@mozilla.org/image/container;1?type=image/x-mng");
if(!mImageContainer) return NS_ERROR_OUT_OF_MEMORY;
aRequest->SetImage(mImageContainer);
/* do MNG init stuff */
NS_REINTERPRET_CAST(imgContainerMNG*, mImageContainer.get())->InitMNG(this);
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////////
// nsIOutputStream methods
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
// void close ();
NS_IMETHODIMP
nsMNGDecoder::Close()
{
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////////
/* void flush (); */
NS_IMETHODIMP
nsMNGDecoder::Flush()
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//////////////////////////////////////////////////////////////////////////////
// unsigned long write (in string buf, in unsigned long count);
NS_IMETHODIMP
nsMNGDecoder::Write(const char *buf, PRUint32 count, PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//////////////////////////////////////////////////////////////////////////////
// unsigned long writeFrom (in nsIInputStream inStr, in unsigned long count);
NS_IMETHODIMP
nsMNGDecoder::WriteFrom(nsIInputStream *inStr,
PRUint32 count,
PRUint32 *_retval)
{
NS_REINTERPRET_CAST(imgContainerMNG*, mImageContainer.get())->WriteMNG(inStr, count, _retval);
return NS_OK;
}
//////////////////////////////////////////////////////////////////////////////
// [noscript] unsigned long writeSegments (in nsReadSegmentFun reader, in voidPtr closure, in unsigned long count);
NS_IMETHODIMP
nsMNGDecoder::WriteSegments(nsReadSegmentFun reader,
void * closure,
PRUint32 count,
PRUint32 *_retval)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//////////////////////////////////////////////////////////////////////////////
// attribute boolean nonBlocking;
NS_IMETHODIMP
nsMNGDecoder::GetNonBlocking(PRBool *aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMNGDecoder::SetNonBlocking(PRBool aNonBlocking)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
//////////////////////////////////////////////////////////////////////////////
// attribute nsIOutputStreamObserver observer;
NS_IMETHODIMP
nsMNGDecoder::GetObserver(nsIOutputStreamObserver * *aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsMNGDecoder::SetObserver(nsIOutputStreamObserver * aObserver)
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -0,0 +1,60 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Tim Rowley.
* Portions created by Tim Rowley are
* Copyright (C) 2001 Tim Rowley. Rights Reserved.
*
* Contributor(s):
* Tim Rowley <tor@cs.brown.edu>
*/
#ifndef _nsMNGDecoder_h_
#define _nsMNGDecoder_h_
#include "nsCOMPtr.h"
#include "imgIDecoder.h"
#include "imgIContainer.h"
#include "imgIDecoderObserver.h"
#include "gfxIImageFrame.h"
#include "imgIRequest.h"
#include "nsWeakReference.h"
#define NS_MNGDECODER_CID \
{ /* d407782c-1dd1-11b2-9b49-dbe684d09cd8 */ \
0xd407782c, \
0x1dd1, \
0x11b2, \
{0x9b, 0x49, 0xdb, 0xe6, 0x84, 0xd0, 0x9c, 0xd8} \
}
//////////////////////////////////////////////////////////////////////
// MNG Decoder Definition
class nsMNGDecoder : public imgIDecoder
{
public:
NS_DECL_ISUPPORTS
NS_DECL_IMGIDECODER
NS_DECL_NSIOUTPUTSTREAM
nsMNGDecoder();
virtual ~nsMNGDecoder();
nsCOMPtr<imgIContainer> mImageContainer;
nsCOMPtr<gfxIImageFrame> mImageFrame;
nsCOMPtr<imgIRequest> mImageRequest;
nsCOMPtr<imgIDecoderObserver> mObserver; // this is just qi'd from mRequest for speed
};
#endif

View File

@ -0,0 +1,48 @@
/*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Tim Rowley.
* Portions created by Tim Rowley are
* Copyright (C) 2001 Tim Rowley. Rights Reserved.
*
* Contributor(s):
* Tim Rowley <tor@cs.brown.edu>
*/
#include "nsIGenericFactory.h"
#include "nsIModule.h"
#include "nsMNGDecoder.h"
#include "imgContainerMNG.h"
// objects that just require generic constructors
NS_GENERIC_FACTORY_CONSTRUCTOR(nsMNGDecoder)
NS_GENERIC_FACTORY_CONSTRUCTOR(imgContainerMNG)
static nsModuleComponentInfo components[] =
{
{ "MNG decoder",
NS_MNGDECODER_CID,
"@mozilla.org/image/decoder;2?type=video/x-mng",
nsMNGDecoderConstructor, },
{ "JNG decoder",
NS_MNGDECODER_CID,
"@mozilla.org/image/decoder;2?type=image/x-jng",
nsMNGDecoderConstructor, },
{ "MNG/JNG image container",
NS_MNGCONTAINER_CID,
"@mozilla.org/image/container;1?type=image/x-mng",
imgContainerMNGConstructor, },
};
NS_IMPL_NSGETMODULE(nsMNGDecoderModule, components)