fixing bug 78690. removing old imagelib. r=jst sr=waterson

git-svn-id: svn://10.0.0.236/trunk@100674 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
pavlov%netscape.com 2001-08-09 20:35:08 +00:00
parent 460155a537
commit 88cf3b5fcb
85 changed files with 0 additions and 17637 deletions

View File

@ -1,145 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIImageGroup_h___
#define nsIImageGroup_h___
#include <stdio.h>
#include "nsISupports.h"
#include "nscore.h"
#include "nsColor.h"
class nsIImageGroupObserver;
class nsIImageRequestObserver;
class nsIImageRequest;
class nsIDeviceContext;
class nsIStreamListener;
class nsILoadGroup;
/** For important images, like backdrops. */
#define nsImageLoadFlags_kHighPriority 0x01
/** Don't throw this image out of cache. */
#define nsImageLoadFlags_kSticky 0x02
/** Don't get image out of image cache. */
#define nsImageLoadFlags_kBypassCache 0x04
/** Don't load if image cache misses. */
#define nsImageLoadFlags_kOnlyFromCache 0x08
// IID for the nsIImageGroup interface
#define NS_IIMAGEGROUP_IID \
{ 0xbe927e40, 0xaeaa, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
/**
*
* Image group. A convenient way to group a set of image load requests
* and control them as a group.
*/
class nsIImageGroup : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMAGEGROUP_IID)
/**
* Initialize an image group with a device context. All images
* in this group will be decoded for the specified device context.
*/
virtual nsresult Init(nsIDeviceContext *aDeviceContext, nsISupports *aLoadContext) = 0;
/**
* Add an observers to be informed of image group notifications.
*
* @param aObserver - An observer to add to the observer list.
* @param boolean indicating whether addition was successful.
*/
virtual PRBool AddObserver(nsIImageGroupObserver *aObserver) = 0;
/**
* Remove a previously added observer from the observer list.
*
* @param aObserver - An observer to remove from the observer list.
* @param boolean indicating whether the removal was successful.
*/
virtual PRBool RemoveObserver(nsIImageGroupObserver *aObserver) = 0;
/**
* Fetch the image corresponding to the specified URL.
*
* @param aUrl - the URL of the image to be loaded.
* @param aObserver - the observer is notified at significant
* points in image loading.
* @param aWidth, aHeight - These parameters specify the target
* dimensions of the image. The image will be stretched
* horizontally, vertically or both to meet these parameters.
* If both width and height are zero, the image is decoded
* using its "natural" size. If only one of width and height
* is zero, the image is scaled to the provided dimension, with
* the unspecified dimension scaled to maintain the image's
* original aspect ratio.
* @param aBackgroundColor - If the background color is NULL, a mask
* will be generated for any transparent images. If background
* color is non-NULL, it indicates the RGB value to be painted
* into the image for "transparent" areas of the image, in which
* case no mask is created. This is intended for backdrops and
* printing.
* @param aFlags - image loading flags are specified above
*
* @return the resulting image request object.
*/
virtual nsIImageRequest* GetImage(const char* aUrl,
nsIImageRequestObserver *aObserver,
const nscolor* aBackgroundColor,
PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags) = 0;
/**
* Like GetImage except load the image from a live stream.
* The call returns an nsIImageRequest and an nsIStreamListener
* that should be connected to the live stream to accept
* the image data.
*/
NS_IMETHOD GetImageFromStream(const char* aURL,
nsIImageRequestObserver *aObserver,
const nscolor* aBackgroundColor,
PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags,
nsIImageRequest*& aResult,
nsIStreamListener*& aListenerResult) = 0;
/**
* Halt decoding of images or animation without destroying associated
* pixmap data. All ImageRequests created with this ImageGroup
* are interrupted.
*/
virtual void Interrupt(void) = 0;
NS_IMETHOD SetImgLoadAttributes(PRUint32 a_grouploading_attribs)=0;
NS_IMETHOD GetImgLoadAttributes(PRUint32 *a_grouploading_attribs)=0;
};
/// Factory method for creating an image group
extern "C" NS_GFX_(nsresult)
NS_NewImageGroup(nsIImageGroup **aInstancePtrResult);
#endif

View File

@ -1,99 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIImageManager_h___
#define nsIImageManager_h___
#include <stdio.h>
#include "nsISupports.h"
#include "nscore.h"
typedef enum
{
nsImageType_kUnknown = 0,
nsImageType_kGIF = 1,
nsImageType_kXBM = 2,
nsImageType_kJPEG = 3,
nsImageType_kPPM = 4,
nsImageType_kPNG = 5,
nsImageType_kART = 6
} nsImageType;
// IID for the nsIImageManager interface
#define NS_IIMAGEMANAGER_IID \
{ 0x9f327100, 0xad5a, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
/**
*
* Image manager. There is only a single instance, returned when invoking
* the factory instantiation method. A user of the image library should
* hold on to the singleton image manager.
*/
class nsIImageManager : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMAGEMANAGER_IID)
/// Initialization method to be called before use
virtual nsresult Init() = 0;
/// Set the size (in bytes) image cache maintained by the image manager
virtual void SetCacheSize(PRInt32 aCacheSize) = 0;
/// @return the current size of the image cache (in bytes)
virtual PRInt32 GetCacheSize(void) = 0;
/**
* Attempts to release some memory by freeing an image from the image
* cache. This may not always be possible either because all images
* in the cache are in use or because the cache is empty.
*
* @return the new approximate size of the imagelib cache.
*/
virtual PRInt32 ShrinkCache(void) = 0;
/**
* Flush the image cache as much as possible. The only images not
* flushed out will be those that are in use.
*/
NS_IMETHOD FlushCache(PRUint8 img_catagory) = 0;
/**
* Determine the type of the image, based on the first few bytes of data.
*
* @param buf - a buffer of image data
* @param length - the length of the buffer
*
* @return the type of the image, if known
*/
// virtual nsImageType GetImageType(const char *buf, PRInt32 length) = 0;
};
/// Factory method to get a reference to the singleton image manager
extern "C" NS_GFX_(nsresult)
NS_NewImageManager(nsIImageManager **aInstancePtrResult);
extern "C" NS_GFX_(void)
NS_FreeImageManager();
#endif

View File

@ -1,175 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIImageObserver_h___
#define nsIImageObserver_h___
#include <stdio.h>
#include "nsISupports.h"
#include "nscore.h"
class nsIImage;
class nsIImageRequest;
class nsIImageGroup;
/// Image request notifications
typedef enum {
nsImageNotification_kStartURL, // Start of decode/display for URL.
nsImageNotification_kDescription, // Availability of image description.
nsImageNotification_kDimensions, // Availability of image dimensions.
nsImageNotification_kIsTransparent, // This image is transparent.
nsImageNotification_kPixmapUpdate, // Change in a rectangular area of
// pixels.
nsImageNotification_kFrameComplete, // Completion of a frame of an animated
// image.
nsImageNotification_kProgress, // Notification of percentage decoded.
nsImageNotification_kImageComplete, // Completion of image decoding. There
// may be multiple instances of this
// event per URL due to server push,
// client pull or looping GIF animation.
nsImageNotification_kStopURL, // Completion of decode/display for URL.
nsImageNotification_kImageDestroyed,// Finalization of an image request. This
// is an indication to perform any
// observer related cleanup.
nsImageNotification_kAborted, // Image decode was aborted by either
// the network library or Interrupt().
nsImageNotification_kInternalImage // Internal image icon.
} nsImageNotification;
/// Image group notifications
typedef enum {
// Start of image loading. Sent when a loading image is
// added to an image group which currently has no loading images.
nsImageGroupNotification_kStartedLoading,
// Some images were aborted. A finished loading message will not be sent
// until the aborted images have been destroyed.
nsImageGroupNotification_kAbortedLoading,
// End of image loading. Sent when the last of the images currently
// in the image group has finished loading.
nsImageGroupNotification_kFinishedLoading,
// Start of image looping. Sent when an animated image starts looping in
// an image group which currently has no looping animations.
nsImageGroupNotification_kStartedLooping,
// End of image looping. Sent when the last of the images currently in
// the image group has finished looping.
nsImageGroupNotification_kFinishedLooping
} nsImageGroupNotification;
/// Image loading errors
typedef enum {
nsImageError_kNotInCache, // Image URL not available in cache when
// kOnlyFromCache flag was set.
nsImageError_kNoData, // Network library unable to fetch
// provided URL.
nsImageError_kImageDataCorrupt, // Checksum error of some kind in
// image data.
nsImageError_kImageDataTruncated, // Missing data at end of stream.
nsImageError_kImageDataIllegal, // Generic image data error.
nsImageError_kInternalError // Internal Image Library error.
} nsImageError;
// IID for the nsIImageRequestObserver interface
#define NS_IIMAGEREQUESTOBSERVER_IID \
{ 0x965467a0, 0xb8f4, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
// IID for the nsIImageGroupObserver interface
#define NS_IIMAGEGROUPOBSERVER_IID \
{ 0xb3cad300, 0xb8f4, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
/**
* Image request observer interface. The implementor will be notified
* of significant loading events or loading errors.
*/
class nsIImageRequestObserver : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMAGEREQUESTOBSERVER_IID)
/**
* Notify the observer of some significant image event. The parameter
* values depend on the notification type as specified below.
*
* kDescription - aParam3 is a string containing the human readable
* description of an image, e.g. "GIF89a 320 x 240 pixels".
* The string storage is static, so it must be copied if
* it is to be preserved after the call to the observer.
* kDimensions - aParam1 and aParam2 are the width and height respectively
* of the image in pixels.
* kPixmapUpdate - aParame3 is a pointer to a nsRect struct containing the
* rectangular area of pixels which has been modified by
* the image library. This notification enables the
* client to drive the progressive display of the image.
* kProgress - aParam1 represents the estimated percentage decoded. This
* notification occurs at unspecified intervals. Provided
* that decoding proceeds without error, it is guaranteed that
* notification will take place on completion with a
* percent_progress value of 100.
*
* @param aImageRequest - the image request in question
* @param aImage - the corresponding image object
* @param aNotificationType - the type of notification
* @param aParam1, aParam2, aParam3 - additional information as described
* above.
*/
virtual void Notify(nsIImageRequest *aImageRequest,
nsIImage *aImage,
nsImageNotification aNotificationType,
PRInt32 aParam1, PRInt32 aParam2,
void *aParam3)=0;
/**
* Notify the observer of an error during image loading.
*
* @param aImageRequest - the image request in question
* @param aErrorType - the error code
*/
virtual void NotifyError(nsIImageRequest *aImageRequest,
nsImageError aErrorType)=0;
};
/**
* Image group observer interface. The implementor will be notified
* of significant image group events.
*/
class nsIImageGroupObserver : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMAGEGROUPOBSERVER_IID)
/**
* Notify the observer of some significant image group event.
*
* @param aImageGroup - the image group in question
* @param aNotificationType - the notification code
*/
virtual void Notify(nsIImageGroup *aImageGroup,
nsImageGroupNotification aNotificationType)=0;
};
#endif

View File

@ -1,81 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIImageRequest_h___
#define nsIImageRequest_h___
#include <stdio.h>
#include "nsISupports.h"
#include "nscore.h"
class nsIImageRequestObserver;
class nsIImage;
// IID for the nsIImageRequest interface
#define NS_IIMAGEREQUEST_IID \
{ 0xc31444c0, 0xaec9, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
/**
*
* An image request generated as a result of invoking the
* <code>GetImage</code> method of the <code>nsIImageGroup</code>
* interface.
*/
class nsIImageRequest : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMAGEREQUEST_IID)
/// @return the image object associated with the request.
virtual nsIImage* GetImage() = 0;
/**
* Returns the natural dimensions of the image. Returns 0,0
* if the dimensions are unknown.
*
* Note: the dimensions that are returned are in pixels
*
* @param aWidth, aHeight - pointers to integers to be filled in with
* the dimensions.
*/
virtual void GetNaturalDimensions(PRUint32 *aWidth, PRUint32 *aHeight) = 0;
/**
* Add an observers to be informed of image loading notifications.
*
* @param aObserver - An observer to add to the observer list.
* @param boolean indicating whether addition was successful.
*/
virtual PRBool AddObserver(nsIImageRequestObserver *aObserver) = 0;
/**
* Remove a previously added observer from the observer list.
*
* @param aObserver - An observer to remove from the observer list.
* @param boolean indicating whether the removal was successful.
*/
virtual PRBool RemoveObserver(nsIImageRequestObserver *aObserver) = 0;
/// Interrupt loading of just this image.
virtual void Interrupt() = 0;
};
#endif

View File

@ -1,386 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsIServiceManager.h"
#include "nsIImageGroup.h"
#include "nsIImageManager.h"
#include "nsIImageObserver.h"
#include "nsIImageRequest.h"
#include "nsImageRequest.h"
#include "ilIImageRenderer.h"
#include "nsImageNet.h"
#include "nsVoidArray.h"
#include "nsCRT.h"
#include "libimg.h"
#include "il_util.h"
#include "nsIDeviceContext.h"
#include "nsIStreamListener.h"
#include "nsGfxCIID.h"
static NS_DEFINE_IID(kImageManagerCID, NS_IMAGEMANAGER_CID);
class ImageGroupImpl : public nsIImageGroup
{
public:
ImageGroupImpl(nsIImageManager *aManager);
virtual ~ImageGroupImpl();
nsresult Init(nsIDeviceContext *aDeviceContext, nsISupports * aLoadContext);
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
virtual PRBool AddObserver(nsIImageGroupObserver *aObserver);
virtual PRBool RemoveObserver(nsIImageGroupObserver *aObserver);
virtual nsIImageRequest* GetImage(const char* aUrl,
nsIImageRequestObserver *aObserver,
const nscolor* aBackgroundColor,
PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags);
NS_IMETHOD GetImageFromStream(const char* aURL,
nsIImageRequestObserver *aObserver,
const nscolor* aBackgroundColor,
PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags,
nsIImageRequest*& aResult,
nsIStreamListener*& aListenerResult);
virtual void Interrupt(void);
IL_GroupContext *GetGroupContext() { return mGroupContext; }
nsVoidArray *GetObservers() { return mObservers; }
NS_IMETHOD SetImgLoadAttributes(PRUint32 a_grouploading_attribs);
NS_IMETHOD GetImgLoadAttributes(PRUint32 *a_grouploading_attribs);
nsIImageManager *mManager;
IL_GroupContext *mGroupContext;
nsVoidArray *mObservers;
nsIDeviceContext *mDeviceContext;
ilINetContext* mNetContext;
nsIStreamListener** mListenerRequest;
//ptn
PRUint32 m_grouploading_attribs;
};
ImageGroupImpl::ImageGroupImpl(nsIImageManager *aManager)
{
NS_INIT_REFCNT();
mManager = aManager;
NS_ADDREF(mManager);
}
ImageGroupImpl::~ImageGroupImpl()
{
NS_IF_RELEASE(mDeviceContext);
if (mObservers != nsnull) {
PRInt32 i, count = mObservers->Count();
nsIImageGroupObserver *observer;
for (i = 0; i < count; i++) {
observer = (nsIImageGroupObserver *)mObservers->ElementAt(i);
if (observer != nsnull) {
NS_RELEASE(observer);
}
}
delete mObservers;
}
if (mGroupContext != nsnull) {
IL_DestroyGroupContext(mGroupContext);
}
NS_IF_RELEASE(mManager);
NS_IF_RELEASE(mNetContext);
}
NS_IMPL_ISUPPORTS1(ImageGroupImpl, nsIImageGroup)
static void ns_observer_proc (XP_Observable aSource,
XP_ObservableMsg aMsg,
void* aMsgData,
void* aClosure)
{
ImageGroupImpl *image_group = (ImageGroupImpl *)aClosure;
nsVoidArray *observer_list = image_group->GetObservers();
if (observer_list != nsnull) {
PRInt32 i, count = observer_list->Count();
nsIImageGroupObserver *observer;
for (i = 0; i < count; i++) {
observer = (nsIImageGroupObserver *)observer_list->ElementAt(i);
if (observer != nsnull) {
switch (aMsg) {
case IL_STARTED_LOADING:
observer->Notify(image_group,
nsImageGroupNotification_kStartedLoading);
break;
case IL_ABORTED_LOADING:
observer->Notify(image_group,
nsImageGroupNotification_kAbortedLoading);
case IL_FINISHED_LOADING:
observer->Notify(image_group,
nsImageGroupNotification_kFinishedLoading);
case IL_STARTED_LOOPING:
observer->Notify(image_group,
nsImageGroupNotification_kStartedLooping);
case IL_FINISHED_LOOPING:
observer->Notify(image_group,
nsImageGroupNotification_kFinishedLooping);
}
}
}
}
}
static PRBool
ReconnectHack(void* arg, nsIStreamListener* aListener)
{
ImageGroupImpl* ig = (ImageGroupImpl*) arg;
if (nsnull != ig->mListenerRequest) {
*ig->mListenerRequest = aListener;
NS_ADDREF(aListener);
return PR_TRUE;
}
return PR_FALSE;
}
nsresult
ImageGroupImpl::Init(nsIDeviceContext *aDeviceContext, nsISupports *aLoadContext)
{
ilIImageRenderer *renderer;
nsresult result;
if ((result = NS_NewImageRenderer(&renderer)) != NS_OK) {
return result;
}
mGroupContext = IL_NewGroupContext((void *)aDeviceContext,
renderer);
if (mGroupContext == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Create an async net context
result = NS_NewImageNetContext(&mNetContext, aLoadContext, ReconnectHack, this);
if (NS_OK != result) {
return result;
}
mDeviceContext = aDeviceContext;
NS_ADDREF(mDeviceContext);
// Get color space to use for this device context.
IL_ColorSpace* colorSpace;
mDeviceContext->GetILColorSpace(colorSpace);
// Set the image group context display mode
IL_DisplayData displayData;
displayData.dither_mode = IL_Auto;
displayData.color_space = colorSpace;
displayData.progressive_display = PR_TRUE;
IL_SetDisplayMode(mGroupContext,
IL_COLOR_SPACE | IL_PROGRESSIVE_DISPLAY | IL_DITHER_MODE,
&displayData);
// Release the color space
IL_ReleaseColorSpace(colorSpace);
return NS_OK;
}
PRBool
ImageGroupImpl::AddObserver(nsIImageGroupObserver *aObserver)
{
if (aObserver == nsnull) {
return PR_FALSE;
}
if (mObservers == nsnull) {
mObservers = new nsVoidArray();
if (mObservers == nsnull) {
return PR_FALSE;
}
IL_AddGroupObserver(mGroupContext, ns_observer_proc, (void *)this);
}
NS_ADDREF(aObserver);
mObservers->AppendElement((void *)aObserver);
return PR_TRUE;
}
PRBool
ImageGroupImpl::RemoveObserver(nsIImageGroupObserver *aObserver)
{
PRBool ret;
if (aObserver == nsnull || mObservers == nsnull) {
return PR_FALSE;
}
ret = mObservers->RemoveElement((void *)aObserver);
if (ret == PR_TRUE) {
NS_RELEASE(aObserver);
}
return ret;
}
nsIImageRequest*
ImageGroupImpl::GetImage(const char* aUrl,
nsIImageRequestObserver *aObserver,
const nscolor* aBackgroundColor,
PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags)
{
NS_PRECONDITION(nsnull != aUrl, "null URL");
ImageRequestImpl *image_req = new ImageRequestImpl;
if (nsnull != image_req) {
nsresult result;
// Ask the image request object to get the image.
PRUint32 groupload_attrib = 0;
GetImgLoadAttributes(&groupload_attrib);
if(!aFlags)
aFlags = groupload_attrib;
mListenerRequest = nsnull;
result = image_req->Init(mGroupContext, aUrl, aObserver, aBackgroundColor,
aWidth, aHeight, aFlags, mNetContext);
if (NS_SUCCEEDED(result)) {
NS_ADDREF(image_req);
} else {
delete image_req;
image_req = nsnull;
}
}
return image_req;
}
NS_IMETHODIMP
ImageGroupImpl::GetImageFromStream(const char* aUrl,
nsIImageRequestObserver *aObserver,
const nscolor* aBackgroundColor,
PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags,
nsIImageRequest*& aResult,
nsIStreamListener*& aListenerResult)
{
NS_PRECONDITION(nsnull != aUrl, "null URL");
nsresult result = NS_OK;
ImageRequestImpl *image_req = new ImageRequestImpl;
if (nsnull == image_req) {
return NS_ERROR_OUT_OF_MEMORY;
}
// Ask the image request object to get the image.
nsIStreamListener* listener = nsnull;
mListenerRequest = &listener;
PRUint32 groupload_attrib = 0;
GetImgLoadAttributes(&groupload_attrib);
if(!aFlags)
aFlags = groupload_attrib;
result = image_req->Init(mGroupContext, aUrl, aObserver, aBackgroundColor,
aWidth, aHeight, aFlags, mNetContext);
aListenerResult = listener;
mListenerRequest = nsnull;
if (NS_SUCCEEDED(result)) {
NS_ADDREF(image_req);
} else {
delete image_req;
image_req = nsnull;
}
aResult = image_req;
return result;
}
void
ImageGroupImpl::Interrupt(void)
{
if (mGroupContext != nsnull) {
IL_InterruptContext(mGroupContext);
}
}
NS_IMETHODIMP
ImageGroupImpl::SetImgLoadAttributes(PRUint32 a_grouploading_attribs){
m_grouploading_attribs = a_grouploading_attribs;
return NS_OK;
}
NS_IMETHODIMP
ImageGroupImpl::GetImgLoadAttributes(PRUint32 *a_grouploading_attribs){
*a_grouploading_attribs = m_grouploading_attribs;
return NS_OK;
}
extern "C" NS_GFX_(nsresult)
NS_NewImageGroup(nsIImageGroup **aInstancePtrResult)
{
nsresult result;
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsCOMPtr<nsIImageManager> manager;
manager = do_GetService(kImageManagerCID, &result);
if (NS_FAILED(result)) {
/* This is just to provide backwards compatibility, until the ImageManagerImpl
can be converted to a service on all platforms. Once, we done the conversion
on all platforms, we should be removing the call to NS_NewImageManager(...)
*/
if ((result = NS_NewImageManager(getter_AddRefs(manager))) != NS_OK) {
return result;
}
}
nsIImageGroup *group = new ImageGroupImpl(manager);
if (group == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return group->QueryInterface(NS_GET_IID(nsIImageGroup), (void **) aInstancePtrResult);
}

View File

@ -1,182 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsIImageManager.h"
#include "nsIMemory.h"
#include "nsIObserver.h"
#include "nsIObserverService.h"
#include "nsWeakReference.h"
#include "nsString.h"
#include "nsIServiceManager.h"
#include "libimg.h"
#include "nsCRT.h"
#include "nsImageNet.h"
#include "nsCOMPtr.h"
#include "nsIPref.h"
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
static NS_DEFINE_IID(kIImageManagerIID, NS_IIMAGEMANAGER_IID);
class ImageManagerImpl : public nsIImageManager,
public nsIObserver,
public nsSupportsWeakReference
{
public:
ImageManagerImpl();
virtual ~ImageManagerImpl();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
virtual nsresult Init();
virtual void SetCacheSize(PRInt32 aCacheSize);
virtual PRInt32 GetCacheSize(void);
virtual PRInt32 ShrinkCache(void);
NS_IMETHOD FlushCache(PRUint8 img_catagory);
// virtual nsImageType GetImageType(const char *buf, PRInt32 length);
private:
nsCOMPtr<ilISystemServices> mSS;
};
// The singleton image manager
// This a service on XP_PC , mac and gtk. Need to convert
// it to a service on all the remaining platforms.
static ImageManagerImpl* gImageManager = nsnull;
ImageManagerImpl::ImageManagerImpl()
{
NS_INIT_REFCNT();
NS_NewImageSystemServices(getter_AddRefs(mSS));
IL_Init(mSS);
PRInt32 cacheSize = (1024L * 2048L);
nsresult res = NS_ERROR_FAILURE;
nsCOMPtr<nsIPref> prefs(do_GetService(kPrefCID, &res));
if (prefs)
{
PRInt32 tempSize;
res = prefs->GetIntPref("browser.cache.image_cache_size", &tempSize);
if ( NS_SUCCEEDED(res) )
{
cacheSize = tempSize * 1024L;
}
}
IL_SetCacheSize(cacheSize);
}
ImageManagerImpl::~ImageManagerImpl()
{
IL_Shutdown();
gImageManager = nsnull;
}
NS_IMPL_ISUPPORTS3(ImageManagerImpl,
nsIImageManager,
nsIObserver,
nsISupportsWeakReference);
nsresult
ImageManagerImpl::Init()
{
nsCOMPtr<nsIObserverService> os =
do_GetService(NS_OBSERVERSERVICE_CONTRACTID);
if (os)
os->AddObserver(this, NS_MEMORY_PRESSURE_TOPIC);
return NS_OK;
}
void
ImageManagerImpl::SetCacheSize(PRInt32 aCacheSize)
{
IL_SetCacheSize(aCacheSize);
}
PRInt32
ImageManagerImpl::GetCacheSize()
{
return IL_GetCacheSize();
}
PRInt32
ImageManagerImpl::ShrinkCache(void)
{
return IL_ShrinkCache();
}
NS_IMETHODIMP
ImageManagerImpl::FlushCache(PRUint8 img_catagory)
{
IL_FlushCache(img_catagory);
return NS_OK;
}
NS_IMETHODIMP
ImageManagerImpl::Observe(nsISupports* aSubject,
const PRUnichar* aTopic,
const PRUnichar* aSomeData)
{
if (nsCRT::strcmp(aTopic, NS_MEMORY_PRESSURE_TOPIC) == 0)
IL_FlushCache(1); // flush everything
return NS_OK;
}
extern "C" NS_GFX_(nsresult)
NS_NewImageManager(nsIImageManager **aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsresult rv;
if (nsnull == gImageManager) {
gImageManager = new ImageManagerImpl();
if (! gImageManager)
return NS_ERROR_OUT_OF_MEMORY;
rv = CallQueryInterface(NS_STATIC_CAST(nsIImageManager*, gImageManager), aInstancePtrResult);
gImageManager->Init();
}
else {
rv = CallQueryInterface(NS_STATIC_CAST(nsIImageManager*, gImageManager), aInstancePtrResult);
}
return rv;
}
/* This is going to be obsolete, once ImageManagerImpl becomes a service on all platforms */
extern "C" NS_GFX_(void)
NS_FreeImageManager()
{
/*Do not release it on platforms on which ImageManagerImpl is a service.
Need to remove this method, once ImageManagerImpl is converted to a service on all platforms.*/
NS_IF_RELEASE(gImageManager);
}

View File

@ -1,49 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "ilINetContext.h"
#include "ilIURL.h"
#include "ilIImageRenderer.h"
#include "ilISystemServices.h"
#include "nscore.h"
class nsIStreamListener;
class nsILoadGroup;
typedef PRBool (*nsReconnectCB)(void* arg, nsIStreamListener* aListener);
extern "C" NS_GFX_(nsresult)
NS_NewImageNetContext(ilINetContext **aInstancePtrResult,
nsISupports* aLoadContext,
nsReconnectCB aReconnectCallback,
void* aReconnectArg);
extern "C" NS_GFX_(nsresult)
NS_NewImageURL(ilIURL **aInstancePtrResult,
const char *aURL , nsILoadGroup* aLoadGroup);
extern "C" NS_GFX_(nsresult) NS_NewImageRenderer(ilIImageRenderer **aInstancePtrResult);
extern "C" NS_GFX_(nsresult) NS_NewImageSystemServices(ilISystemServices **aInstancePtrResult);
// Internal net context used for synchronously loading icons
nsresult NS_NewImageNetContextSync(ilINetContext** aInstancePtrResult);

View File

@ -1,904 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "libimg.h"
#include "nsImageNet.h"
#include "ilINetContext.h"
#include "ilIURL.h"
#include "ilINetReader.h"
#include "ilErrors.h"
#include "nsIStreamListener.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "nsILoadGroup.h"
#include "nsIChannel.h"
#include "nsCOMPtr.h"
#include "nsWeakPtr.h"
#include "prprf.h"
#include "nsITimer.h"
#include "nsVoidArray.h"
#include "nsString.h"
#include "prmem.h"
#include "plstr.h"
#include "nsNetUtil.h"
#include "nsCURILoader.h"
#include "nsIURIContentListener.h"
#include "nsIHttpChannel.h"
#include "nsIStreamConverterService.h"
#include "nsIPref.h"
#include "nsMimeTypes.h"
static NS_DEFINE_CID(kStreamConvServiceCID, NS_STREAMCONVERTERSERVICE_CID);
static NS_DEFINE_IID(kIURLIID, NS_IURL_IID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
PRLogModuleInfo *image_net_context_async_log_module = NULL;
#define IMAGE_BUF_SIZE 4096
class ImageConsumer;
class ImageNetContextImpl : public ilINetContext {
public:
ImageNetContextImpl(ImgCachePolicy aReloadPolicy,
nsISupports * aLoadContext,
nsReconnectCB aReconnectCallback,
void* aReconnectArg);
virtual ~ImageNetContextImpl();
NS_DECL_ISUPPORTS
virtual ilINetContext* Clone();
virtual ImgCachePolicy GetReloadPolicy();
virtual ImgCachePolicy SetReloadPolicy(ImgCachePolicy ReloadPolicy);
virtual void AddReferer(ilIURL *aUrl);
virtual void Interrupt();
virtual ilIURL* CreateURL(const char *aUrl,
ImgCachePolicy aReloadMethod);
virtual PRBool IsLocalFileURL(char *aAddress);
#ifdef NU_CACHE
virtual PRBool IsURLInCache(ilIURL *aUrl);
#else /* NU_CACHE */
virtual PRBool IsURLInMemCache(ilIURL *aUrl);
virtual PRBool IsURLInDiskCache(ilIURL *aUrl);
#endif
virtual int GetURL (ilIURL * aUrl, ImgCachePolicy aLoadMethod,
ilINetReader *aReader, PRBool IsAnimationLoop);
virtual int GetContentLength(ilIURL * aURL);
nsresult RemoveRequest(ImageConsumer *aConsumer);
nsresult RequestDone(ImageConsumer *aConsumer, nsIRequest* request,
nsISupports* ctxt, nsresult status, const PRUnichar* aMsg);
nsVoidArray *mRequests; // WEAK references to |ImageConsumer|s
ImgCachePolicy mReloadPolicy;
nsWeakPtr mLoadContext;
nsReconnectCB mReconnectCallback;
void* mReconnectArg;
};
class ImageConsumer : public nsIStreamListener, public nsIURIContentListener, public nsIInterfaceRequestor
{
public:
NS_DECL_ISUPPORTS
ImageConsumer(ilIURL *aURL, ImageNetContextImpl *aContext);
// nsIRequestObserver methods:
NS_DECL_NSIREQUESTOBSERVER
NS_DECL_NSISTREAMLISTENER
NS_DECL_NSIURICONTENTLISTENER
NS_DECL_NSIINTERFACEREQUESTOR
void SetKeepPumpingData(nsIRequest* request, nsISupports* context) {
NS_ADDREF(request);
NS_IF_RELEASE(mRequest);
mRequest = request;
NS_IF_ADDREF(context);
NS_IF_RELEASE(mUserContext);
mUserContext = context;
}
void Interrupt();
static void KeepPumpingStream(nsITimer *aTimer, void *aClosure);
protected:
virtual ~ImageConsumer();
ilIURL *mURL;
PRBool mInterrupted;
ImageNetContextImpl *mContext;
nsIInputStream *mStream;
nsCOMPtr<nsITimer> mTimer;
PRBool mFirstRead;
char *mBuffer;
PRInt32 mStatus;
nsIRequest* mRequest;
nsISupports* mUserContext;
PRBool mIsMulti;
};
ImageConsumer::ImageConsumer(ilIURL *aURL, ImageNetContextImpl *aContext)
{
NS_INIT_REFCNT();
mURL = aURL;
NS_ADDREF(mURL);
mContext = aContext;
NS_ADDREF(mContext);
mInterrupted = PR_FALSE;
mFirstRead = PR_TRUE;
mStream = nsnull;
mBuffer = nsnull;
mStatus = 0;
mRequest = nsnull;
mUserContext = nsnull;
mIsMulti = PR_FALSE;
}
NS_IMPL_THREADSAFE_ADDREF(ImageConsumer)
NS_IMPL_THREADSAFE_RELEASE(ImageConsumer)
NS_INTERFACE_MAP_BEGIN(ImageConsumer)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIContentListener)
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
NS_INTERFACE_MAP_ENTRY(nsIRequestObserver)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
NS_INTERFACE_MAP_END
NS_IMETHODIMP ImageConsumer::GetInterface(const nsIID & aIID, void * *aInstancePtr)
{
NS_ENSURE_ARG_POINTER(aInstancePtr);
return QueryInterface(aIID, aInstancePtr);
}
// nsIURIContentListener support
NS_IMETHODIMP
ImageConsumer::OnStartURIOpen(nsIURI* aURI, PRBool* aAbortOpen)
{
return NS_OK;
}
NS_IMETHODIMP
ImageConsumer::GetProtocolHandler(nsIURI *aURI, nsIProtocolHandler **aProtocolHandler)
{
*aProtocolHandler = nsnull;
return NS_OK;
}
NS_IMETHODIMP
ImageConsumer::GetParentContentListener(nsIURIContentListener** aParent)
{
*aParent = nsnull;
return NS_OK;
}
NS_IMETHODIMP
ImageConsumer::SetParentContentListener(nsIURIContentListener* aParent)
{
return NS_OK;
}
NS_IMETHODIMP
ImageConsumer::GetLoadCookie(nsISupports ** aLoadCookie)
{
nsCOMPtr<nsISupports> loadContext = do_QueryReferent(mContext->mLoadContext);
*aLoadCookie = loadContext;
NS_IF_ADDREF(*aLoadCookie);
return NS_OK;
}
NS_IMETHODIMP
ImageConsumer::SetLoadCookie(nsISupports * aLoadCookie)
{
return NS_OK;
}
NS_IMETHODIMP
ImageConsumer::IsPreferred(const char * aContentType,
nsURILoadCommand aCommand,
char ** aDesiredContentType,
PRBool * aCanHandleContent)
{
return CanHandleContent(aContentType, aCommand,
aDesiredContentType, aCanHandleContent);
}
NS_IMETHODIMP
ImageConsumer::CanHandleContent(const char * aContentType,
nsURILoadCommand aCommand,
char ** aDesiredContentType,
PRBool * aCanHandleContent)
{
// if we had a webshell or doc shell around, we'd pass this call
// through to it...but we don't =(
if (!nsCRT::strcasecmp(aContentType, "message/rfc822"))
*aDesiredContentType = nsCRT::strdup("application/vnd.mozilla.xul+xml");
// since we explicilty loaded the url, we always want to handle it!
*aCanHandleContent = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
ImageConsumer::DoContent(const char * aContentType,
nsURILoadCommand aCommand,
nsIRequest * aOpenedChannel,
nsIStreamListener ** aContentHandler,
PRBool * aAbortProcess)
{
nsresult rv = NS_OK;
if (aAbortProcess)
*aAbortProcess = PR_FALSE;
nsAutoString contentType; contentType.AssignWithConversion(aContentType);
if (contentType.EqualsWithConversion(MULTIPART_MIXED_REPLACE)
|| contentType.EqualsWithConversion(MULTIPART_MIXED)) {
// if we're getting multipart data, we have to convert it.
// so wedge the converter inbetween us and the consumer.
mIsMulti= PR_TRUE;
nsCOMPtr<nsIStreamConverterService> convServ = do_GetService(kStreamConvServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
nsAutoString astrix; astrix.AssignWithConversion("*/*");
return convServ->AsyncConvertData(contentType.get(),
astrix.get(),
NS_STATIC_CAST(nsIStreamListener*, this),
nsnull /*a context?*/, aContentHandler);
}
QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aContentHandler);
return rv;
}
NS_IMETHODIMP
ImageConsumer::OnStartRequest(nsIRequest* aRequest, nsISupports* aContext)
{
nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
PRUint32 httpStatus;
if (mInterrupted) {
mStatus = MK_INTERRUPTED;
return NS_ERROR_ABORT;
}
mBuffer = (char *)PR_MALLOC(IMAGE_BUF_SIZE);
if (mBuffer == nsnull) {
mStatus = MK_IMAGE_LOSSAGE;
return NS_ERROR_ABORT;
}
nsCOMPtr<nsIHttpChannel> pHTTPCon(do_QueryInterface(channel));
if (pHTTPCon) {
pHTTPCon->GetResponseStatus(&httpStatus);
if (httpStatus == 404) {
mStatus = MK_IMAGE_LOSSAGE;
return NS_ERROR_ABORT;
}
}
ilINetReader *reader = mURL->GetReader(); //ptn test: nsCOMPtr??
/*nsresult err=*/ reader->FlushImgBuffer(); //flush current data in buffer before starting
nsresult rv = NS_OK;
char* aContentType = NULL;
rv = channel->GetContentType(&aContentType); //nsCRT alloc's str
if (NS_FAILED(rv)) {
if(aContentType){
nsCRT::free(aContentType);
}
aContentType = nsCRT::strdup("unknown");
}
if(nsCRT::strlen(aContentType) > 50){
//somethings wrong. mimetype string shouldn't be this big.
//protect us from the user.
nsCRT::free(aContentType);
aContentType = nsCRT::strdup("unknown");
}
if (reader->StreamCreated(mURL, aContentType) != PR_TRUE) {
mStatus = MK_IMAGE_LOSSAGE;
reader->StreamAbort(mStatus);
NS_RELEASE(reader);
nsCRT::free(aContentType);
return NS_ERROR_ABORT;
}
nsCRT::free(aContentType);
NS_RELEASE(reader);
return NS_OK;
}
#define IMAGE_BUF_SIZE 4096
NS_IMETHODIMP
ImageConsumer::OnDataAvailable(nsIRequest* request, nsISupports* aContext,
nsIInputStream *pIStream, PRUint32 offset, PRUint32 length)
{
PRUint32 max_read=0;
PRUint32 bytes_read = 0;
ilINetReader *reader = mURL->GetReader();
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
if (mInterrupted || mStatus != 0) {
mStatus = MK_INTERRUPTED;
reader->StreamAbort(mStatus);
NS_RELEASE(reader);
return NS_ERROR_ABORT;
}
nsresult err = 0;
PRUint32 nb = 0;
char* uriStr = NULL;
nsCOMPtr<nsIURI> uri;
err = channel->GetURI(getter_AddRefs(uri));
if (NS_SUCCEEDED(err) && uri) {
err = uri->GetSpec(&uriStr);
if (NS_FAILED(err)){
/* if we can't get a file spec, it is bad, very bad.*/
mStatus = MK_INTERRUPTED;
reader->StreamAbort(mStatus);
NS_RELEASE(reader);
return NS_ERROR_ABORT;
}
}
do {
err = reader->WriteReady(&max_read); //max read is most decoder can handle
if(NS_FAILED(err)) //note length tells how much we already have.
break;
if(max_read < 0){
max_read = 128;
}
if (max_read > (length - bytes_read)) {
max_read = length - bytes_read;
}
if (max_read > IMAGE_BUF_SIZE) {
max_read = IMAGE_BUF_SIZE;
}
// make sure there's enough data available to decode the image.
// put test into WriteReady
if (mFirstRead && length < 4)
break;
err = pIStream->Read(mBuffer,
max_read, &nb);
if (err == NS_BASE_STREAM_WOULD_BLOCK) {
NS_ASSERTION(nb == 0, "Data will be lost.");
err = NS_OK;
break;
}
if (NS_FAILED(err) || nb == 0) {
NS_ASSERTION(nb == 0, "Data will be lost.");
break;
}
bytes_read += nb;
if (mFirstRead == PR_TRUE) {
err = reader->FirstWrite((const unsigned char *)mBuffer, nb, uriStr);
mFirstRead = PR_FALSE; //? move after err chk?
/*
* If FirstWrite(...) fails then the image type
* cannot be determined and the il_container
* stream functions have not been initialized!
*/
if (NS_FAILED(err)) {
mStatus = MK_IMAGE_LOSSAGE;
mInterrupted = PR_TRUE;
if(uriStr)
nsCRT::free(uriStr);
NS_RELEASE(reader);
return NS_ERROR_ABORT;
}
}
err = reader->Write((const unsigned char *)mBuffer, (int32)nb);
if(NS_FAILED(err)){
mStatus = MK_IMAGE_LOSSAGE;
mInterrupted = PR_TRUE;
if(uriStr)
nsCRT::free(uriStr);
NS_RELEASE(reader);
return NS_ERROR_ABORT;
}
} while(bytes_read < length);
if (uriStr) {
nsCRT::free(uriStr);
}
if (NS_FAILED(err)) {
mStatus = MK_IMAGE_LOSSAGE;
mInterrupted = PR_TRUE;
}
if (bytes_read < length) {
// If we haven't emptied the stream, hold onto it, because
// we will need to read from it subsequently and we don't
// know if we'll get a OnDataAvailable call again.
//
// Addref the new stream before releasing the old one,
// in case it is the same stream!
NS_ADDREF(pIStream);
NS_IF_RELEASE(mStream);
mStream = pIStream;
} else {
NS_IF_RELEASE(mStream);
}
NS_RELEASE(reader);
return NS_OK;
}
void
ImageConsumer::KeepPumpingStream(nsITimer *aTimer, void *aClosure)
{
ImageConsumer *consumer = (ImageConsumer *)aClosure;
consumer->OnStopRequest(consumer->mRequest, consumer->mUserContext,
NS_BINDING_SUCCEEDED);
}
NS_IMETHODIMP
ImageConsumer::OnStopRequest(nsIRequest* request, nsISupports* aContext, nsresult status)
{
if (mTimer) {
mTimer->Cancel();
mTimer = nsnull;
}
if (NS_BINDING_SUCCEEDED != status) {
mStatus = MK_INTERRUPTED;
}
// Since we're still holding on to the stream, there's still data
// that needs to be read. So, pump the stream ourselves.
if((mStream != nsnull) && (status == NS_BINDING_SUCCEEDED)) {
PRUint32 str_length;
nsresult err = mStream->Available(&str_length);
if (NS_SUCCEEDED(err)) {
NS_ASSERTION((str_length > 0), "No data left in the stream!");
err = OnDataAvailable(request, aContext, mStream, 0, str_length); // XXX fix offset
if (NS_SUCCEEDED(err)) {
// If we still have the stream, there's still data to be
// pumped, so we set a timer to call us back again.
if (mStream) {
SetKeepPumpingData(request, aContext);
nsresult rv;
mTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
if (NS_FAILED(rv) ||
(NS_OK != mTimer->Init(ImageConsumer::KeepPumpingStream, this, 0))) {
mStatus = MK_IMAGE_LOSSAGE;
NS_RELEASE(mStream);
}
else {
return NS_OK;
}
}
}
else {
mStatus = MK_IMAGE_LOSSAGE;
NS_IF_RELEASE(mStream);
}
}
else {
mStatus = MK_IMAGE_LOSSAGE;
NS_IF_RELEASE(mStream);
}
}
ilINetReader *reader = mURL->GetReader();
if (0 != mStatus) {
reader->StreamAbort(mStatus);
}
else {
reader->StreamComplete(mIsMulti);
}
if(mIsMulti)
mFirstRead = PR_TRUE; //reset to read new frame
reader->NetRequestDone(mURL, mStatus);
NS_RELEASE(reader);
return mContext->RequestDone(this, request, aContext, status, nsnull);
}
void
ImageConsumer::Interrupt()
{
mInterrupted = PR_TRUE;
}
ImageConsumer::~ImageConsumer()
{
if (mTimer) {
mTimer->Cancel();
mTimer = nsnull;
}
if (mContext) {
nsresult res = mContext->RemoveRequest(this);
if (NS_SUCCEEDED(res)) {
// The load was canceled.
mStatus = MK_INTERRUPTED;
if (mURL) {
nsCOMPtr<ilINetReader> reader( dont_AddRef( mURL->GetReader() ) );
reader->StreamAbort(mStatus);
reader->NetRequestDone(mURL, mStatus);
}
}
NS_RELEASE(mContext);
}
NS_IF_RELEASE(mURL);
NS_IF_RELEASE(mStream);
if (mBuffer != nsnull) {
PR_DELETE(mBuffer);
}
NS_IF_RELEASE(mRequest);
NS_IF_RELEASE(mUserContext);
}
ImageNetContextImpl::ImageNetContextImpl(ImgCachePolicy aReloadPolicy,
nsISupports * aLoadContext,
nsReconnectCB aReconnectCallback,
void* aReconnectArg)
{
NS_INIT_REFCNT();
mRequests = nsnull;
mLoadContext = getter_AddRefs(NS_GetWeakReference(aLoadContext));
mReloadPolicy = aReloadPolicy;
mReconnectCallback = aReconnectCallback;
mReconnectArg = aReconnectArg;
}
ImageNetContextImpl::~ImageNetContextImpl()
{
delete mRequests;
}
NS_IMPL_THREADSAFE_ISUPPORTS1(ImageNetContextImpl, ilINetContext)
ilINetContext*
ImageNetContextImpl::Clone()
{
ilINetContext *cx;
nsCOMPtr<nsISupports> loadContext = do_QueryReferent(mLoadContext);
//mReconnectArg is ImageGroup. If GetURL is triggered
//by timer for animation, ImageGroup may have been unloaded
//before timer kicks off.
//mReconnectCallback=nsnull; mReconnectArg=nsnull;
if (NS_NewImageNetContext(&cx, loadContext, mReconnectCallback, mReconnectArg) == NS_OK)
{
return cx;
}
else {
return nsnull;
}
}
ImgCachePolicy
ImageNetContextImpl::GetReloadPolicy()
{
return mReloadPolicy;
}
ImgCachePolicy
ImageNetContextImpl::SetReloadPolicy(ImgCachePolicy reloadpolicy)
{
mReloadPolicy=reloadpolicy;
return mReloadPolicy;
}
void
ImageNetContextImpl::AddReferer(ilIURL *aUrl)
{
}
void
ImageNetContextImpl::Interrupt()
{
if (mRequests != nsnull) {
int i, count = mRequests->Count();
for (i=0; i < count; i++) {
ImageConsumer *ic = (ImageConsumer *)mRequests->ElementAt(i);
ic->Interrupt();
}
}
}
ilIURL*
ImageNetContextImpl::CreateURL(const char *aURL,
ImgCachePolicy aReloadMethod)
{
ilIURL *url;
nsCOMPtr<nsISupports> loadContext (do_QueryReferent(mLoadContext));
nsCOMPtr<nsILoadGroup> group (do_GetInterface(loadContext));
if (NS_NewImageURL(&url, aURL, group) == NS_OK)
{
return url;
}
else {
return nsnull;
}
}
PRBool
ImageNetContextImpl::IsLocalFileURL(char *aAddress)
{
if (PL_strncasecmp(aAddress, "file:", 5) == 0) {
return PR_TRUE;
}
else {
return PR_FALSE;
}
}
#ifdef NU_CACHE
PRBool
ImageNetContextImpl::IsURLInCache(ilIURL *aUrl)
{
return PR_TRUE;
}
#else /* NU_CACHE */
PRBool
ImageNetContextImpl::IsURLInMemCache(ilIURL *aUrl)
{
return PR_FALSE;
}
PRBool
ImageNetContextImpl::IsURLInDiskCache(ilIURL *aUrl)
{
return PR_TRUE;
}
#endif /* NU_CACHE */
int
ImageNetContextImpl::GetContentLength (ilIURL * aURL)
{
return -1;
}
int
ImageNetContextImpl::GetURL (ilIURL * aURL,
ImgCachePolicy aLoadMethod,
ilINetReader *aReader,
PRBool IsAnimationLoop)
{
NS_PRECONDITION(nsnull != aURL, "null URL");
NS_PRECONDITION(nsnull != aReader, "null reader");
if (aURL == nsnull || aReader == nsnull) {
return -1;
}
if (mRequests == nsnull) {
mRequests = new nsVoidArray();
if (mRequests == nsnull) {
// XXX Should still call exit function
return -1;
}
}
int ret;
nsresult rv;
nsCOMPtr<nsIURI> nsurl = do_QueryInterface(aURL, &rv);
if (NS_FAILED(rv)) return 0;
aURL->SetReader(aReader);
SetReloadPolicy(aLoadMethod);
// Find previously created ImageConsumer if possible
ImageConsumer *ic = new ImageConsumer(aURL, this);
if (ic == nsnull)
return -1;
NS_ADDREF(ic);
// See if a reconnect is being done...(XXX: hack!)
if (mReconnectCallback == nsnull
|| !(*mReconnectCallback)(mReconnectArg, ic)) {
// first, create a channel for the protocol....
nsCOMPtr<nsIChannel> channel;
nsCOMPtr<nsISupports> loadContext (do_QueryReferent(mLoadContext));
nsCOMPtr<nsILoadGroup> group (do_GetInterface(loadContext));
nsCOMPtr<nsIInterfaceRequestor> sink(do_QueryInterface(loadContext));
nsLoadFlags flags=0;
if(IsAnimationLoop)
flags |= nsIRequest::LOAD_FROM_CACHE;
rv = NS_OpenURI(getter_AddRefs(channel), nsurl, nsnull, group, sink, flags);
if (NS_FAILED(rv)) goto error;
nsCOMPtr<nsIHttpChannel> httpChannel = do_QueryInterface(channel);
if (httpChannel)
{
// Get the defloadRequest from the loadgroup-
nsCOMPtr<nsIRequest> defLoadRequest;
if (NS_SUCCEEDED(group->GetDefaultLoadRequest(
getter_AddRefs(defLoadRequest))) && defLoadRequest)
{
nsCOMPtr<nsIChannel> reqchannel = do_QueryInterface(defLoadRequest);
// Get the referrer from the loadchannel-
nsCOMPtr<nsIURI> referrer;
if (NS_SUCCEEDED(reqchannel->GetURI(getter_AddRefs(referrer))))
{
// Set the referrer-
httpChannel->SetReferrer(referrer, nsIHttpChannel::REFERRER_INLINES);
}
}
}
rv = channel->GetLoadFlags(&flags);
if (NS_FAILED(rv)) goto error;
if (aURL->GetBackgroundLoad())
flags |= nsIRequest::LOAD_BACKGROUND;
(void)channel->SetLoadFlags(flags);
nsCOMPtr<nsISupports> window (do_QueryInterface(NS_STATIC_CAST(nsIStreamListener *, ic)));
// let's try uri dispatching...
nsCOMPtr<nsIURILoader> pURILoader (do_GetService(NS_URI_LOADER_CONTRACTID, &rv));
if (NS_SUCCEEDED(rv))
{
nsURILoadCommand loadCmd = nsIURILoader::viewNormal;
PRBool bIsBackground = aURL->GetBackgroundLoad();
if (bIsBackground) {
loadCmd = nsIURILoader::viewNormalBackground;
}
rv = pURILoader->OpenURI(channel, loadCmd, window);
}
// rv = channel->AsyncOpen(ic, nsnull);
if (NS_FAILED(rv)) goto error;
}
ret = mRequests->AppendElement((void *)ic) ? 0 : -1;
NS_RELEASE(ic); // if nothing else is holding onto it, it will remove
// itself from mRequests
return ret;
error:
NS_RELEASE(ic);
return -1;
}
nsresult
ImageNetContextImpl::RemoveRequest(ImageConsumer *aConsumer)
{
nsresult rv = NS_OK;
if (mRequests) {
rv = mRequests->RemoveElement((void *)aConsumer)?NS_OK:NS_ERROR_FAILURE;
}
return rv;
}
nsresult
ImageNetContextImpl::RequestDone(ImageConsumer *aConsumer, nsIRequest* request,
nsISupports* ctxt, nsresult status, const PRUnichar* aMsg)
{
RemoveRequest(aConsumer);
/// if (mLoadGroup)
/// return mLoadGroup->RemoveChannel(channel, ctxt, status, aMsg);
/// else
return NS_OK;
}
extern "C" NS_GFX_(nsresult)
NS_NewImageNetContext(ilINetContext **aInstancePtrResult,
nsISupports * aLoadContext,
nsReconnectCB aReconnectCallback,
void* aReconnectArg)
{
PRUint32 necko_attribs;
ImgCachePolicy imglib_attribs = USE_IMG_CACHE;
nsLoadFlags defchan_attribs = nsIRequest::LOAD_NORMAL;
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if(aLoadContext){
nsCOMPtr<nsILoadGroup> group (do_GetInterface(aLoadContext));
/*nsresult rv = */group->GetLoadFlags(&necko_attribs);
/*
Need code to check freshness of necko cache.
*/
nsCOMPtr<nsIRequest> defLoadRequest;
nsCOMPtr<nsIChannel> channel;
if (NS_SUCCEEDED(group->GetDefaultLoadRequest(
getter_AddRefs(defLoadRequest))) && defLoadRequest)
{
channel = do_QueryInterface(defLoadRequest);
if (channel) channel->GetLoadFlags(&defchan_attribs);
}
#if defined( DEBUG )
if (image_net_context_async_log_module == NULL) {
image_net_context_async_log_module = PR_NewLogModule("IMAGENETCTXASYNC");
}
#endif
if((nsIRequest::VALIDATE_ALWAYS & defchan_attribs)||
(nsIRequest::INHIBIT_PERSISTENT_CACHING & defchan_attribs)||
(nsIRequest::LOAD_BYPASS_CACHE & defchan_attribs)) {
imglib_attribs = DONT_USE_IMG_CACHE;
#if defined( DEBUG )
PR_LOG(image_net_context_async_log_module, 1, ("ImageNetContextAsync: NS_NewImageNetContext: DONT_USE_IMAGE_CACHE\n"));
#endif
}
}
ilINetContext *cx = new ImageNetContextImpl( imglib_attribs,
aLoadContext,
aReconnectCallback,
aReconnectArg);
if (cx == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return cx->QueryInterface(NS_GET_IID(ilINetContext), (void **) aInstancePtrResult);
}

View File

@ -1,319 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "libimg.h"
#include "nsImageNet.h"
#include "ilINetContext.h"
#include "ilIURL.h"
#include "ilINetReader.h"
#include "nsIInputStream.h"
#include "nsIURL.h"
#include "prmem.h"
#include "plstr.h"
//#include "il_strm.h"
#include "nsIIOService.h"
#include "nsIURL.h"
#include "nsIChannel.h"
#include "nsCRT.h"
#include "nsIServiceManager.h"
#include "nsNetCID.h"
static NS_DEFINE_IID(kIURLIID, NS_IURL_IID);
static NS_DEFINE_IID(kIIOServiceIID, NS_IIOSERVICE_IID);
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
class ImageNetContextSyncImpl : public ilINetContext {
public:
ImageNetContextSyncImpl(ImgCachePolicy aReloadPolicy);
virtual ~ImageNetContextSyncImpl();
NS_DECL_ISUPPORTS
virtual ilINetContext* Clone();
virtual ImgCachePolicy GetReloadPolicy();
virtual void AddReferer(ilIURL* aUrl);
virtual void Interrupt();
virtual ilIURL* CreateURL(const char* aUrl,
ImgCachePolicy aReloadMethod);
virtual PRBool IsLocalFileURL(char* aAddress);
#ifdef NU_CACHE
virtual PRBool IsURLInCache(ilIURL* aUrl);
#else /* NU_CACHE */
virtual PRBool IsURLInMemCache(ilIURL* aUrl);
virtual PRBool IsURLInDiskCache(ilIURL* aUrl);
#endif /* NU_CACHE */
virtual int GetURL(ilIURL* aUrl,ImgCachePolicy aLoadMethod,
ilINetReader* aReader, PRBool IsAnimationLoop);
virtual int GetContentLength (ilIURL * aURL);
ImgCachePolicy mReloadPolicy;
};
ImageNetContextSyncImpl::ImageNetContextSyncImpl(ImgCachePolicy aReloadPolicy)
{
NS_INIT_REFCNT();
mReloadPolicy = aReloadPolicy;
}
ImageNetContextSyncImpl::~ImageNetContextSyncImpl()
{
}
NS_IMPL_ISUPPORTS1(ImageNetContextSyncImpl, ilINetContext)
ilINetContext*
ImageNetContextSyncImpl::Clone()
{
ilINetContext *cx;
if (NS_NewImageNetContextSync(&cx) == NS_OK) {
return cx;
}
return nsnull;
}
ImgCachePolicy
ImageNetContextSyncImpl::GetReloadPolicy()
{
return mReloadPolicy;
}
void
ImageNetContextSyncImpl::AddReferer(ilIURL *aUrl)
{
}
void
ImageNetContextSyncImpl::Interrupt()
{
}
ilIURL*
ImageNetContextSyncImpl::CreateURL(const char* aURL,
ImgCachePolicy aReloadMethod)
{
ilIURL *url;
if (NS_NewImageURL(&url, aURL, nsnull) == NS_OK)
{
return url;
}
return nsnull;
}
PRBool
ImageNetContextSyncImpl::IsLocalFileURL(char *aAddress)
{
if (PL_strncasecmp(aAddress, "file:", 5) == 0) {
return PR_TRUE;
} else {
return PR_FALSE;
}
}
#ifdef NU_CACHE
PRBool
ImageNetContextSyncImpl::IsURLInCache(ilIURL *aUrl)
{
return PR_TRUE;
}
#else /* NU_CACHE */
PRBool
ImageNetContextSyncImpl::IsURLInMemCache(ilIURL *aUrl)
{
return PR_FALSE;
}
PRBool
ImageNetContextSyncImpl::IsURLInDiskCache(ilIURL *aUrl)
{
return PR_FALSE;
}
#endif /* NU_CACHE */
int
ImageNetContextSyncImpl::GetContentLength (ilIURL * aURL)
{
return 0;
}
int
ImageNetContextSyncImpl::GetURL(ilIURL* aURL,
ImgCachePolicy aLoadMethod,
ilINetReader* aReader,
PRBool IsAnimationLoop)
{
NS_PRECONDITION(nsnull != aURL, "null URL");
NS_PRECONDITION(nsnull != aReader, "null reader");
if (aURL == nsnull || aReader == nsnull) {
return -1;
}
aURL->SetReader(aReader);
PRInt32 status = 0;
// Get a nsIURI interface
nsIURI* url = nsnull;
aURL->QueryInterface(kIURLIID, (void **)&url);
nsresult res;
// Get a network service interface which we'll use to create a stream
nsCOMPtr<nsIIOService> service(do_GetService(kIOServiceCID, &res));
if (NS_SUCCEEDED(res)) {
nsIInputStream* stream = nsnull;
nsIURI *uri = nsnull;
nsresult rv;
rv = url->QueryInterface(NS_GET_IID(nsIURI), (void**)&uri);
if (NS_FAILED(rv)) return -1;
nsIChannel *channel = nsnull;
rv = service->NewChannelFromURI(uri, &channel);
NS_RELEASE(uri);
if (NS_FAILED(rv))
return -1;
char* aContentType = NULL;
rv = channel->GetContentType(&aContentType); //nsCRT alloc's str
if (NS_FAILED(rv)) {
if(aContentType){
nsCRT::free(aContentType);
}
}
if (!aContentType) {
aContentType = nsCRT::strdup("unknown");
}
if(nsCRT::strlen(aContentType) > 50){
//somethings wrong. mimetype string shouldn't be this big.
//protect us from the user.
nsCRT::free(aContentType);
aContentType = nsCRT::strdup("unknown");
}
rv = channel->Open( &stream);
NS_RELEASE(channel);
if (NS_SUCCEEDED(rv)) {
if (aReader->StreamCreated(aURL, aContentType) == PR_TRUE) {
// Read the URL data
char buf[2048];
PRUint32 count;
nsresult result;
PRBool first = PR_TRUE;
char* uriStr = NULL;
uriStr = aURL->GetAddress();
result = stream->Read(buf, sizeof(buf), &count);
while (NS_SUCCEEDED(result) && (count > 0)) {
if (first == PR_TRUE) {
PRInt32 ilErr;
ilErr = aReader->FirstWrite((const unsigned char *)buf, (int32)count, uriStr);
first = PR_FALSE;
// If FirstWrite fails then the image type cannot be determined
if (ilErr != 0) {
result = NS_ERROR_ABORT;
break;
}
}
aReader->Write((const unsigned char *)buf, (int32)count);
// Get the next block
result = stream->Read(buf, sizeof(buf), &count);
}
nsCRT::free(uriStr);
if (NS_FAILED(result)) {
aReader->StreamAbort(-1);
status = -1;
} else {
NS_ASSERTION(0 == count, "expected EOF");
aReader->StreamComplete(PR_FALSE);
}
} else {
aReader->StreamAbort(-1);
status = -1;
}
NS_IF_RELEASE(stream);
} else {
aReader->StreamAbort(-1);
status = -1;
}
nsCRT::free(aContentType);
} else {
aReader->StreamAbort(-1);
status = -1;
}
aReader->NetRequestDone(aURL, status);
NS_IF_RELEASE(url);
return 0;
}
nsresult NS_NewImageNetContextSync(ilINetContext **aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
//Note default of USE_IMG_CACHE used.
ilINetContext *cx = new ImageNetContextSyncImpl(USE_IMG_CACHE);
if (cx == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return cx->QueryInterface(NS_GET_IID(ilINetContext), (void **) aInstancePtrResult);
}

View File

@ -1,355 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "libimg.h"
#include "ilIImageRenderer.h"
#include "nsIImage.h"
#include "nsIRenderingContext.h"
#include "ni_pixmp.h"
#include "il_util.h"
#include "nsGfxCIID.h"
#include "nsIDeviceContext.h"
static NS_DEFINE_IID(kIImageRendererIID, IL_IIMAGERENDERER_IID);
class ImageRendererImpl : public ilIImageRenderer {
public:
ImageRendererImpl();
NS_DECL_ISUPPORTS
NS_IMETHOD NewPixmap(void* aDisplayContext,
PRInt32 aWidth, PRInt32 aHeight,
IL_Pixmap* aImage, IL_Pixmap* aMask);
NS_IMETHOD UpdatePixmap(void* aDisplayContext,
IL_Pixmap* aImage,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD ControlPixmapBits(void* aDisplayContext,
IL_Pixmap* aImage, PRUint32 aControlMsg);
NS_IMETHOD DestroyPixmap(void* aDisplayContext, IL_Pixmap* aImage);
NS_IMETHOD DisplayPixmap(void* aDisplayContext,
IL_Pixmap* aImage, IL_Pixmap* aMask,
PRInt32 aX, PRInt32 aY,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight);
NS_IMETHOD DisplayIcon(void* aDisplayContext,
PRInt32 aX, PRInt32 aY, PRUint32 aIconNumber);
NS_IMETHOD GetIconDimensions(void* aDisplayContext,
PRInt32 *aWidthPtr, PRInt32 *aHeightPtr,
PRUint32 aIconNumber);
NS_IMETHOD SetImageNaturalDimensions(IL_Pixmap* aImage, PRInt32 naturalwidth, PRInt32 naturalheight);
NS_IMETHOD SetDecodedRect(IL_Pixmap* aImage,
PRInt32 x1, PRInt32 y1,
PRInt32 x2, PRInt32 y2);
};
NS_IMETHODIMP
ImageRendererImpl::SetImageNaturalDimensions(
IL_Pixmap* aImage,
PRInt32 naturalwidth,
PRInt32 naturalheight){
nsIImage *img = (nsIImage *)aImage->client_data;
if(img){
nsresult rv = img->SetNaturalWidth(naturalwidth);
rv = img->SetNaturalHeight(naturalheight);
}
return NS_OK;
}
ImageRendererImpl::ImageRendererImpl()
{
NS_INIT_REFCNT();
}
NS_IMPL_ISUPPORTS1(ImageRendererImpl, ilIImageRenderer)
NS_IMETHODIMP
ImageRendererImpl::NewPixmap(void* aDisplayContext,
PRInt32 aWidth, PRInt32 aHeight,
IL_Pixmap* aImage, IL_Pixmap* aMask)
{
nsIDeviceContext *dc = (nsIDeviceContext *)aDisplayContext;
nsIImage *img;
nsresult rv;
nsMaskRequirements maskflag;
static NS_DEFINE_IID(kImageCID, NS_IMAGE_CID);
static NS_DEFINE_IID(kImageIID, NS_IIMAGE_IID);
if (!aImage)
return NS_ERROR_NULL_POINTER;
// initialize in case of failure
NS_ASSERTION(!aImage->bits, "We have bits already?");
aImage->bits = nsnull;
aImage->haveBits = PR_FALSE;
if (aMask)
{
aMask->haveBits = PR_FALSE;
aMask->bits = nsnull;
}
// Create a new image object
rv = nsComponentManager::CreateInstance(kImageCID, nsnull, kImageIID, (void **)&img);
if (NS_FAILED(rv)) {
return rv;
}
// Have the image match the depth and color space associated with the
// device.
// XXX We probably don't want to do that for monomchrome images (e.g., XBM)
// or one-bit deep GIF images.
PRInt32 depth;
IL_ColorSpace *colorSpace;
rv = dc->GetILColorSpace(colorSpace);
if (NS_FAILED(rv)) {
return rv;
}
depth = colorSpace->pixmap_depth;
// Initialize the image object
if(aMask == nsnull)
maskflag = nsMaskRequirements_kNoMask;
else
maskflag = nsMaskRequirements_kNeeds1Bit;
if(aImage->header.alpha_bits == 8)
maskflag = nsMaskRequirements_kNeeds8Bit;
rv = img->Init(aWidth, aHeight, depth, maskflag);
if (NS_FAILED(rv)) {
return rv;
}
// Update the pixmap image and mask information
// Don't get the bits here, because we can't guarantee that this address
// will still be valid when we start using it. We *must* wait until we're
// inside a lock/unlocks pixels block before getting the bits address
// aImage->bits = img->GetBits();
aImage->haveBits = PR_TRUE;
aImage->client_data = img; // we don't need to add a ref here, because there's
// already one from the call to create the image object
aImage->header.width = aWidth;
aImage->header.height = aHeight;
aImage->header.widthBytes = img->GetLineStride();
if (aMask) {
// see comment about about getting the bits here
// aMask->bits = img->GetAlphaBits();
aMask->haveBits = PR_TRUE;
aMask->client_data = img;
// We must add another reference here, because when the mask's pixmap is
// destroyed it will release a reference
NS_ADDREF(img);
aMask->header.width = aWidth;
aMask->header.height = aHeight;
aMask->header.widthBytes = img->GetAlphaLineStride();
}
// Replace the existing color space with the color space associated
// with the device.
IL_ReleaseColorSpace(aImage->header.color_space);
aImage->header.color_space = colorSpace;
// XXX Why do we do this on a per-image basis?
if (8 == depth) {
IL_ColorMap *cmap = &colorSpace->cmap;
nsColorMap *nscmap = img->GetColorMap();
PRUint8 *mapptr = nscmap->Index;
int i;
for (i=0; i < cmap->num_colors; i++) {
*mapptr++ = cmap->map[i].red;
*mapptr++ = cmap->map[i].green;
*mapptr++ = cmap->map[i].blue;
}
img->ImageUpdated(dc, nsImageUpdateFlags_kColorMapChanged, nsnull);
if (aImage->header.transparent_pixel) {
PRUint8 red, green, blue;
PRUint8 *lookup_table = (PRUint8 *)aImage->header.color_space->cmap.table;
red = aImage->header.transparent_pixel->red;
green = aImage->header.transparent_pixel->green;
blue = aImage->header.transparent_pixel->blue;
aImage->header.transparent_pixel->index = lookup_table[((red >> 3) << 10) |
((green >> 3) << 5) |
(blue >> 3)];
}
}
return NS_OK;
}
NS_IMETHODIMP
ImageRendererImpl::UpdatePixmap(void* aDisplayContext,
IL_Pixmap* aImage,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight)
{
nsIDeviceContext *dc = (nsIDeviceContext *)aDisplayContext;
nsIImage *img = (nsIImage *)aImage->client_data;
nsRect drect(aXOffset, aYOffset, aWidth, aHeight);
img->ImageUpdated(dc, nsImageUpdateFlags_kBitsChanged, &drect);
return NS_OK;
}
NS_IMETHODIMP
ImageRendererImpl::SetDecodedRect( IL_Pixmap* aImage,
PRInt32 x1, PRInt32 y1,
PRInt32 x2, PRInt32 y2)
{
nsIImage *img;
if(aImage == NULL)
return NS_OK;
img= (nsIImage *)aImage->client_data;
img->SetDecodedRect(x1, y1, x2, y2);
return NS_OK;
}
NS_IMETHODIMP
ImageRendererImpl::ControlPixmapBits(void* aDisplayContext,
IL_Pixmap* aImage, PRUint32 aControlMsg)
{
nsIDeviceContext *dc = (nsIDeviceContext *)aDisplayContext;
if (!aImage)
return NS_ERROR_NULL_POINTER;
nsIImage *img = (nsIImage *)aImage->client_data;
if (!img)
return NS_ERROR_UNEXPECTED;
PRBool isMask = aImage->header.is_mask;
nsresult rv = NS_OK;
switch (aControlMsg)
{
case IL_LOCK_BITS:
rv = img->LockImagePixels(isMask);
if (NS_FAILED(rv))
return rv;
// the pixels may have moved, so need to update the bits ptr
aImage->bits = (isMask) ? img->GetAlphaBits() : img->GetBits();
break;
case IL_UNLOCK_BITS:
rv = img->UnlockImagePixels(isMask);
break;
case IL_RELEASE_BITS:
rv = img->Optimize(dc);
break;
default:
NS_NOTREACHED("Uknown control msg");
}
return rv;
}
NS_IMETHODIMP
ImageRendererImpl::DestroyPixmap(void* aDisplayContext, IL_Pixmap* aImage)
{
nsIImage *img = (nsIImage *)aImage->client_data;
aImage->client_data = nsnull;
if (img) {
NS_RELEASE(img);
}
return NS_OK;
}
NS_IMETHODIMP
ImageRendererImpl::DisplayPixmap(void* aDisplayContext,
IL_Pixmap* aImage, IL_Pixmap* aMask,
PRInt32 aX, PRInt32 aY,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight)
{
// Image library doesn't drive the display process.
// XXX Why is this part of the API?
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ImageRendererImpl::DisplayIcon(void* aDisplayContext,
PRInt32 aX, PRInt32 aY, PRUint32 aIconNumber)
{
// XXX Why is this part of the API?
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
ImageRendererImpl::GetIconDimensions(void* aDisplayContext,
PRInt32 *aWidthPtr, PRInt32 *aHeightPtr,
PRUint32 aIconNumber)
{
// XXX Why is this part of the API?
return NS_ERROR_NOT_IMPLEMENTED;
}
extern "C" NS_GFX_(nsresult)
NS_NewImageRenderer(ilIImageRenderer **aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
ilIImageRenderer *renderer = new ImageRendererImpl();
if (renderer == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return renderer->QueryInterface(NS_GET_IID(ilIImageRenderer), (void **)aInstancePtrResult);
}

View File

@ -1,362 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsImageRequest.h"
#include "nsIImageGroup.h"
#include "nsIImageObserver.h"
#include "nsIImage.h"
#include "nsVoidArray.h"
#include "nsRect.h"
#include "nsImageNet.h"
static NS_DEFINE_IID(kIImageRequestIID, NS_IIMAGEREQUEST_IID);
static void ns_observer_proc (XP_Observable aSource,
XP_ObservableMsg aMsg,
void* aMsgData,
void* aClosure)
{
ImageRequestImpl *image_request = (ImageRequestImpl *)aClosure;
IL_MessageData *message_data = (IL_MessageData *)aMsgData;
nsVoidArray *observer_list = nsnull;
nsIImage *image = nsnull;
// IL_ImageReq *il_image_req = image_request->GetImageRequest();
IL_ImageReq *il_image_req = (IL_ImageReq *)aSource;
if (image_request != nsnull) {
observer_list = image_request->GetObservers();
}
if (il_image_req != nsnull) {
IL_Pixmap *pixmap = IL_GetImagePixmap(il_image_req);
if (pixmap != nsnull) {
image = (nsIImage *)pixmap->client_data;
}
}
if (observer_list != nsnull) {
PRInt32 i, count = observer_list->Count();
nsIImageRequestObserver *observer;
for (i = 0; i < count; i++) {
observer = (nsIImageRequestObserver *)observer_list->ElementAt(i);
if (observer != nsnull) {
switch (aMsg) {
case IL_START_URL:
observer->Notify(image_request,
image, nsImageNotification_kStartURL, 0, 0,
nsnull);
break;
case IL_DESCRIPTION:
observer->Notify(image_request,
image, nsImageNotification_kDescription, 0, 0,
message_data->description);
break;
case IL_DIMENSIONS:
observer->Notify(image_request,
image, nsImageNotification_kDimensions,
(PRInt32)message_data->width,
(PRInt32)message_data->height,
nsnull);
break;
case IL_IS_TRANSPARENT:
observer->Notify(image_request,
image, nsImageNotification_kIsTransparent, 0, 0,
nsnull);
break;
case IL_PIXMAP_UPDATE:
{
nsRect rect(message_data->update_rect.x_origin,
message_data->update_rect.y_origin,
message_data->update_rect.width,
message_data->update_rect.height);
observer->Notify(image_request,
image, nsImageNotification_kPixmapUpdate, 0, 0,
&rect);
}
break;
case IL_FRAME_COMPLETE:
observer->Notify(image_request,
image, nsImageNotification_kFrameComplete, 0, 0,
nsnull);
break;
case IL_PROGRESS:
observer->Notify(image_request,
image, nsImageNotification_kProgress,
message_data->percent_progress, 0,
nsnull);
break;
case IL_IMAGE_COMPLETE:
observer->Notify(image_request,
image, nsImageNotification_kImageComplete, 0, 0,
nsnull);
break;
case IL_STOP_URL:
observer->Notify(image_request,
image, nsImageNotification_kStopURL, 0, 0,
nsnull);
break;
case IL_IMAGE_DESTROYED:
image_request->SetImageRequest(nsnull);
observer->Notify(image_request,
image, nsImageNotification_kImageDestroyed, 0, 0,
nsnull);
break;
case IL_ABORTED:
image_request->SetImageRequest(nsnull);
observer->Notify(image_request,
image, nsImageNotification_kAborted, 0, 0,
nsnull);
break;
case IL_INTERNAL_IMAGE:
observer->Notify(image_request,
image, nsImageNotification_kInternalImage, 0, 0,
nsnull);
break;
case IL_NOT_IN_CACHE:
observer->NotifyError(image_request,
nsImageError_kNotInCache);
break;
case IL_ERROR_NO_DATA:
observer->NotifyError(image_request,
nsImageError_kNoData);
break;
case IL_ERROR_IMAGE_DATA_CORRUPT:
observer->NotifyError(image_request,
nsImageError_kImageDataCorrupt);
break;
case IL_ERROR_IMAGE_DATA_TRUNCATED:
observer->NotifyError(image_request,
nsImageError_kImageDataTruncated);
break;
case IL_ERROR_IMAGE_DATA_ILLEGAL:
observer->NotifyError(image_request,
nsImageError_kImageDataIllegal);
break;
case IL_ERROR_INTERNAL:
observer->NotifyError(image_request,
nsImageError_kInternalError);
break;
}
}
}
}
/*
* If the IL_ImageReq is being destroyed, clear the reference held by
* the nsImageRequestImpl...
*
* This will prevent a dangling reference in cases where the image group
* is destroyed before the image request...
*/
if ((IL_IMAGE_DESTROYED == aMsg) && (nsnull != image_request)) {
image_request->SetImageRequest(nsnull);
image_request->ImageDestroyed();
}
}
ImageRequestImpl::ImageRequestImpl()
{
NS_INIT_REFCNT();
}
ImageRequestImpl::~ImageRequestImpl()
{
if (mXPObserver) {
// Make sure dangling reference to this object goes away
XP_RemoveObserver(mXPObserver, ns_observer_proc, (void*)this);
}
if (mImageReq) {
IL_DestroyImage(mImageReq);
}
// Delete the list of observers, and release the reference to the image
// request observer object
if (nsnull != mObservers) {
for (PRInt32 cnt = 0; cnt < mObservers->Count(); cnt++)
{
nsIImageRequestObserver* observer;
observer = (nsIImageRequestObserver*)mObservers->ElementAt(cnt);
NS_IF_RELEASE(observer);
mObservers->ReplaceElementAt(nsnull, cnt);
}
delete mObservers;
}
// XP Observer list destroyed by the image library
}
nsresult
ImageRequestImpl::Init(IL_GroupContext *aGroupContext,
const char* aUrl,
nsIImageRequestObserver *aObserver,
const nscolor* aBackgroundColor,
PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags,
ilINetContext* aNetContext)
{
NS_PRECONDITION(nsnull != aGroupContext, "null group context");
NS_PRECONDITION(nsnull != aUrl, "null URL");
NS_Error status;
IL_IRGB bgcolor;
PRUint32 flags;
mGroupContext = aGroupContext;
if (nsnull != aObserver) {
if (AddObserver(aObserver) == PR_FALSE) {
return NS_ERROR_OUT_OF_MEMORY;
}
}
status = XP_NewObserverList(NULL, &mXPObserver);
if (status < 0) {
return NS_ERROR_OUT_OF_MEMORY;
}
status = XP_AddObserver(mXPObserver, ns_observer_proc, (void *)this);
if (status < 0) {
XP_DisposeObserverList(mXPObserver);
mXPObserver = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
if (nsnull != aBackgroundColor)
{
bgcolor.red = NS_GET_R(*aBackgroundColor);
bgcolor.green = NS_GET_G(*aBackgroundColor);
bgcolor.blue = NS_GET_B(*aBackgroundColor);
}
flags = ((aFlags & IL_HIGH_PRIORITY) ? nsImageLoadFlags_kHighPriority : 0) |
((aFlags & IL_STICKY) ? nsImageLoadFlags_kSticky : 0) |
((aFlags & IL_BYPASS_CACHE) ? nsImageLoadFlags_kBypassCache : 0) |
((aFlags & IL_ONLY_FROM_CACHE) ? nsImageLoadFlags_kOnlyFromCache : 0);
mImageReq = IL_GetImage(aUrl, aGroupContext, mXPObserver,
nsnull == aBackgroundColor ? nsnull : &bgcolor,
aWidth, aHeight, flags, (void *)aNetContext, aObserver);
if (mImageReq == nsnull) {
XP_DisposeObserverList(mXPObserver);
mXPObserver = nsnull;
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
NS_IMPL_ISUPPORTS1(ImageRequestImpl, nsIImageRequest);
nsIImage*
ImageRequestImpl::GetImage()
{
if (mImageReq != nsnull) {
IL_Pixmap *pixmap = IL_GetImagePixmap(mImageReq);
if (pixmap != nsnull) {
nsIImage *image = (nsIImage *)pixmap->client_data;
if (image != nsnull) {
NS_ADDREF(image);
return image;
}
}
}
return nsnull;
}
void
ImageRequestImpl::GetNaturalDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
{
if (mImageReq != nsnull) {
IL_GetNaturalDimensions(mImageReq, (int *)aWidth, (int *)aHeight);
}
else {
*aWidth = 0;
*aHeight = 0;
}
}
PRBool
ImageRequestImpl::AddObserver(nsIImageRequestObserver *aObserver)
{
if (aObserver == nsnull) {
return PR_FALSE;
}
if (mObservers == nsnull) {
mObservers = new nsVoidArray();
if (mObservers == nsnull) {
return PR_FALSE;
}
}
NS_ADDREF(aObserver);
mObservers->AppendElement((void *)aObserver);
return PR_TRUE;
}
PRBool
ImageRequestImpl::RemoveObserver(nsIImageRequestObserver *aObserver)
{
PRBool ret;
if (aObserver == nsnull || mObservers == nsnull) {
return PR_FALSE;
}
ret = mObservers->RemoveElement((void *)aObserver);
if (ret == PR_TRUE) {
NS_RELEASE(aObserver);
}
return ret;
}
void
ImageRequestImpl::Interrupt()
{
if (mImageReq != nsnull) {
IL_InterruptRequest(mImageReq);
}
}
void
ImageRequestImpl::ImageDestroyed()
{
if (mXPObserver) {
// Make sure dangling reference to this object goes
// away; this is just in case the image library changes
// and holds onto the observer list after destroying the
// image.
XP_RemoveObserver(mXPObserver, ns_observer_proc, (void*)this);
mXPObserver = nsnull;
}
}

View File

@ -1,79 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsImageRequest_h___
#define nsImageRequest_h___
#include "nsIImageRequest.h"
#include "libimg.h"
#include "nsCRT.h"
#include "nsColor.h"
class nsVoidArray;
class nsIImageRequestObserver;
class ilINetContext;
class ImageRequestImpl : public nsIImageRequest {
public:
ImageRequestImpl();
virtual ~ImageRequestImpl();
nsresult Init(IL_GroupContext *aGroupContext, const char* aUrl,
nsIImageRequestObserver *aObserver,
const nscolor* aBackgroundColor,
PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags,
ilINetContext* aNetContext);
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
// Get the image associated with the request.
virtual nsIImage* GetImage();
// Return the natural dimensions of the image. Returns 0,0
//if the dimensions are unknown.
virtual void GetNaturalDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
// Add and remove observers to listen in on image loading notifications
virtual PRBool AddObserver(nsIImageRequestObserver *aObserver);
virtual PRBool RemoveObserver(nsIImageRequestObserver *aObserver);
// Interrupt loading of just this image.
virtual void Interrupt();
// XXX These should go: fix ns_observer_proc to be a static method
IL_ImageReq *GetImageRequest() { return mImageReq; }
void SetImageRequest(IL_ImageReq *aImageReq) { mImageReq = aImageReq; }
nsVoidArray *GetObservers() { return mObservers; }
void ImageDestroyed();
private:
IL_ImageReq *mImageReq;
IL_GroupContext *mGroupContext;
nsVoidArray *mObservers;
XP_ObserverList mXPObserver;
};
#endif

View File

@ -1,141 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "ilISystemServices.h"
#include "nsITimer.h"
#include "prtypes.h"
#include "prmem.h"
#include "nsCRT.h"
class ImageSystemServicesImpl : public ilISystemServices {
public:
static ImageSystemServicesImpl *sSS;
ImageSystemServicesImpl();
virtual ~ImageSystemServicesImpl();
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
NS_DECL_ISUPPORTS
virtual void * SetTimeout(ilTimeoutCallbackFunction aFunc,
void * aClosure, PRUint32 aMsecs);
virtual void ClearTimeout(void *aTimerID);
};
typedef struct {
ilTimeoutCallbackFunction mFunc;
void *mClosure;
} TimerClosure;
ImageSystemServicesImpl* ImageSystemServicesImpl::sSS = nsnull;
ImageSystemServicesImpl::ImageSystemServicesImpl()
{
NS_INIT_REFCNT();
}
ImageSystemServicesImpl::~ImageSystemServicesImpl()
{
}
NS_IMPL_ISUPPORTS1(ImageSystemServicesImpl, ilISystemServices)
static
void
timer_callback (nsITimer *aTimer, void *aClosure)
{
TimerClosure *tc = (TimerClosure *)aClosure;
(*tc->mFunc)(tc->mClosure);
NS_RELEASE(aTimer);
PR_DELETE(tc);
}
void *
ImageSystemServicesImpl::SetTimeout(ilTimeoutCallbackFunction aFunc,
void * aClosure, PRUint32 aMsecs)
{
nsITimer *timer;
TimerClosure *tc;
nsresult rv;
rv = nsComponentManager::CreateInstance("@mozilla.org/timer;1",
nsnull,
NS_GET_IID(nsITimer),
(void**)&timer);
if (NS_FAILED(rv)) {
return nsnull;
}
tc = (TimerClosure *)PR_NEWZAP(TimerClosure);
if (tc == nsnull) {
NS_RELEASE(timer);
return nsnull;
}
tc->mFunc = aFunc;
tc->mClosure = aClosure;
if (timer->Init(timer_callback, (void *)tc, aMsecs) != NS_OK) {
NS_RELEASE(timer);
PR_DELETE(tc);
return nsnull;
}
return (void *)timer;
}
void
ImageSystemServicesImpl::ClearTimeout(void *aTimerID)
{
nsITimer* timer = (nsITimer *)aTimerID;
void* closure = timer->GetClosure();
timer->Cancel();
NS_RELEASE(timer);
PR_DELETE(closure);
}
extern "C" NS_GFX_(nsresult)
NS_NewImageSystemServices(ilISystemServices **aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (ImageSystemServicesImpl::sSS == nsnull) {
ImageSystemServicesImpl::sSS = new ImageSystemServicesImpl();
}
if (ImageSystemServicesImpl::sSS == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
return ImageSystemServicesImpl::sSS->QueryInterface(NS_GET_IID(ilISystemServices),
(void **) aInstancePtrResult);
}

View File

@ -1,214 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "libimg.h"
#include "nsImageNet.h"
#include "ilINetContext.h"
#include "ilINetReader.h"
#include "ilIURL.h"
#include "nsIURL.h"
#include "nsIURL.h"
#include "nsNetUtil.h"
#include "nsString.h"
static NS_DEFINE_IID(kIImageURLIID, IL_IURL_IID);
class ImageURLImpl : public ilIURL {
public:
ImageURLImpl(void);
virtual ~ImageURLImpl();
NS_DECL_ISUPPORTS
nsresult Init(const char *aURL);
virtual void SetReader(ilINetReader *aReader);
virtual ilINetReader *GetReader();
virtual int GetContentLength();
virtual char* GetAddress();
virtual time_t GetExpires();
virtual PRBool GetBackgroundLoad();
virtual void SetBackgroundLoad(PRBool aBgload);
virtual int GetOwnerId();
virtual void SetOwnerId(int aOwnderId);
private:
nsIURI *mURL;
ilINetReader *mReader;
PRBool mBackgroundLoad;
};
ImageURLImpl::ImageURLImpl(void)
: mURL(nsnull), mReader(nsnull)
{
NS_INIT_REFCNT();
mBackgroundLoad = PR_FALSE;
}
nsresult
ImageURLImpl::Init(const char *aURL)
{
nsresult rv;
{
rv = NS_NewURI(&mURL, aURL);
}
return rv;
}
ImageURLImpl::~ImageURLImpl()
{
NS_IF_RELEASE(mURL);
NS_IF_RELEASE(mReader);
}
nsresult
ImageURLImpl::QueryInterface(const nsIID& aIID,
void** aInstancePtr)
{
if (NULL == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kClassIID, kIImageURLIID);
static NS_DEFINE_IID(kURIIID, NS_IURI_IID);
static NS_DEFINE_IID(kURLIID, NS_IURL_IID);
// xxx I think this is wrong -- this class isn't aggregated with nsIURI!
if (aIID.Equals(kURIIID) ||
aIID.Equals(kURLIID)) {
*aInstancePtr = (void*) mURL;
NS_ADDREF(mURL);
return NS_OK;
}
if (aIID.Equals(kClassIID)) {
*aInstancePtr = (void*) this;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) ((nsISupports*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_THREADSAFE_ADDREF(ImageURLImpl)
NS_IMPL_THREADSAFE_RELEASE(ImageURLImpl)
void
ImageURLImpl::SetReader(ilINetReader *aReader)
{
NS_IF_RELEASE(mReader);
mReader = aReader;
NS_IF_ADDREF(mReader);
}
ilINetReader *
ImageURLImpl::GetReader()
{
NS_IF_ADDREF(mReader);
return mReader;
}
int
ImageURLImpl::GetContentLength()
{
return 0;
}
char*
ImageURLImpl::GetAddress()
{
if (mURL != nsnull) {
char* spec;
mURL->GetSpec(&spec);
return spec;
}
else {
return nsnull;
}
}
time_t
ImageURLImpl::GetExpires()
{
return 0x7FFFFFFF;
}
PRBool ImageURLImpl::GetBackgroundLoad()
{
return mBackgroundLoad;
}
void
ImageURLImpl::SetBackgroundLoad(PRBool aBgload)
{
// XXX help!
mBackgroundLoad = aBgload;
}
int
ImageURLImpl::GetOwnerId()
{
return 0;
}
void
ImageURLImpl::SetOwnerId(int aOwnerId)
{
}
extern "C" NS_GFX_(nsresult)
NS_NewImageURL(ilIURL **aInstancePtrResult, const char *aURL,
nsILoadGroup* aLoadGroup)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
ImageURLImpl *url = new ImageURLImpl();
if (url == nsnull) {
return NS_ERROR_OUT_OF_MEMORY;
}
nsresult rv = url->Init(aURL);
if (rv != NS_OK) {
delete url;
return rv;
}
return url->QueryInterface(kIImageURLIID, (void **) aInstancePtrResult);
}

View File

@ -1,62 +0,0 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = nsjpg
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsJPGModule
REQUIRES = xpcom string img util layout
CPPSRCS = \
jpeg.cpp \
nsJPGDecoder.cpp \
nsJPGModule.cpp \
$(NULL)
LOCAL_INCLUDES = -I$(srcdir)
EXTRA_DSO_LDOPTS = $(JPEG_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
EXTRA_LIBS = $(NSPR_LIBS)
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
include $(topsrcdir)/config/rules.mk
ifeq ($(OS_ARCH)$(OS_RELEASE),SunOS5)
ifeq ($(shell uname -r),5.3)
# In this special case (jpeg.cpp), the compiler has to know
# the OS version to a finer granularity than normal.
DEFINES += -DOSMINOR=3
endif
endif

File diff suppressed because it is too large Load Diff

View File

@ -1,34 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* jpeg.h */
extern int il_jpeg_init(il_container *ic);
extern int il_jpeg_write(il_container *, const PRUint8 *, int32);
extern void il_jpeg_complete(il_container *ic);
//extern unsigned int il_jpeg_write_ready(il_container *ic);
extern void il_jpeg_abort(il_container *ic);

View File

@ -1,84 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
#------------------------------------------------------------------------
#
# Makefile to build the IMGLIB LIB
#
#------------------------------------------------------------------------
MODULE=img
LIBRARY_NAME=nsjpg
MODULE_NAME=nsJPGModule
DEPTH=..\..\..
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
#
# Make sure we have MOZILLA_CLIENT defined so we get the
# proper JS includes
#
LCFLAGS = $(LCFLAGS) -DMOZILLA_CLIENT
!ifdef BUILD_DEBUG_GC
LCFLAGS = $(LCFLAGS) -DDEBUG_GC
!endif
LCFLAGS = $(LCFLAGS) /TP
LLIBS= $(LIBNSPR) \
$(DIST)\lib\util.lib \
$(DIST)\lib\jpeg3250.lib \
$(DIST)\lib\xpcom.lib \
!ifdef NU_CACHE
$(DIST)\lib\cache.lib \
!endif
$(NULL)
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
DEFFILE=nsjpg.def
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
LINCS=-I$(DEPTH)/dist/public/xpcom -I. -I$(DEPTH)/dist/public/raptor -I$(DEPTH)/dist/public/jpeg
CPPSRCS= nsJPGDecoder.cpp nsJPGModule.cpp jpeg.cpp
CPP_OBJS= \
.\$(OBJDIR)\nsJPGDecoder.obj \
.\$(OBJDIR)\nsJPGModule.obj \
.\$(OBJDIR)\jpeg.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@ -1,131 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsJPGDecoder.cpp --- interface to JPG decoder
*/
#include "nsCOMPtr.h"
#include "nsJPGDecoder.h"
#include "jpeg.h"
//////////////////////////////////////////////////////////////////////
// JPG Decoder Implementation
NS_IMPL_ISUPPORTS1(JPGDecoder, nsIImgDecoder);
JPGDecoder::JPGDecoder(il_container* aContainer)
{
NS_INIT_REFCNT();
ilContainer = aContainer;
}
JPGDecoder::~JPGDecoder(void)
{
}
NS_METHOD
JPGDecoder::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
if (aOuter) return NS_ERROR_NO_AGGREGATION;
il_container *ic = new il_container();
if (!ic) return NS_ERROR_OUT_OF_MEMORY;
JPGDecoder *decoder = new JPGDecoder(ic);
if (!decoder) {
delete ic;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(decoder);
rv = decoder->QueryInterface(aIID, aResult);
NS_RELEASE(decoder);
/* why are we creating and destroying this object for no reason? */
delete ic; /* is a place holder */
return rv;
}
/*------------------------------------------------------*/
/* api functions
*/
/*------------------------------------------------------*/
NS_IMETHODIMP
JPGDecoder::ImgDInit()
{
int ret;
if( ilContainer != NULL ) {
ret = il_jpeg_init(ilContainer);
if(ret != 1)
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
JPGDecoder::ImgDWriteReady(PRUint32 *max_read)
{
/* dummy return needed */
*max_read = 2048;
return NS_OK;
}
NS_IMETHODIMP
JPGDecoder::ImgDWrite(const unsigned char *buf, int32 len)
{
int ret;
if( ilContainer != NULL ) {
ret = il_jpeg_write(ilContainer, buf,len);
if(ret != 0)
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
JPGDecoder::ImgDComplete()
{
if( ilContainer != NULL ) {
il_jpeg_complete(ilContainer);
}
return NS_OK;
}
NS_IMETHODIMP
JPGDecoder::ImgDAbort()
{
if( ilContainer != NULL ) {
il_jpeg_abort(ilContainer);
}
return NS_OK;
}

View File

@ -1,58 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsJPGDecoder_h___
#define nsJPGDecoder_h___
#include "nsIImgDecoder.h"
/* 1b0e6b90-d68a-11d2-802e-0060088f91a3 */
#define NS_JPGDECODER_CID \
{ 0x1b0e6b90, 0xd68a, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
class JPGDecoder : public nsIImgDecoder
{
public:
JPGDecoder(il_container* aContainer);
virtual ~JPGDecoder();
NS_DECL_ISUPPORTS
static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
/* stream */
NS_IMETHOD ImgDInit();
NS_IMETHOD ImgDWriteReady(PRUint32 *max_read);
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len);
NS_IMETHOD ImgDComplete();
NS_IMETHOD ImgDAbort();
NS_IMETHOD_(il_container *) SetContainer(il_container *ic){ilContainer = ic; return ic;}
NS_IMETHOD_(il_container *) GetContainer() {return ilContainer;}
private:
il_container* ilContainer;
};
#endif /* nsJPGDecoder_h___ */

View File

@ -1,40 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Pierre Phaneuf <pp@ludusdesign.com>
*/
#include "nsJPGDecoder.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsISupports.h"
#include "nsCOMPtr.h"
static NS_DEFINE_CID(kJPGDecoderCID, NS_JPGDECODER_CID);
static nsModuleComponentInfo components[] =
{
{ "JPEG Decoder",
NS_JPGDECODER_CID,
"@mozilla.org/image/decoder;1?type=image/jpeg",
JPGDecoder::Create }
};
NS_IMPL_NSGETMODULE(nsJPGModule, components)

View File

@ -1,49 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsJPGModule_h___
#define nsJPGModule_h___
#include "nsIModule.h"
class nsJPGModule : public nsIModule
{
public:
NS_DECL_ISUPPORTS
// Construction, Init and desstruction
nsJPGModule();
virtual ~nsJPGModule();
// nsIModule Interfaces
NS_DECL_NSIMODULE
// Facility for counting object instances
int IncrementObjCount() { if (mObjCount == -1) mObjCount = 0; return ++mObjCount; }
int DecrementObjCount() { if (mObjCount == -1) mObjCount = 0; return --mObjCount; }
int GetObjCount() { return mObjCount; }
private:
int mObjCount;
nsISupports* mClassObject;
};
#endif /* nsJPGModule_h___ */

View File

@ -1,14 +0,0 @@
;
; temp def file for nsjpg dll
;
LIBRARY nsjpg.dll
DESCRIPTION 'test dll'
EXPORTS
ImgDInit @1002 PRIVATE
ImgDWrite @1003 PRIVATE
ImgDWriteReady @1004 PRIVATE
ImgDComplete @1005 PRIVATE
ImgDAbort @1006 PRIVATE

View File

@ -1,24 +0,0 @@
?fill_input_buffer@@YAEPAUjpeg_decompress_struct@@@Z ; 53
?ImgDWrite@JPGDecoder@@UAGIPBEJ@Z ; 45
?il_jpeg_write@@YAHPAUil_container_struct@@PBEJ@Z ; 45
?ImgDWriteReady@JPGDecoder@@UAGIPAI@Z ; 44
?output_jpeg_scanlines@@YAHPAUil_container_struct@@H@Z ; 4
?init_source@@YAXPAUjpeg_decompress_struct@@@Z ; 2
?AddRef@JPGDecoder@@UAGKXZ ; 2
?Release@JPGDecoder@@UAGKXZ ; 2
?skip_input_data@@YAXPAUjpeg_decompress_struct@@J@Z ; 2
?SetContainer@JPGDecoder@@UAGPAUil_container_struct@@PAU2@@Z ; 2
?il_jpeg_abort@@YAXPAUil_container_struct@@@Z ; 2
_NSGetModule ; 1
?il_jpeg_COM_handler@@YAEPAUjpeg_decompress_struct@@@Z ; 1
?il_jpeg_init@@YAHPAUil_container_struct@@@Z ; 1
?setup_jpeg_src@@YAHPAUjpeg_decompress_struct@@PAUjpeg_struct@@@Z ; 1
?ImgDInit@JPGDecoder@@UAGIXZ ; 1
?QueryInterface@JPGDecoder@@UAGIABUnsID@@PAPAX@Z ; 1
??_GJPGDecoder@@UAEPAXI@Z ; 1
??0JPGDecoder@@QAE@PAUil_container_struct@@@Z ; 1
?Create@JPGDecoder@@SGIPAVnsISupports@@ABUnsID@@PAPAX@Z ; 1
??1JPGDecoder@@UAE@XZ ; 1
?ImgDAbort@JPGDecoder@@UAGIXZ ; 1
?ImgDComplete@JPGDecoder@@UAGIXZ ; 1
?il_jpeg_complete@@YAXPAUil_container_struct@@@Z ; 1

View File

@ -1,53 +0,0 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = nsmng
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsMNGModule
REQUIRES = xpcom string img layout util mng
CPPSRCS = \
nsMNGDecoder.cpp \
nsMNGModule.cpp \
$(NULL)
LOCAL_INCLUDES = -I$(srcdir)
EXTRA_DSO_LDOPTS = $(MNG_LIBS) $(JPEG_LIBS) $(ZLIB_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
EXTRA_LIBS = $(NSPR_LIBS)
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
include $(topsrcdir)/config/rules.mk

View File

@ -1,86 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
#------------------------------------------------------------------------
#
# Makefile to build the IMGLIB LIB
#
#------------------------------------------------------------------------
MODULE=img
LIBRARY_NAME=nsmng
MODULE_NAME=nsMNGModule
DEPTH=..\..\..
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
#
# Make sure we have MOZILLA_CLIENT defined so we get the
# proper JS includes
#
LCFLAGS = $(LCFLAGS) -DMOZILLA_CLIENT
!ifdef BUILD_DEBUG_GC
LCFLAGS = $(LCFLAGS) -DDEBUG_GC
!endif
LCFLAGS = $(LCFLAGS) /TP
LLIBS= $(LIBNSPR) \
$(DIST)\lib\util.lib \
$(DIST)\lib\mng.lib \
$(DIST)\lib\jpeg3250.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\zlib.lib \
!ifdef NU_CACHE
$(DIST)\lib\cache.lib \
!endif
$(NULL)
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
DEFFILE=nsmng.def
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
LINCS=-I$(DEPTH)/dist/public/xpcom -I. -I$(DEPTH)/dist/public/raptor \
-I$(DEPTH)/dist/public/jpeg -I$(DEPTH)/dist/public/zlib -I$(DEPTH)/dist/public/img
CPPSRCS= nsMNGDecoder.cpp nsMNGCallback.cpp
CPP_OBJS= \
.\$(OBJDIR)\nsMNGDecoder.obj \
.\$(OBJDIR)\nsMNGModule.obj
include <$(DEPTH)\config\rules.mak>

View File

@ -1,456 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Tim Rowley, tor@cs.brown.edu, original author
*/
#include "nsMNGDecoder.h"
#include "nsIImgDCallbk.h"
#include "nsMemory.h"
#include "libmng.h"
#include "prinrval.h"
typedef struct imng_str {
mng_handle handle;
PRUint32 width;
PRUint32 height;
PRUint8 *image; /* full image buffer */
PRUint8 *rowbuf; /* ImgDCBHaveRow is destructive. Grrr... */
PRUint32 channels; /* How many channels (3 or 4) */
void *timer_id;
PRUint8 *writeBuffer; /* Bugzilla 41831 */
PRUint32 bufferSize;
PRUint32 bufferEnd;
PRUint32 bufferPtr;
PRBool resumeNeeded; /* need to call display_resume? */
il_container *ic;
} imng_struct, *imng_structp;
#define EXTRACT_STRUCTS \
il_container *ic = (il_container *)mng_get_userdata(handle); \
imng_structp imng_p = (imng_structp)ic->ds
#ifdef DEBUG_tor
#define dprintf(x) fprintf x
#else
#define dprintf(x)
#endif
// 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_STRUCTS;
dprintf((stderr, "MNG::readdata size=%d buffered=%d\n",
size, imng_p->bufferEnd - imng_p->bufferPtr));
size = PR_MIN(size, imng_p->bufferEnd - imng_p->bufferPtr);
memcpy(buf, imng_p->writeBuffer+imng_p->bufferPtr, size);
imng_p->bufferPtr += size;
*stored = size;
return MNG_TRUE;
}
static mng_bool
il_mng_processheader(mng_handle handle, mng_uint32 width, mng_uint32 height)
{
EXTRACT_STRUCTS;
imng_p->width = width;
imng_p->height = height;
ic->src_header->width = width;
ic->src_header->height = height;
switch (mng_get_alphadepth(handle)) {
case 0:
dprintf((stderr, "--- MNG ALPHA NONE\n"));
ic->image->header.alpha_bits = 0;
mng_set_canvasstyle(imng_p->handle, MNG_CANVAS_RGB8);
imng_p->channels = 3;
break;
case 1:
dprintf((stderr, "--- MNG ALPHA THRESHHOLD\n"));
ic->image->header.alpha_bits = 1;
mng_set_canvasstyle(imng_p->handle, MNG_CANVAS_RGBA8);
imng_p->channels = 4;
break;
default:
dprintf((stderr, "--- MNG ALPHA 8-BIT\n"));
ic->image->header.alpha_bits = 8;
mng_set_canvasstyle(imng_p->handle, MNG_CANVAS_RGBA8);
imng_p->channels = 4;
break;
}
ic->image->header.alpha_shift = 0;
ic->image->header.is_interleaved_alpha = TRUE;
imng_p->image =
(unsigned char*)nsMemory::Alloc(imng_p->channels*width*height);
memset(imng_p->image, 0, imng_p->channels*width*height);
imng_p->rowbuf = (unsigned char*)nsMemory::Alloc(imng_p->channels*width);
ic->imgdcb->ImgDCBImageSize();
ic->imgdcb->ImgDCBSetupColorspaceConverter();
return MNG_TRUE;
}
static mng_ptr
il_mng_getcanvasline(mng_handle handle, mng_uint32 iLinenr)
{
EXTRACT_STRUCTS;
return imng_p->image+imng_p->channels*imng_p->width*iLinenr;
}
static mng_bool
il_mng_refresh(mng_handle handle,
mng_uint32 left, mng_uint32 top,
mng_uint32 width, mng_uint32 height)
{
// dprintf((stderr, "=== refresh(top=%d left=%d width=%d height=%d)\n",
// top, left, width, height));
EXTRACT_STRUCTS;
for (mng_uint32 y=top; y<top+height; y++) {
memcpy(imng_p->rowbuf,
imng_p->image+y*imng_p->channels*imng_p->width,
imng_p->channels*imng_p->width);
ic->imgdcb->ImgDCBHaveRow(0 /* color index data */,
imng_p->rowbuf /* rgb[a] */,
0 /* x-offset */,
imng_p->width /* width in pixels */,
y /* start row */,
1 /* row duplication count */,
ilErase /* draw mode */,
mng_get_refreshpass(handle) /* pass */);
}
if (mng_get_imagetype(handle) == mng_it_mng) {
ic->imgdcb->ImgDCBFlushImage();
ic->imgdcb->ImgDCBHaveImageFrame();
}
return MNG_TRUE;
}
static mng_uint32
il_mng_gettickcount(mng_handle handle)
{
// dprintf((stderr, "=== gettickcount()\n"));
return PR_IntervalToMilliseconds(PR_IntervalNow());
}
static void
il_mng_timeout_func(void *data)
{
mng_handle handle = (mng_handle)data;
EXTRACT_STRUCTS;
// dprintf((stderr, "il_mng_timeout_func\n"));
imng_p->timer_id = 0;
int ret = mng_display_resume(handle);
if (ret == MNG_NEEDMOREDATA)
imng_p->resumeNeeded = PR_TRUE;
// dprintf((stderr, "il_mng_timeout_func display_resume returned %d\n", ret));
}
static mng_bool
il_mng_settimer(mng_handle handle, mng_uint32 msec)
{
dprintf((stderr, "=== settimer(%d)\n", msec));
EXTRACT_STRUCTS;
imng_p->timer_id =
ic->imgdcb->ImgDCBSetTimeout(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);
}
#ifdef DEBUG_tor
static mng_bool
il_mng_trace(mng_handle handle, mng_int32 iFuncnr, mng_int32 iFuncseq,
mng_pchar zFuncname)
{
dprintf((stderr, "== trace == %s %d %d\n", zFuncname, iFuncnr, iFuncseq));
return MNG_TRUE;
}
static mng_bool
il_mng_error(mng_handle hHandle, mng_int32 iErrorcode, mng_int8 iSeverity,
mng_chunkid iChunkname, mng_uint32 iChunkseq, mng_int32 iExtra1,
mng_int32 iExtra2, mng_pchar zErrortext)
{
dprintf((stderr, "== error == %s\n", zErrortext));
return MNG_TRUE;
}
#endif
// Boilerplate methods... *yawn*
//===========================================================
MNGDecoder::MNGDecoder(il_container* aContainer)
{
NS_INIT_REFCNT();
ilContainer = aContainer;
}
MNGDecoder::~MNGDecoder(void)
{
}
NS_IMPL_ISUPPORTS1(MNGDecoder, nsIImgDecoder)
NS_METHOD
MNGDecoder::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
if (aOuter) return NS_ERROR_NO_AGGREGATION;
il_container *ic = new il_container();
if (!ic) return NS_ERROR_OUT_OF_MEMORY;
MNGDecoder *decoder = new MNGDecoder(ic);
if (!decoder) {
delete ic;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(decoder);
rv = decoder->QueryInterface(aIID, aResult);
NS_RELEASE(decoder);
/* why are we creating and destroying this object for no reason? */
delete ic; /* is a place holder */
return rv;
}
// Hooking mozilla and libmng together...
//===========================================================
NS_IMETHODIMP
MNGDecoder::ImgDInit()
{
if( ilContainer != NULL ) {
imng_structp imng_p;
imng_p = (imng_structp) nsMemory::Alloc(sizeof(imng_struct));
if (!imng_p)
return PR_FALSE;
memset(imng_p, 0, sizeof(imng_struct));
imng_p->writeBuffer = (PRUint8 *)nsMemory::Alloc(4096);
imng_p->bufferSize = 4096;
ilContainer->image->header.width = ilContainer->dest_width;
ilContainer->image->header.height = ilContainer->dest_height;
ilContainer->ds = imng_p;
imng_p->ic = ilContainer;
/* Initialize the container's source image header. */
/* Always decode to 24 bit pixdepth */
NI_ColorSpace *src_color_space = ilContainer->src_header->color_space;
src_color_space->type = NI_TrueColor;
src_color_space->pixmap_depth = 24;
src_color_space->bit_alloc.index_depth = 0;
/* pass ic as user data */
imng_p->handle =
mng_initialize(ilContainer, 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...
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
/* (alternatively, could check for SCREEN_GAMMA environment variable) */
display_exponent = LUT_exponent * CRT_exponent;
mng_set_dfltimggamma(imng_p->handle, 0.45455);
mng_set_displaygamma(imng_p->handle, display_exponent);
////////////
mng_setcb_openstream(imng_p->handle, il_mng_openstream);
mng_setcb_closestream(imng_p->handle, il_mng_closestream);
mng_setcb_readdata(imng_p->handle, il_mng_readdata);
mng_setcb_processheader(imng_p->handle, il_mng_processheader);
mng_setcb_getcanvasline(imng_p->handle, il_mng_getcanvasline);
mng_setcb_refresh(imng_p->handle, il_mng_refresh);
mng_setcb_gettickcount(imng_p->handle, il_mng_gettickcount);
mng_setcb_settimer(imng_p->handle, il_mng_settimer);
mng_setcb_memalloc(imng_p->handle, il_mng_alloc);
mng_setcb_memfree(imng_p->handle, il_mng_free);
mng_set_suspensionmode(imng_p->handle, MNG_TRUE);
if (mng_readdisplay(imng_p->handle) == MNG_NEEDMOREDATA)
imng_p->resumeNeeded = PR_TRUE;
}
return NS_OK;
}
NS_IMETHODIMP
MNGDecoder::ImgDWriteReady(PRUint32 *max_read)
{
dprintf((stderr, "MNG::ImgDWriteReady() = "));
imng_structp imng_p = (imng_structp)ilContainer->ds;
/* add a bit, because libimg actually believes us if max_read==0 */
*max_read = imng_p->bufferSize - imng_p->bufferEnd + 1024;
dprintf((stderr, "%d\n", *max_read));
return NS_OK;
}
NS_IMETHODIMP
MNGDecoder::ImgDWrite(const unsigned char *buf, int32 len)
{
dprintf((stderr, "MNG::ImgDWrite(%d)\n", len));
if (ilContainer != NULL) {
imng_structp imng_p = (imng_structp)ilContainer->ds;
if (imng_p->bufferEnd+len > imng_p->bufferSize) {
imng_p->bufferSize *= 2;
imng_p->writeBuffer = (PRUint8 *)
nsMemory::Realloc(imng_p->writeBuffer, imng_p->bufferSize);
}
memcpy(imng_p->writeBuffer+imng_p->bufferEnd, buf, len);
imng_p->bufferEnd += len;
if (imng_p->resumeNeeded) {
// dprintf((stderr, "MNG::ImgDWrite display_resume\n"));
imng_p->resumeNeeded = PR_FALSE;
int ret = mng_display_resume(imng_p->handle);
if (ret == MNG_NEEDMOREDATA)
imng_p->resumeNeeded = PR_TRUE;
// dprintf((stderr, "MNG::ImgDWrite display_resume returned %d\n", ret));
}
}
return NS_OK;
}
NS_IMETHODIMP
MNGDecoder::ImgDComplete()
{
return NS_OK;
}
NS_IMETHODIMP
MNGDecoder::ImgDAbort()
{
if( ilContainer != NULL ) {
imng_structp imng_p = (imng_structp)ilContainer->ds;
if (!imng_p)
return NS_OK;
if (imng_p->timer_id) {
ilContainer->imgdcb->ImgDCBClearTimeout(imng_p->timer_id);
imng_p->timer_id = 0;
}
mng_display_freeze(imng_p->handle);
mng_cleanup(&imng_p->handle);
nsMemory::Free(imng_p->writeBuffer);
nsMemory::Free(imng_p->image);
nsMemory::Free(imng_p->rowbuf);
nsMemory::Free(imng_p);
imng_p = NULL;
}
return NS_OK;
}

View File

@ -1,61 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Tim Rowley, tor@cs.brown.edu, original author
*/
#ifndef nsMNGDecoder_h___
#define nsMNGDecoder_h___
#include "nsIImgDecoder.h"
/* d73f1676-1dd1-11b2-ba33-aabc09e02d10 */
#define NS_MNGDECODER_CID \
{ 0xd73f1676, 0x1dd1, 0x11b2, \
{ 0xba, 0x33, 0xaa, 0xbc, 0x09, 0xe0, 0x2d, 0x10 } }
class MNGDecoder : public nsIImgDecoder
{
public:
MNGDecoder(il_container* aContainer);
virtual ~MNGDecoder();
NS_DECL_ISUPPORTS
static NS_METHOD Create(nsISupports *aOuter, const nsIID &aIID, void **aResult);
/* stream */
NS_IMETHOD ImgDInit();
NS_IMETHOD ImgDWriteReady(PRUint32 *max_read);
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len);
NS_IMETHOD ImgDComplete();
NS_IMETHOD ImgDAbort();
NS_IMETHOD_(il_container *) SetContainer(il_container *ic){ilContainer = ic; return ic;}
NS_IMETHOD_(il_container *) GetContainer() {return ilContainer;}
private:
il_container* ilContainer;
};
#endif /* nsMNGDecoder_h___ */

View File

@ -1,44 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Tim Rowley, tor@cs.brown.edu, original author
*/
#include "nsMNGDecoder.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsISupports.h"
#include "nsCOMPtr.h"
static NS_DEFINE_CID(kMNGDecoderCID, NS_MNGDECODER_CID);
static nsModuleComponentInfo components[] =
{
{ "MNG Decoder",
NS_MNGDECODER_CID,
"@mozilla.org/image/decoder;1?type=video/x-mng",
MNGDecoder::Create },
{ "JNG Decoder",
NS_MNGDECODER_CID,
"@mozilla.org/image/decoder;1?type=image/x-jng",
MNGDecoder::Create }
};
NS_IMPL_NSGETMODULE(nsMNGModule, components)

View File

@ -1,14 +0,0 @@
;
; temp def file for nsmng dll
;
LIBRARY nsmng.dll
DESCRIPTION 'test dll'
EXPORTS
ImgDInit @1002 PRIVATE
ImgDWrite @1003 PRIVATE
ImgDWriteReady @1004 PRIVATE
ImgDComplete @1005 PRIVATE
ImgDAbort @1006 PRIVATE

View File

@ -1 +0,0 @@
_NSGetModule ; 1

View File

@ -1,54 +0,0 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = nspng
EXPORT_LIBRARY = 1
IS_COMPONENT = 1
MODULE_NAME = nsPNGModule
REQUIRES = xpcom string img util layout png
CPPSRCS = \
ipng.cpp \
nsPNGDecoder.cpp \
nsPNGModule.cpp \
$(NULL)
LOCAL_INCLUDES = -I$(srcdir)
EXTRA_DSO_LDOPTS = $(PNG_LIBS) $(ZLIB_LIBS) \
$(MOZ_COMPONENT_LIBS) \
$(NULL)
EXTRA_LIBS = $(NSPR_LIBS)
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
include $(topsrcdir)/config/rules.mk

View File

@ -1,447 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
*
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM described herein are
* Copyright (c) International Business Machines
* Corporation, 2000
*
* Modifications to Mozilla code or documentation
* identified per MPL Section 3.3
*
* Date Modified by Description of modification
* 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
* use in OS2
*/
#include "png.h"
#include "nsIImgDecoder.h" // include if_struct.h Needs to be first
#include "ipng.h"
#include "pngdec.h"
#include "nsPNGDecoder.h"
#include "nsIImgDCallbk.h"
#include "ilISystemServices.h"
#define MINIMUM_DELAY_TIME 10
static void PR_CALLBACK info_callback(png_structp png_ptr, png_infop info);
static void PR_CALLBACK row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass);
static void PR_CALLBACK end_callback(png_structp png_ptr, png_infop info);
static void PR_CALLBACK il_png_error_handler(png_structp png_ptr, png_const_charp msg);
#ifdef DEBUG
static int il_debug_png = 0;
static PRLogModuleInfo *il_log_module_png = NULL;
#define ILTRACE(l,t) { if(il_debug_png>l) {PR_LOG(il_log_module_png, 1, t);} }
#else
#define ILTRACE(l,t) {}
#endif
#define CAN_SUPPORT_8_BIT_MASK
PRBool
il_png_init(il_container *ic)
{
ipng_struct *ipng_p;
NI_ColorSpace *src_color_space = ic->src_header->color_space;
ic->image->header.width = ic->dest_width;
ic->image->header.height = ic->dest_height;
ipng_p = PR_NEWZAP(ipng_struct);
if (!ipng_p)
return PR_FALSE;
ic->ds = ipng_p;
ipng_p->state = PNG_INIT;
ipng_p->ic = ic;
/* Initialize the container's source image header. */
/* Always decode to 24 bit pixdepth */
src_color_space->type = NI_TrueColor;
src_color_space->pixmap_depth = 24;
src_color_space->bit_alloc.index_depth = 0;
png_structp png_ptr;
png_infop info_ptr;
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, ipng_p,
il_png_error_handler, NULL);
if (png_ptr == NULL) {
ipng_p->pngs_p = NULL;
ipng_p->info_p = NULL;
ipng_p->state = PNG_ERROR;
return -1;
}
info_ptr = png_create_info_struct(png_ptr);
if (info_ptr == NULL) {
png_destroy_read_struct(&png_ptr, NULL, NULL);
ipng_p->pngs_p = NULL;
ipng_p->info_p = NULL;
ipng_p->state = PNG_ERROR;
return -1;
}
ipng_p->pngs_p = png_ptr;
ipng_p->info_p = info_ptr;
/* use ic as libpng "progressive pointer" (retrieve in callbacks) */
png_set_progressive_read_fn(png_ptr, (void *)ic, info_callback,
row_callback, end_callback);
return PR_TRUE;
}
/* Gather n characters from the input stream and then enter state s. */
int
il_png_write(il_container *ic, const unsigned char *buf, int32 len)
{
ipng_structp ipng_p;
PR_ASSERT(ic != NULL);
ipng_p = (ipng_structp)ic->ds;
if (ipng_p->state == PNG_ERROR)
return -1;
if (setjmp(ipng_p->jmpbuf)) {
png_destroy_read_struct(&ipng_p->pngs_p, &ipng_p->info_p, NULL);
ipng_p->state = PNG_ERROR;
return -1;
}
png_process_data(ipng_p->pngs_p, ipng_p->info_p, (unsigned char *)buf, len);
ipng_p->state = PNG_CONTINUE;
return 0;
}
int
il_png_complete(il_container *ic)
{
/* notify observers that the current frame has completed. */
ic->imgdcb->ImgDCBHaveImageAll();
return 0;
}
int
il_png_abort(il_container *ic)
{
if (ic->ds) {
ipng_structp ipng_p = (ipng_structp)ic->ds;
PR_FREEIF(ipng_p->rgbrow);
PR_FREEIF(ipng_p->alpharow);
PR_FREEIF(ipng_p->interlacebuf);
ipng_p->rgbrow = NULL;
ipng_p->alpharow = NULL;
ipng_p->interlacebuf = NULL;
if((ipng_p->pngs_p)&&(ipng_p->info_p))
png_destroy_read_struct(&ipng_p->pngs_p, &ipng_p->info_p, NULL);
PR_FREEIF(ipng_p);
ic->ds = NULL;
}
/* il_abort( ic ); */
return 0;
}
/*---------------------------------------------------------------------------
Former contents of png_png.cpp, a.k.a. libpng's example.c (modified):
---------------------------------------------------------------------------*/
static void
info_callback(png_structp png_ptr, png_infop info_ptr)
{
/* int number_passes; NOT USED */
png_uint_32 width, height;
int bit_depth, color_type, interlace_type, compression_type, filter_type;
int channels;
double LUT_exponent, CRT_exponent = 2.2, display_exponent, aGamma;
il_container *ic;
ipng_structp ipng_p;
NI_PixmapHeader *img_hdr;
NI_PixmapHeader *src_hdr;
png_bytep trans=NULL;
int num_trans =0;
/* always decode to 24-bit RGB or 32-bit RGBA */
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type,
&interlace_type, &compression_type, &filter_type);
if (color_type == PNG_COLOR_TYPE_PALETTE)
png_set_expand(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
png_set_expand(png_ptr);
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS))
{
png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL);
png_set_expand(png_ptr);
}
if (bit_depth == 16)
png_set_strip_16(png_ptr);
if (color_type == PNG_COLOR_TYPE_GRAY ||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
png_set_gray_to_rgb(png_ptr);
/* 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
/* (alternatively, could check for SCREEN_GAMMA environment variable) */
display_exponent = LUT_exponent * CRT_exponent;
if (png_get_gAMA(png_ptr, info_ptr, &aGamma))
png_set_gamma(png_ptr, display_exponent, aGamma);
else
png_set_gamma(png_ptr, display_exponent, 0.45455);
/* let libpng expand interlaced images */
if (interlace_type == PNG_INTERLACE_ADAM7)
/* number_passes = */ png_set_interlace_handling(png_ptr);
/* now all of those things we set above are used to update various struct
* members and whatnot, after which we can get channels, rowbytes, etc. */
png_read_update_info(png_ptr, info_ptr);
channels = png_get_channels(png_ptr, info_ptr);
PR_ASSERT(channels == 3 || channels == 4);
/* set the ic values */
ic = (il_container *)png_get_progressive_ptr(png_ptr);
PR_ASSERT(ic != NULL);
/*---------------------------------------------------------------*/
/* copy PNG info into imagelib structs (formerly png_set_dims()) */
/*---------------------------------------------------------------*/
ipng_p = (ipng_structp)ic->ds;
img_hdr = &ic->image->header;
src_hdr = ic->src_header;
ipng_p->width = src_hdr->width = width;
ipng_p->height = src_hdr->height = height;
ipng_p->channels = channels;
PR_ASSERT(ipng_p->rgbrow == NULL);
PR_ASSERT(ipng_p->alpharow == NULL);
ipng_p->rgbrow = (PRUint8 *)PR_MALLOC(channels*width);
if (!ipng_p->rgbrow) {
ILTRACE(0, ("il:png: MEM row"));
ipng_p->state = PNG_ERROR;
return;
}
if(interlace_type == PNG_INTERLACE_ADAM7) {
ipng_p->interlacebuf = (PRUint8 *)PR_MALLOC(channels*width*height);
if (!ipng_p->interlacebuf) {
ILTRACE(0, ("il:png: MEM interlacebuf"));
ipng_p->state = PNG_ERROR;
return;
}
}
else
ipng_p->interlacebuf = NULL;
if (channels > 3) {
ipng_p->alpharow = NULL;
#if defined(CAN_SUPPORT_8_BIT_MASK)
if (color_type || PNG_COLOR_MASK_ALPHA) {
/* check if alpha is coming from a tRNS chunk and is binary */
if (num_trans) {
ic->image->header.alpha_bits = 1;
/* if it's not a indexed color image, tRNS means binary */
if (color_type == PNG_COLOR_TYPE_PALETTE)
for (int i=0; i<num_trans; i++)
if ((trans[i] != 0) && (trans[i] != 255)) {
ic->image->header.alpha_bits = 8;
break;
}
} else
ic->image->header.alpha_bits = 8/*png_ptr->pixel_depth*/; /* 8 */
} else
#endif
ic->image->header.alpha_bits = 1;
ic->image->header.alpha_shift = 0;
ic->image->header.is_interleaved_alpha = PR_TRUE;
}
ic->imgdcb->ImgDCBImageSize();
/* Note: all PNGs are decoded to RGB or RGBA and
converted by imglib to appropriate pixel depth */
ic->imgdcb->ImgDCBSetupColorspaceConverter();
return;
}
static void
row_callback(png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass)
{
/* libpng comments:
*
* this function is called for every row in the image. If the
* image is interlacing, and you turned on the interlace handler,
* this function will be called for every row in every pass.
* Some of these rows will not be changed from the previous pass.
* When the row is not changed, the new_row variable will be NULL.
* The rows and passes are called in order, so you don't really
* need the row_num and pass, but I'm supplying them because it
* may make your life easier.
*
* For the non-NULL rows of interlaced images, you must call
* png_progressive_combine_row() passing in the row and the
* old row. You can call this function for NULL rows (it will
* just return) and for non-interlaced images (it just does the
* memcpy for you) if it will make the code easier. Thus, you
* can just do this for all cases:
*
* png_progressive_combine_row(png_ptr, old_row, new_row);
*
* where old_row is what was displayed for previous rows. Note
* that the first pass (pass == 0 really) will completely cover
* the old row, so the rows do not have to be initialized. After
* the first pass (and only for interlaced images), you will have
* to pass the current row, and the function will combine the
* old row and the new row.
*/
il_container *ic = (il_container *)png_get_progressive_ptr(png_ptr);
ipng_structp ipng_p = (ipng_structp)ic->ds;
PR_ASSERT(ipng_p);
int bw = ipng_p->channels * ipng_p->width;
png_bytep line;
if(ipng_p->interlacebuf)
{
line = ipng_p->interlacebuf+row_num*bw;
png_progressive_combine_row(png_ptr, line, new_row);
}
else
line = new_row;
if (new_row) {
/* first we copy the row data to a different buffer so that
* il_emit_row() in scale.cpp doesn't mess up libpng's row buffer
*/
memcpy(ipng_p->rgbrow, line, bw);
ic->imgdcb->ImgDCBHaveRow(0, ipng_p->rgbrow, 0, ipng_p->width,
row_num, 1, ilErase /* ilOverlay */, pass);
}
}
static void
end_callback(png_structp png_ptr, png_infop info_ptr)
{
/* libpng comments:
*
* this function is called when the whole image has been read,
* including any chunks after the image (up to and including
* the IEND). You will usually have the same info chunk as you
* had in the header, although some data may have been added
* to the comments and time fields.
*
* Most people won't do much here, perhaps setting a flag that
* marks the image as finished.
*/
il_container *ic = (il_container *)png_get_progressive_ptr(png_ptr);
ic->imgdcb->ImgDCBFlushImage();
}
static void
il_png_error_handler(png_structp png_ptr, png_const_charp msg)
{
ipng_structp ipng_p;
/* This function, aside from the extra step of retrieving the "error
* pointer" (below) and the fact that it exists within the application
* rather than within libpng, is essentially identical to libpng's
* default error handler. The second point is critical: since both
* setjmp() and longjmp() are called from the same code, they are
* guaranteed to have compatible notions of how big a jmp_buf is,
* regardless of whether _BSD_SOURCE or anything else has (or has not)
* been defined. Adapted from readpng2_error_handler() in "PNG: The
* Definitive Guide" (O'Reilly, 1999). */
#ifdef DEBUG
fprintf(stderr, "nspng libpng error: %s\n", msg);
fflush(stderr);
#endif
ipng_p = (ipng_structp)png_get_error_ptr(png_ptr);
if (ipng_p == NULL) { /* we are completely hosed now */
#ifdef DEBUG
fprintf(stderr, "nspng severe error: jmpbuf not recoverable.\n");
fflush(stderr);
#endif
PR_ASSERT(ipng_p != NULL); /* instead of exit(99); */
}
longjmp(ipng_p->jmpbuf, 1);
}

View File

@ -1,58 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* ipng.h */
typedef enum {
PNG_ERROR,
PNG_INIT,
PNG_CONTINUE,
PNG_DELAY,
PNG_FINISH,
PNG_DONE
} png_state;
typedef struct ipng_str {
png_state state; /* Decoder FSM state */
/* int rows_per_chunk; NOT USED (similar variable in jpeg_struct) */
void *delay_timeout;
PRUint32 delay_time;
png_structp pngs_p;
png_infop info_p;
jmp_buf jmpbuf; /* use ours, not libpng's, for consistency */
PRUint32 width;
PRUint32 height;
int channels; /* color channels (3 or 4) */
PRUint8 *rgbrow; /* RGB row buffer (3*width bytes) */
PRUint8 *alpharow; /* alpha row buffer (width bytes) */
PRUint8 *interlacebuf; /* interlace buffer */
/* One scanline's worth of post-processed sample data */
il_container *ic;
} ipng_struct, *ipng_structp;

View File

@ -1,86 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
#------------------------------------------------------------------------
#
# Makefile to build the IMGLIB LIB
#
#------------------------------------------------------------------------
MODULE=img
LIBRARY_NAME=nspng
MODULE_NAME=nsPNGModule
DEPTH=..\..\..
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
#
# Make sure we have MOZILLA_CLIENT defined so we get the
# proper JS includes
#
LCFLAGS = $(LCFLAGS) -DMOZILLA_CLIENT
!ifdef BUILD_DEBUG_GC
LCFLAGS = $(LCFLAGS) -DDEBUG_GC
!endif
LCFLAGS = $(LCFLAGS) /TP
LLIBS= $(LIBNSPR) \
$(DIST)\lib\util.lib \
$(DIST)\lib\png.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\zlib.lib \
!ifdef NU_CACHE
$(DIST)\lib\cache.lib \
!endif
$(NULL)
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
DEFFILE=nspng.def
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
LINCS=-I$(DEPTH)/dist/public/xpcom -I. -I$(DEPTH)/dist/public/raptor \
-I$(DEPTH)/dist/public/png -I$(DEPTH)/dist/public/zlib -I$(DEPTH)/dist/public/img
CPPSRCS= nsPNGDecoder.cpp nsPNGCallback.cpp ipng.cpp
CPP_OBJS= \
.\$(OBJDIR)\nsPNGDecoder.obj \
.\$(OBJDIR)\nsPNGModule.obj \
.\$(OBJDIR)\ipng.obj
include <$(DEPTH)\config\rules.mak>

View File

@ -1,139 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsPNGDecoder.cpp --- interface to png decoder
*/
#include "nsPNGDecoder.h"
#include "pngdec.h"
/*-----------class----------------*/
/*-------------------------------------------------*/
PNGDecoder::PNGDecoder(il_container* aContainer)
{
NS_INIT_REFCNT();
ilContainer = aContainer;
};
PNGDecoder::~PNGDecoder(void)
{
};
NS_IMPL_ISUPPORTS1(PNGDecoder, nsIImgDecoder)
NS_METHOD
PNGDecoder::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
if (aOuter) return NS_ERROR_NO_AGGREGATION;
il_container *ic = new il_container();
if (!ic) return NS_ERROR_OUT_OF_MEMORY;
PNGDecoder *decoder = new PNGDecoder(ic);
if (!decoder) {
delete ic;
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(decoder);
rv = decoder->QueryInterface(aIID, aResult);
NS_RELEASE(decoder);
/* why are we creating and destroying this object for no reason? */
delete ic; /* is a place holder */
return rv;
}
/*----------------------------------------------------*/
// api functions
/*------------------------------------------------------*/
NS_IMETHODIMP
PNGDecoder::ImgDInit()
{
int ret;
if( ilContainer != NULL ) {
ret = il_png_init(ilContainer);
if(!ret)
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
PNGDecoder::ImgDWriteReady(PRUint32 *max_read)
{
/* dummy return needed */
*max_read = 2048;
return NS_OK;
}
NS_IMETHODIMP
PNGDecoder::ImgDWrite(const unsigned char *buf, int32 len)
{
int ret;
if( ilContainer != NULL ) {
ret = il_png_write(ilContainer, buf,len);
if(ret != 0)
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
PNGDecoder::ImgDComplete()
{
int ret;
if( ilContainer != NULL ) {
ret = il_png_complete(ilContainer);
if(ret != 0)
return NS_ERROR_FAILURE;
}
return NS_OK;
}
NS_IMETHODIMP
PNGDecoder::ImgDAbort()
{
int ret;
if( ilContainer != NULL ) {
ret = il_png_abort(ilContainer);
if(ret != 0)
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@ -1,58 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsPNGDecoder_h___
#define nsPNGDecoder_h___
#include "nsIImgDecoder.h"
/* 573010b0-de61-11d2-802c-0060088f91a3 */
#define NS_PNGDECODER_CID \
{ 0x573010b0, 0xde61, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
class PNGDecoder : public nsIImgDecoder
{
public:
PNGDecoder(il_container* aContainer);
virtual ~PNGDecoder();
NS_DECL_ISUPPORTS
static NS_METHOD Create(nsISupports *aOuter, const nsIID &aIID, void **aResult);
/* stream */
NS_IMETHOD ImgDInit();
NS_IMETHOD ImgDWriteReady(PRUint32 *max_read);
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len);
NS_IMETHOD ImgDComplete();
NS_IMETHOD ImgDAbort();
NS_IMETHOD_(il_container *) SetContainer(il_container *ic){ilContainer = ic; return ic;}
NS_IMETHOD_(il_container *) GetContainer() {return ilContainer;}
private:
il_container* ilContainer;
};
#endif /* nsPNGDecoder_h___ */

View File

@ -1,40 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsPNGDecoder.h"
#include "nsIComponentManager.h"
#include "nsIGenericFactory.h"
#include "nsISupports.h"
#include "nsCOMPtr.h"
static NS_DEFINE_CID(kPNGDecoderCID, NS_PNGDECODER_CID);
static nsModuleComponentInfo components[] =
{
{ "PNG Decoder",
NS_PNGDECODER_CID,
"@mozilla.org/image/decoder;1?type=image/png",
PNGDecoder::Create }
};
NS_IMPL_NSGETMODULE(nsPNGModule, components)

View File

@ -1,14 +0,0 @@
;
; temp def file for nspng dll
;
LIBRARY nspng.dll
DESCRIPTION 'test dll'
EXPORTS
ImgDInit @1002 PRIVATE
ImgDWrite @1003 PRIVATE
ImgDWriteReady @1004 PRIVATE
ImgDComplete @1005 PRIVATE
ImgDAbort @1006 PRIVATE

View File

@ -1,140 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* png_png.c - modified from example.c code */
#include "png.h"
#include "nsIImgDecoder.h" // include if_struct.h Needs to be first
#include "ipng.h"
#include "nsPNGDecoder.h"
#include "nsIImgDCallbk.h"
extern void png_set_dims(il_container *, png_structp);
void info_callback(png_structp png_ptr, png_infop info)
{
/* do any setup here, including setting any of the transformations
* mentioned in the Reading PNG files section. For now, you _must_
* call either png_start_read_image() or png_read_update_info()
* after all the transformations are set (even if you don't set
* any). You may start getting rows before png_process_data()
* returns, so this is your last chance to prepare for that.
*/
int number_passes;
double screen_gamma;
/*always decode to 24 bit*/
if(png_ptr->color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->bit_depth <= 8)
png_set_expand(png_ptr);
if(png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth <= 8){
png_set_gray_to_rgb(png_ptr);
png_set_expand(png_ptr);
}
if(png_get_valid(png_ptr, info, PNG_INFO_tRNS))
png_set_expand(png_ptr);
/* implement scr gamma for mac & unix. (do preferences later.) */
#ifdef XP_MAC
screen_gamma = 1.7; /*Mac : 1.7 */
#else
screen_gamma = 2.2; /*good for PC.*/
#endif
/*
if (png_get_gAMA(png_ptr, info, (double *)&png_ptr->gamma))
png_set_gamma(png_ptr, screen_gamma, png_ptr->gamma);
else
png_set_gamma(png_ptr, screen_gamma, 0.45);
*/
if(png_ptr->interlaced == PNG_INTERLACE_ADAM7)
number_passes = png_set_interlace_handling(png_ptr);
png_read_update_info(png_ptr, info);
/* Set the ic values */
png_set_dims((il_container *)png_ptr->io_ptr, png_ptr);
}
void row_callback( png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass )
{
/* this function is called for every row in the image. If the
* image is interlacing, and you turned on the interlace handler,
* this function will be called for every row in every pass.
* Some of these rows will not be changed from the previous pass.
* When the row is not changed, the new_row variable will be NULL.
* The rows and passes are called in order, so you don't really
* need the row_num and pass, but I'm supplying them because it
* may make your life easier.
*
* For the non-NULL rows of interlaced images, you must call
* png_progressive_combine_row() passing in the row and the
* old row. You can call this function for NULL rows (it will
* just return) and for non-interlaced images (it just does the
* memcpy for you) if it will make the code easier. Thus, you
* can just do this for all cases:
*/
il_container *ic = (il_container *)png_ptr->io_ptr;
if(new_row){
ic->imgdcb->ImgDCBHaveRow( 0, new_row, 0, png_ptr->width,
row_num, 1, ilErase /* ilOverlay */, png_ptr->pass );
/* il_flush_image_data(png_ptr->io_ptr); */
}
/* where old_row is what was displayed for previous rows. Note
* that the first pass (pass == 0 really) will completely cover
* the old row, so the rows do not have to be initialized. After
* the first pass (and only for interlaced images), you will have
* to pass the current row, and the function will combine the
* old row and the new row.
*/
}
void end_callback(png_structp png_ptr, png_infop info)
{
/* this function is called when the whole image has been read,
* including any chunks after the image (up to and including
* the IEND). You will usually have the same info chunk as you
* had in the header, although some data may have been added
* to the comments and time fields.
*
* Most people won't do much here, perhaps setting a flag that
* marks the image as finished.
*/
il_container *ic = (il_container *)png_ptr->io_ptr;
ic->imgdcb->ImgDCBFlushImage();
}

View File

@ -1,30 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* pngdec.h */
extern int il_png_init(il_container *ic);
extern int il_png_write(il_container *, const PRUint8 *, int32);
extern int il_png_complete(il_container *ic);
extern int il_png_abort(il_container *ic);
//extern unsigned int il_png_write_ready(il_container *ic);

View File

@ -1,85 +0,0 @@
png_get_progressive_ptr ; 327
png_do_expand_palette ; 325
png_memcpy_check ; 325
png_read_push_finish_row ; 325
png_push_process_row ; 325
png_read_filter_row ; 325
png_do_read_transformations ; 325
png_push_have_row ; 325
png_push_fill_buffer ; 39
png_read_data ; 32
png_calculate_crc ; 28
png_crc_read ; 26
png_free ; 21
png_get_uint_32 ; 15
png_malloc ; 14
png_process_some_data ; 11
png_zalloc ; 10
png_zfree ; 10
png_push_read_chunk ; 7
png_crc_error ; 6
png_crc_finish ; 6
png_reset_crc ; 6
?ImgDWrite@PNGDecoder@@UAGIPBEJ@Z ; 3
?il_png_write@@YAHPAUil_container_struct@@PBEJ@Z ; 3
png_push_read_IDAT ; 3
png_free_data ; 3
png_process_data ; 3
png_push_restore_buffer ; 3
?Release@PNGDecoder@@UAGKXZ ; 2
png_create_struct ; 2
png_process_IDAT_data ; 2
png_destroy_struct ; 2
?SetContainer@PNGDecoder@@UAGPAUil_container_struct@@PAU2@@Z ; 2
png_set_gAMA_fixed ; 2
png_set_read_fn ; 2
?ImgDWriteReady@PNGDecoder@@UAGIPAI@Z ; 2
png_set_gAMA ; 2
?AddRef@PNGDecoder@@UAGKXZ ; 2
png_info_init ; 2
png_set_cHRM_fixed ; 1
png_handle_PLTE ; 1
png_create_read_struct ; 1
png_handle_sRGB ; 1
?Create@PNGDecoder@@SGIPAVnsISupports@@ABUnsID@@PAPAX@Z ; 1
png_create_info_struct ; 1
png_get_IHDR ; 1
png_set_PLTE ; 1
?il_png_init@@YAHPAUil_container_struct@@@Z ; 1
png_info_destroy ; 1
png_get_gAMA ; 1
png_read_start_row ; 1
?QueryInterface@PNGDecoder@@UAGIABUnsID@@PAPAX@Z ; 1
png_set_error_fn ; 1
png_read_transform_info ; 1
png_get_valid ; 1
png_push_have_end ; 1
png_set_cHRM ; 1
??_GPNGDecoder@@UAEPAXI@Z ; 1
png_push_have_info ; 1
NSGetModule ; 1
png_set_gamma ; 1
png_set_progressive_read_fn ; 1
png_memset_check ; 1
?il_png_abort@@YAHPAUil_container_struct@@@Z ; 1
png_destroy_read_struct ; 1
png_read_destroy ; 1
?ImgDComplete@PNGDecoder@@UAGIXZ ; 1
?ImgDInit@PNGDecoder@@UAGIXZ ; 1
png_handle_IHDR ; 1
?ImgDAbort@PNGDecoder@@UAGIXZ ; 1
png_handle_IEND ; 1
?il_png_complete@@YAHPAUil_container_struct@@@Z ; 1
png_init_read_transformations ; 1
png_push_save_buffer ; 1
png_read_update_info ; 1
png_handle_gAMA ; 1
png_set_sRGB_gAMA_and_cHRM ; 1
png_set_sRGB ; 1
png_set_IHDR ; 1
png_set_expand ; 1
png_get_channels ; 1
png_sig_cmp ; 1
??1PNGDecoder@@UAE@XZ ; 1
png_push_read_sig ; 1
??0PNGDecoder@@QAE@PAUil_container_struct@@@Z ; 1

View File

@ -1,18 +0,0 @@
#
# This is a list of local files which get copied to the mozilla:dist:libimg directory
#
dummy_nc.h
ilErrors.h
ilIImageRenderer.h
ilINetContext.h
ilINetReader.h
ilISystemServices.h
ilIURL.h
il_icons.h
il_strm.h
il_types.h
il_util.h
libimg.h
ni_pixmp.h
xpcompat.h

View File

@ -1,55 +0,0 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = img
EXPORTS = \
il_types.h \
ni_pixmp.h \
libimg.h \
il_icons.h \
il_strm.h \
il_util.h \
ilINetContext.h \
ilIURL.h \
ilINetReader.h \
ilIImageRenderer.h \
ilISystemServices.h \
dummy_nc.h \
xpcompat.h \
ilErrors.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
include $(topsrcdir)/config/rules.mk

View File

@ -1,45 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* This is a dummy Net Context which the Image Library uses for network
operations in lieu of an MWContext. It will be replaced by a true
Net Context when the Network Library is modularized. */
#ifndef _DUMMY_NC_H
#define _DUMMY_NC_H
#include "prtypes.h"
typedef void* IL_NetContext;
PR_BEGIN_EXTERN_C
extern IL_NetContext *
IL_NewDummyNetContext(MWContext *context,
NET_ReloadMethod cache_reload_policy);
extern void
IL_DestroyDummyNetContext(IL_NetContext *net_cx);
PR_END_EXTERN_C
#endif /* _DUMMY_NC_H */

View File

@ -1,39 +0,0 @@
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
ilErrors.h - Image Library error codes.
*/
#ifndef _IL_ERRORS_H
#define _IL_ERRORS_H
/*
* Return codes
*/
#define MK_INTERRUPTED -201
#define MK_IMAGE_LOSSAGE -277
#define MK_OBJECT_NOT_IN_CACHE -239
#endif /* _IL_ERRORS_H */

View File

@ -1,183 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef ilIImageRenderer_h___
#define ilIImageRenderer_h___
#include <stdio.h>
#include "libimg.h"
#include "nsISupports.h"
// IID for the nsIImageRenderer interface
#define IL_IIMAGERENDERER_IID \
{ 0xec4e9fc0, 0xb1f3, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
/**
* Interface to be implemented by image creation and rendering
* component plugged into the image library.
*/
class ilIImageRenderer : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(IL_IIMAGERENDERER_IID);
/**
* This is the function invoked for allocating pixmap storage and
* platform-specific pixmap resources.
*
* On entry, the native color space and the original dimensions of the
* source image and its mask are initially filled in the two provided
* IL_Pixmap arguments. (If no mask or alpha channel is present, the
* second pixmap is NULL.)
*
* The width and height arguments represent the desired dimensions of the
* target image. If the implementation supports scaling, then the
* storage allocated for the IL_Pixmaps may be based on the original
* dimensions of the source image. In this case, the headers of the
* IL_Pixmap should not be modified, however, the implementation
* should be able to determine the target dimensions of the image for
* a given IL_Pixmap. (The opaque client_data pointer in the IL_Pixmap
* structure can be used to store the target image dimensions or a scale
* factor.)
*
* If the implementation does not support scaling, the supplied width
* and height must be used as the dimensions of the created pixmap storage
* and the headers within the IL_Pixmap should be side-effected to reflect
* that change.
*
* The allocator may side-effect the image and mask headers to target
* a different colorspace.
*
* The allocation function should side-effect bits, a member of the
* IL_Pixmap structure, to point to allocated storage. If there are
* insufficient resources to allocate both the image and mask, neither
* should be allocated. (The bits pointers, initially NULL-valued,
* should not be altered.)
*/
NS_IMETHOD NewPixmap(void* aDisplayContext,
PRInt32 aWidth, PRInt32 aHeight,
IL_Pixmap* aImage, IL_Pixmap* aMask)=0;
/**
* Inform the implementation that the specified rectangular portion of
* the pixmap has been modified. This might be used, for example, to
* transfer the altered area to the X server on a unix client.
*
* x_offset and y_offset are measured in pixels, with the
* upper-left-hand corner of the pixmap as the origin, increasing
* left-to-right, top-to-bottom.
*/
NS_IMETHOD UpdatePixmap(void* aDisplayContext,
IL_Pixmap* aImage,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight)=0;
/**
* Inform the implementation that the specified rectangular portion
* of the destination image has been decoded. Currently the origin
* of the decoded image is always at 0,0. The implementation doesn't
* assume this. See libimg/src/scale.cpp, ~line 214 for the current
* decoded image.
*/
NS_IMETHOD SetDecodedRect(IL_Pixmap* aImage, PRInt32 x1, PRInt32 y1,
PRInt32 x2, PRInt32 y2)=0;
/**
* Informs the callee that the imagelib has acquired or relinquished
* control over the IL_Pixmap's bits. The message argument should be
* one of IL_LOCK_BITS, IL_UNLOCK_BITS or IL_RELEASE_BITS.
*
* The imagelib will issue an IL_LOCK_BITS message whenever it wishes to
* alter the bits. When the imaglib has finished altering the bits, it will
* issue an IL_UNLOCK_BITS message. These messages are provided so that
* the callee may perform memory-management tasks during the time that
* the imagelib is not writing to the pixmap's buffer.
*
* Once the imagelib is sure that it will not modify the pixmap any further
* and, therefore, will no longer dereference the bits pointer in the
* IL_Pixmap, it will issue an IL_RELEASE_BITS request. (Requests may still
* be made to display the pixmap, however, using whatever opaque pixmap
* storage the callee may retain.) The IL_RELEASE_BITS message
* could be used, for example, by an X11 front-end to free the client-side
* image data, preserving only the server pixmap.
*/
NS_IMETHOD ControlPixmapBits(void* aDisplayContext,
IL_Pixmap* aImage, PRUint32 aControlMsg)=0;
/**
* Release the memory storage and other resources associated with an image
* pixmap; the pixmap will never be referenced again. The pixmap's header
* information and the IL_Pixmap structure itself will be freed by the Image
* Library.
*/
NS_IMETHOD DestroyPixmap(void* aDisplayContext, IL_Pixmap* aImage)=0;
/**
* Render a rectangular portion of the given pixmap.
*
* Render the image using transparency if mask is non-NULL.
* x and y are measured in pixels and are in document coordinates.
* x_offset and y_offset are with respect to the image origin.
*
* If the width and height values would otherwise cause the sub-image
* to extend off the edge of the source image, the function should
* perform tiling of the source image. This is used to draw document,
* layer and table cell backdrops. (Note: it is assumed this case will
* apply only to images which do not require any scaling.)
*
* All coordinates are in terms of the target pixmap dimensions, which
* may differ from those of the pixmap storage if the callee
* supports scaling.
*/
NS_IMETHOD DisplayPixmap(void* aDisplayContext,
IL_Pixmap* aImage, IL_Pixmap* aMask,
PRInt32 aX, PRInt32 aY,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight)=0;
/**
* <bold>(Probably temporary and subject to change).</bold>
* Display an icon. x and y are in document coordinates.
*/
NS_IMETHOD DisplayIcon(void* aDisplayContext,
PRInt32 aX, PRInt32 aY, PRUint32 aIconNumber)=0;
/**
* Sets image's natural dimensions in nsImage for use by editor and FE.
*/
NS_IMETHOD SetImageNaturalDimensions(IL_Pixmap* aImage,
PRInt32 naturalwidth, PRInt32 naturalheight)=0;
/**
* <bold>(Probably temporary and subject to change).</bold>
* This method should fill in the targets of the width and
* height pointers to indicate icon dimensions
*/
NS_IMETHOD GetIconDimensions(void* aDisplayContext,
PRInt32 *aWidthPtr, PRInt32 *aHeightPtr,
PRUint32 aIconNumber)=0;
};
#endif

View File

@ -1,69 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef ilINetContext_h___
#define ilINetContext_h___
#include <stdio.h>
#include "nsISupports.h"
// IID for the ilINetContext interface
#define IL_INETCONTEXT_IID \
{ 0x425da760, 0xb412, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class ilIURL;
class ilINetReader;
class ilINetContext : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(IL_INETCONTEXT_IID)
virtual ilINetContext* Clone()=0;
virtual ImgCachePolicy GetReloadPolicy()=0;
virtual void AddReferer(ilIURL *aUrl)=0;
virtual void Interrupt()=0;
virtual ilIURL* CreateURL(const char *aUrl,
ImgCachePolicy aReloadMethod)=0;
virtual PRBool IsLocalFileURL(char *aAddress)=0;
#ifdef NU_CACHE
virtual PRBool IsURLInCache(ilIURL* iUrl)=0;
#else
virtual PRBool IsURLInMemCache(ilIURL *aUrl)=0;
virtual PRBool IsURLInDiskCache(ilIURL *aUrl)=0;
#endif /* NU_CACHE */
virtual int GetURL (ilIURL * aUrl, ImgCachePolicy aLoadMethod,
ilINetReader *aReader, PRBool IsAnimationLoop)=0;
virtual int GetContentLength (ilIURL * aUrl)=0;
};
#endif

View File

@ -1,63 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef ilINetReader_h___
#define ilINetReader_h___
#include <stdio.h>
#include "nsISupports.h"
// IID for the ilINetReader interface
#define IL_INETREADER_IID \
{ 0xbe324220, 0xb416, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class ilIURL;
class ilINetReader : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(IL_INETREADER_IID);
NS_IMETHOD WriteReady(PRUint32 *max_read)=0;
NS_IMETHOD FirstWrite(const unsigned char *str, int32 len, char* url)=0;
NS_IMETHOD Write(const unsigned char *str, int32 len)=0;
NS_IMETHOD StreamAbort(int status)=0;
NS_IMETHOD StreamComplete(PRBool is_multipart)=0;
NS_IMETHOD NetRequestDone(ilIURL *urls, int status)=0;
virtual PRBool StreamCreated(ilIURL *urls, char* type)=0;
virtual PRBool IsMulti()=0;
NS_IMETHOD FlushImgBuffer()=0;
};
#endif

View File

@ -1,47 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef ilISystemServices_h___
#define ilISystemServices_h___
#include <stdio.h>
#include "nsISupports.h"
// IID for the ilISystemServices interface
#define IL_ISYSTEMSERVICES_IID \
{ 0xc14659e0, 0xb9fe, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
typedef void (*ilTimeoutCallbackFunction) (void * closure);
class ilISystemServices : public nsISupports {
public:
NS_DEFINE_STATIC_IID_ACCESSOR(IL_ISYSTEMSERVICES_IID)
virtual void * SetTimeout(ilTimeoutCallbackFunction aFunc,
void * aClosure, PRUint32 aMsecs)=0;
virtual void ClearTimeout(void *aTimerID)=0;
};
#endif

View File

@ -1,56 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef ilIURL_h___
#define ilIURL_h___
#include <stdio.h>
#include "nsISupports.h"
// IID for the ilIURL interface
#define IL_IURL_IID \
{ 0x6d7a5600, 0xb412, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
class ilIURL : public nsISupports {
public:
virtual void SetReader(ilINetReader *aReader)=0;
virtual ilINetReader *GetReader()=0;
virtual int GetContentLength()=0;
virtual char* GetAddress()=0;
virtual time_t GetExpires()=0;
virtual PRBool GetBackgroundLoad()=0;
virtual void SetBackgroundLoad(PRBool aBgload)=0;
virtual int GetOwnerId()=0;
virtual void SetOwnerId(int)=0;
};
#endif

View File

@ -1,108 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_icons.h --- Image icon enumeration.
* $Id: il_icons.h,v 3.4 2001-06-19 08:46:23 pavlov%netscape.com Exp $
*/
#ifndef _IL_ICONS_H_
#define _IL_ICONS_H_
/* Fixed image icons */
#define IL_IMAGE_FIRST 0x11
#define IL_IMAGE_DELAYED 0x11
#define IL_IMAGE_NOT_FOUND 0x12
#define IL_IMAGE_BAD_DATA 0x13
#define IL_IMAGE_INSECURE 0x14
#define IL_IMAGE_EMBED 0x15
#define IL_IMAGE_LAST 0x15
#define IL_NEWS_FIRST 0x21
#define IL_NEWS_CATCHUP 0x21
#define IL_NEWS_CATCHUP_THREAD 0x22
#define IL_NEWS_FOLLOWUP 0x23
#define IL_NEWS_GOTO_NEWSRC 0x24
#define IL_NEWS_NEXT_ART 0x25
#define IL_NEWS_NEXT_ART_GREY 0x26
#define IL_NEWS_NEXT_THREAD 0x27
#define IL_NEWS_NEXT_THREAD_GREY 0x28
#define IL_NEWS_POST 0x29
#define IL_NEWS_PREV_ART 0x2A
#define IL_NEWS_PREV_ART_GREY 0x2B
#define IL_NEWS_PREV_THREAD 0x2C
#define IL_NEWS_PREV_THREAD_GREY 0x2D
#define IL_NEWS_REPLY 0x2E
#define IL_NEWS_RTN_TO_GROUP 0x2F
#define IL_NEWS_SHOW_ALL_ARTICLES 0x30
#define IL_NEWS_SHOW_UNREAD_ARTICLES 0x31
#define IL_NEWS_SUBSCRIBE 0x32
#define IL_NEWS_UNSUBSCRIBE 0x33
#define IL_NEWS_FILE 0x34
#define IL_NEWS_FOLDER 0x35
#define IL_NEWS_FOLLOWUP_AND_REPLY 0x36
#define IL_NEWS_LAST 0x36
#define IL_GOPHER_FIRST 0x41
#define IL_GOPHER_TEXT 0x41
#define IL_GOPHER_IMAGE 0x42
#define IL_GOPHER_BINARY 0x43
#define IL_GOPHER_SOUND 0x44
#define IL_GOPHER_MOVIE 0x45
#define IL_GOPHER_FOLDER 0x46
#define IL_GOPHER_SEARCHABLE 0x47
#define IL_GOPHER_TELNET 0x48
#define IL_GOPHER_UNKNOWN 0x49
#define IL_GOPHER_LAST 0x49
#define IL_EDIT_FIRST 0x60
#define IL_EDIT_NAMED_ANCHOR 0x61
#define IL_EDIT_FORM_ELEMENT 0x62
#define IL_EDIT_UNSUPPORTED_TAG 0x63
#define IL_EDIT_UNSUPPORTED_END_TAG 0x64
#define IL_EDIT_JAVA 0x65
#define IL_EDIT_PLUGIN 0x66
#define IL_EDIT_LAST 0x66
/* Security Advisor and S/MIME icons */
#define IL_SA_FIRST 0x70
#define IL_SA_SIGNED 0x71
#define IL_SA_ENCRYPTED 0x72
#define IL_SA_NONENCRYPTED 0x73
#define IL_SA_SIGNED_BAD 0x74
#define IL_SA_ENCRYPTED_BAD 0x75
#define IL_SMIME_ATTACHED 0x76
#define IL_SMIME_SIGNED 0x77
#define IL_SMIME_ENCRYPTED 0x78
#define IL_SMIME_ENC_SIGNED 0x79
#define IL_SMIME_SIGNED_BAD 0x7A
#define IL_SMIME_ENCRYPTED_BAD 0x7B
#define IL_SMIME_ENC_SIGNED_BAD 0x7C
#define IL_SA_LAST 0x7C
#define IL_MSG_FIRST 0x80
#define IL_MSG_ATTACH 0x80
#define IL_MSG_LAST 0x80
#endif /* _IL_ICONS_H_ */

View File

@ -1,49 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_strm.h --- Stream converters for the image library.
* $Id: il_strm.h,v 3.6 2001-06-19 08:46:24 pavlov%netscape.com Exp $
*/
/******************** Identifiers for standard image types. ******************/
#define IL_UNKNOWN 0
#define IL_GIF 1
#define IL_XBM 2
#define IL_JPEG 3
#define IL_PPM 4
#define IL_PNG 5
#define IL_ART 6
#define IL_NOTFOUND 256
/********************** Opaque reference to MWContext. ***********************/
#ifdef IL_INTERNAL /* If used within the Image Library. */
#define OPAQUE_CONTEXT void
#else
#define OPAQUE_CONTEXT MWContext /* The old MWContext. */
#endif /* IL_INTERNAL */

View File

@ -1,301 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_types.h --- Image library data types and structures.
* $Id: il_types.h,v 3.7 2001-06-19 08:46:25 pavlov%netscape.com Exp $
*/
#ifndef _IL_TYPES_H_
#define _IL_TYPES_H_
#include "prtypes.h"
#define IL_EXTERN(__type) PR_EXTERN(__type)
#define IL_IMPLEMENT(__type) PR_IMPLEMENT(__type)
/************************** Notes ********************************************
* 1. Required #defines:
* IL_CLIENT - This should only be defined by clients of the Image Library.
* IL_INTERNAL - Defined only by the Image Library.
*
* 2. The Image Library clients and display front ends should only use types
* with an IL_ prefix, instead of the equivalent types with an NI_ prefix.
* The NI_ prefix will be used by Image Plugins.
******************************************************************************/
/************************** Miscellaneous Data Types *************************/
/* Flags to be passed into IL_GetImage. */
#define IL_HIGH_PRIORITY 0x01 /* For important images, like backdrops. */
#define IL_STICKY 0x02 /* Don't throw this image out of cache. */
#define IL_BYPASS_CACHE 0x04 /* Don't get image out of image cache. */
#define IL_ONLY_FROM_CACHE 0x08 /* Don't load if image cache misses. */
typedef enum
{
USE_IMG_CACHE, /* use imgcache */
DONT_USE_IMG_CACHE, /* dont use imgcache AND if found in imgcache delete entry */
SYNTH_IMGDOC_NEEDS_IMG_CACHE /* needed for view-image/image doc */
} ImgCachePolicy;
/* A rectangle structure. */
typedef struct _IL_Rect {
PRUint16 x_origin;
PRUint16 y_origin;
PRUint16 width;
PRUint16 height;
} IL_Rect;
/* Pixmap control messages issued by the imagelib to indicate that it
has acquired or relinquished control over a IL_Pixmap's bits. */
typedef enum {
IL_LOCK_BITS, /* Issued prior to modifying the bits. */
IL_UNLOCK_BITS, /* Issued after modifying the bits. */
IL_RELEASE_BITS /* Issued once the bits will no longer
be modified or accessed by the imagelib. */
} IL_PixmapControl;
/*********** Cross Platform Pixmaps and Colorspace Information ***************/
/* The IL_Pixmap data structure is a cross-platform representation of a
pixmap, which contains information about the dimensions, colorspace and
bits of an image. The IL_Pixmap structure is exported to the various
Front Ends through the header file ni_pixmap.h, and it will also be
exported to image decoder plugins, when they become available. */
#ifdef IL_CLIENT
typedef void IL_Pixmap; /* Cross platform pixmap. */
typedef void IL_ColorSpace; /* Colorspace. */
/* An indexed RGB triplet. */
typedef struct _IL_IRGB {
PRUint8 index;
PRUint8 red, green, blue;
} IL_IRGB;
/* A RGB triplet representing a single pixel in the image's colormap
(if present.) */
typedef struct _IL_RGB
{
PRUint8 red, green, blue, pad; /* Windows requires the fourth byte &
many compilers pad it anyway. */
PRUint16 hist_count; /* Histogram frequency count. */
} IL_RGB;
#else /* Image Library and Front Ends. */
#include "ni_pixmp.h"
typedef NI_Pixmap IL_Pixmap;
typedef NI_ColorMap IL_ColorMap;
typedef NI_ColorSpace IL_ColorSpace;
typedef NI_RGBBits IL_RGBBits; /* RGB bit allocation. */
typedef NI_IRGB IL_IRGB;
typedef NI_RGB IL_RGB;
#endif /* IL_CLIENT */
/*********************** Image Contexts and Handles **************************/
#ifndef IL_INTERNAL
/* A temporary placeholder for a cross-platform representation of
shared netlib state to be passed to netlib functions. This will
actually be defined by netlib in some other header file. */
/* typedef void NetGpCxt;*/
/* An opaque handle to an instance of a single image request, passed
as the return value of IL_GetImage(). Although multiple requests
for the same URL may be coalesced within the image library, a
unique IL_ImageReq handle is still generated for every request. */
typedef void IL_ImageReq;
/* An opaque handle to shared image state and callback functions.
Image library API functions are provided to perform certain
operations on all IL_ImageReq's that share the same IL_GroupContext.
The expectation is that many images will share a single
IL_GroupContext, i.e. all the images in a document or window. */
typedef void IL_GroupContext;
#endif /* IL_INTERNAL */
/*********************** Image Observer Notification *************************
* - for observers of an IL_ImageReq.
******************************************************************************/
/* Possible image observer notification messages. */
enum {
IL_START_URL, /* Start of decode/display for URL. */
IL_DESCRIPTION, /* Availability of image description. */
IL_DIMENSIONS, /* Availability of image dimensions. */
IL_IS_TRANSPARENT, /* Is this image transparent. */
IL_PIXMAP_UPDATE, /* Change in a rectangular area of pixels. */
IL_FRAME_COMPLETE, /* Completion of a frame of an animated
image.*/
IL_PROGRESS, /* Notification of percentage decoded. */
IL_IMAGE_COMPLETE, /* Completion of image decoding. There
may be multiple instances of this
event per URL due to server push,
client pull or looping GIF animation. */
IL_STOP_URL, /* Completion of decode/display for URL. */
IL_IMAGE_DESTROYED, /* Finalization of an image request. This
is an indication to remove observers from
the observer list and to perform any
observer related cleanup. */
IL_ABORTED, /* Image decode was aborted by either
netlib or IL_InterruptContext(). */
IL_NOT_IN_CACHE, /* Image URL not available in cache when
IL_ONLY_FROM_CACHE flag was set. */
IL_ERROR_NO_DATA, /* Netlib unable to fetch provided URL. */
IL_ERROR_IMAGE_DATA_CORRUPT, /* Checksum error of some kind in image
data. */
IL_ERROR_IMAGE_DATA_TRUNCATED, /* Missing data at end of stream. */
IL_ERROR_IMAGE_DATA_ILLEGAL, /* Generic image data error. */
IL_INTERNAL_IMAGE, /* Internal image icon. */
IL_ERROR_INTERNAL /* Internal Image Library error. */
};
/* Message data passed to the client-provided image observer callbacks. */
typedef struct {
void *display_context; /* The Front End display context associated
with the image group context. */
IL_ImageReq *image_instance; /* The image being observed. */
/* Data for IL_DESCRIPTION message. */
char *description; /* Human readable description of an image, e.g.
"GIF89a 320 x 240 pixels". The string
storage is static, so it must be copied if
it is to be preserved after the call to the
observer. The intention is that this can be
used to title a document window. */
/* Data for IL_PIXMAP_UPDATE message. */
IL_Rect update_rect; /* A rectangular area of pixels which has been
modified by the image library. This
notification enables the client to drive
the display via an immediate or deferred
call to IL_DisplaySubImage. */
/* Data for IL_PROGRESS message. */
int percent_progress; /* Estimated percentage decoded. This
notification occurs at unspecified
intervals. Provided that decoding proceeds
without error, it is guaranteed that
notification will take place on completion
with a percent_progress value of 100. */
/* Data for IL_DIMENSIONS message. */
PRUint16 width; /* Image width. */
PRUint16 height; /* Image height. */
/* Data for IL_INTERNAL_IMAGE message, or for error messages which require
an icon to be displayed: IL_ERROR_NO_DATA, IL_ERROR_IMAGE_DATA_CORRUPT,
IL_ERROR_IMAGE_DATA_TRUNCATED, IL_ERROR_IMAGE_DATA_ILLEGAL or
IL_ERROR_INTERNAL. */
PRUint16 icon_width; /* Icon width. */
PRUint16 icon_height; /* Icon height. */
int32 icon_number; /* Icon number. */
} IL_MessageData;
/************************* Image Group Observer Notification *****************
* - for observers of an IL_GroupContext.
******************************************************************************/
/* Possible image group observer notification messages. Note: animations are
considered to have loaded at the end of the first iteration. A looping
animation is one which is on its second or a subsequent iteration. */
enum {
IL_STARTED_LOADING, /* Start of image loading. Sent when a loading
image is added to an image group which
currently has no loading images. */
IL_ABORTED_LOADING, /* Some images were aborted. A finished
loading message will not be sent until the
aborted images have been destroyed. */
IL_FINISHED_LOADING, /* End of image loading. Sent when the last
of the images currently in the image group
has finished loading. */
IL_STARTED_LOOPING, /* Start of image looping. Sent when an
animated image starts looping in an image
group which currently has no looping
animations. */
IL_FINISHED_LOOPING /* End of image looping. Sent when the last
of the images currently in the image group
has finished looping. */
};
/* Message data passed to the client-provided image group observer
callbacks. */
typedef struct {
void *display_context; /* The Front End display context associated
with the image group context. */
IL_GroupContext *image_context; /* The image group context being
observed. */
} IL_GroupMessageData;
/************************** Display Preferences ******************************/
/* Flags to be passed into IL_SetDisplayMode. */
#define IL_DISPLAY_CONTEXT 0x01
#define IL_DISPLAY_TYPE 0x02
#define IL_COLOR_SPACE 0x04
#define IL_PROGRESSIVE_DISPLAY 0x08
#define IL_DITHER_MODE 0x10
/* The display type. */
typedef enum {
IL_Console = 0,
IL_Printer = 1,
IL_PostScript = 2,
IL_MetaFile = 3
} IL_DisplayType;
/* Dithering preference. */
typedef enum IL_DitherMode {
IL_ClosestColor = 0,
IL_Dither = 1,
IL_Auto = 2
} IL_DitherMode;
/* Data for setting the display mode. */
typedef struct {
void *display_context; /* The FE's display context. */
IL_DisplayType display_type; /* IL_Console, IL_Printer, IL_PostScript, or
IL_MetaFile. */
IL_ColorSpace *color_space; /* Display colorspace. */
PRBool progressive_display; /* Toggle for progressive image display. */
IL_DitherMode dither_mode; /* IL_ClosestColor, IL_Dither or IL_Auto. */
} IL_DisplayData;
#endif /* _IL_TYPES_H_ */

View File

@ -1,137 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_util.h Colormap and colorspace utilities.
*
* $Id: il_util.h,v 3.6 2001-06-19 08:46:27 pavlov%netscape.com Exp $
*/
#ifndef _IL_UTIL_H
#define _IL_UTIL_H
#include "ni_pixmp.h" /* Cross-platform pixmap structure. */
#include "il_types.h"
XP_BEGIN_PROTOS
/************************* Colormap utilities ********************************/
/* Create a new color map consisting of a given set of reserved colors, and
a color cube. num_colors represents the requested size of the colormap,
including the reserved colors. The actual number of colors in the colormap
could be less depending on the color cube that is allocated.
The Image Library will only make use of entries in the color cube. This
function represents the current state of affairs, and it will eventually
be replaced when the Image Library has the capability to dither to an
arbitrary palette. */
IL_EXTERN(IL_ColorMap *)
IL_NewCubeColorMap(IL_RGB *reserved_colors, PRUint16 num_reserved_colors,
PRUint16 num_colors);
/* Create an optimal fixed palette of the specified size, starting with
the given set of reserved colors.
XXX - This will not be implemented initially. */
IL_EXTERN(IL_ColorMap *)
IL_NewOptimalColorMap(IL_RGB *reserved_colors, PRUint16 num_reserved_colors,
PRUint16 num_colors);
/* Create an empty colormap. The caller is responsible for filling in the
colormap entries. */
IL_EXTERN(IL_ColorMap *)
IL_NewColorMap(void);
/* Append the specified color to an existing IL_ColorMap, returning TRUE if
successful. The position of the new color in the IL_ColorMap's map array
is returned in new_color->index. The caller should also update the
corresponding entry in the IL_ColorMap's index array,
cmap->index[new_color->index], if the actual colormap indices do not
correspond to the order of the entries in the map array.
Note: For now, at least, this function does not cause the Image Library's
lookup table to be altered, so the Image Library will continue to dither
to the old colormap. Therefore, the current purpose of this function is
to add colors (such as a background color for transparent images) which
are not a part of the Image Library's color cube. */
IL_EXTERN(int)
IL_AddColorToColorMap(IL_ColorMap *cmap, IL_IRGB *new_color);
/* Free all memory associated with a given colormap.
Note: This should *not* be used to destroy a colormap once it has been
passed into IL_CreatePseudoColorSpace. Use IL_ReleaseColorSpace instead. */
IL_EXTERN(void)
IL_DestroyColorMap (IL_ColorMap *cmap);
/* Reorder the entries in a colormap. new_order is an array mapping the old
indices to the new indices.
XXX Is this really necessary? */
IL_EXTERN(void)
IL_ReorderColorMap(IL_ColorMap *cmap, PRUint16 *new_order);
/************************** Colorspace utilities *****************************/
/* Create a new True-colorspace of the dimensions specified by IL_RGBBits and
set the reference count to 1. The pixmap_depth is the sum of the bits
assigned to the three color channels, plus any additional allowance that
might be necessary, e.g. for an alpha channel, or for alignment. Note: the
contents of the IL_RGBBits structure will be copied, so they need not be
preserved after the call to IL_CreateTrueColorSpace. */
IL_EXTERN(IL_ColorSpace *)
IL_CreateTrueColorSpace(IL_RGBBits *rgb, PRUint8 pixmap_depth);
/* Create a new Pseudo-colorspace using the given colormap and set the
reference count to 1. The index_depth is the bit-depth of the colormap
indices (typically 8), while the pixmap_depth is the index_depth plus any
additional allowance that might be necessary e.g. for an alpha channel, or
for alignment. Note: IL_ColorMaps passed into IL_CreatePseudoColorSpace
become a part of the IL_ColorSpace structure. The IL_ColorMap pointer is
invalid after the the call to IL_CreatePseudoColorSpace, so it should
neither be accessed, nor destroyed using IL_DestroyColorMap. Access to
the colormap, *is* available through the colormap member of the
IL_ColorSpace. Memory associated with the colormap will be freed by
IL_ReleaseColorSpace when the reference count reaches zero. */
IL_EXTERN(IL_ColorSpace *)
IL_CreatePseudoColorSpace(IL_ColorMap *cmap, PRUint8 index_depth,
PRUint8 pixmap_depth);
/* Create a new Greyscale-colorspace of depth specified by index_depth and
set the reference count to 1. The pixmap_depth is the index_depth plus
any additional allowance that might be necessary e.g. for an alpha channel,
or for alignment. */
IL_EXTERN(PRBool)
IL_CreateGreyScaleColorSpace(PRUint8 index_depth, PRUint8 pixmap_depth, IL_ColorSpace **color_space);
/* Decrements the reference count for an IL_ColorSpace. If the reference
count reaches zero, all memory associated with the colorspace (including
any colormap associated memory) will be freed. */
IL_EXTERN(void)
IL_ReleaseColorSpace(IL_ColorSpace *color_space);
/* Increment the reference count for an IL_ColorSpace. */
IL_EXTERN(void)
IL_AddRefToColorSpace(IL_ColorSpace *color_space);
XP_END_PROTOS
#endif /* _IL_UTIL_H */

View File

@ -1,325 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* libimg.h --- API calls to the Image Library.
* $Id: libimg.h,v 3.10 2001-06-19 08:46:28 pavlov%netscape.com Exp $
*/
#ifndef _LIBIMG_H
#define _LIBIMG_H
#include "prtypes.h"
#include "il_types.h"
#if 0
#include "dummy_nc.h"
#endif
#include "ilISystemServices.h"
#include "ilIImageRenderer.h"
#include "nsIImageObserver.h"
/*********************** Observers and Observables ***************************/
/* This is the cross-platform observer mechanism. The image library's client
should create an XP_ObserverList, and pass it into IL_GetImage(). This
observer list represents the set of client-provided callbacks to be
associated with the IL_ImageReq handle returned by IL_GetImage. Callbacks
will be invoked with an appropriate message, whenever the image library
wishes to notify its clients of the availability of information about the
image or other important changes in the image. The observer list's
XP_Observable will be set by IL_GetImage, so the XP_ObserverList should be
created with a NULL observable. */
#include "xp_obs.h"
/**************************** Initialization *********************************/
PR_BEGIN_EXTERN_C
/* One-time image library initialization.
- Initialize internal state.
- Scan image plug-in directory.
- Register individual image decoders with the netlib. */
IL_EXTERN(int)
IL_Init(ilISystemServices *ss);
/* Used when exiting the client, this code frees all imagelib data structures.
This is done for two reasons:
- It makes leakage analysis of the heap easier.
- It causes resources to be freed on 16-bit Windows that would otherwise
persist beyond the program's lifetime. */
IL_EXTERN(void)
IL_Shutdown(void);
/********************** Image Group Contexts *********************************/
/* Create an IL_GroupContext, which represents an aggregation of state
for one or more images and which contains an interface to access
external service functions and callbacks. IL_NewGroupContext will use
the IMGCBIF_AddRef callback to increment the reference count for the
interface.
The display_context argument is opaque to the image library and is
passed back to all of the callbacks in IMGCBIF interface. */
IL_EXTERN(IL_GroupContext *)
IL_NewGroupContext(void *display_context,
ilIImageRenderer *image_render);
/* Free an image context. IL_DestroyGroupContext will make a call
to the IMGCBIF_Release callback function of the JMC interface prior to
releasing the IL_GroupContext structure. The IMGCBIF_Release callback
is expected to decrement the reference count for the IMGCBIF interface,
and to free the callback vtable and the interface structure if the
reference count is zero. */
IL_EXTERN(void)
IL_DestroyGroupContext(IL_GroupContext *image_context);
/* Add an observer/closure pair to an image group context's observer list.
Returns PR_TRUE if the observer is successfully registered. */
IL_EXTERN(PRBool)
IL_AddGroupObserver(IL_GroupContext *img_cx, XP_ObserverProc observer,
void *closure);
/* Remove an observer/closure pair from an image group context's observer
list. Returns PR_TRUE if successful. */
IL_EXTERN(PRBool)
IL_RemoveGroupObserver(IL_GroupContext *img_cx, XP_ObserverProc observer,
void *closure);
/************************* Primary API functions *****************************/
/* This is the primary entry point to the imagelib, used to map from a
URL to a pixmap, fetching and decoding as necessary.
The width and height parameters specify the target dimensions of
the image. The image will be stretched horizontally, vertically or
both to meet these parameters. If both width and height are zero,
the image is decoded using its "natural" size. If only one of
width and height is zero, the image is scaled to the provided
dimension, with the unspecified dimension scaled to maintain the
image's original aspect ratio.
If background_color is NULL, a separate mask pixmap will be
constructed for any transparent images. If background_color is
non-NULL, it indicates the RGB value to be painted into the image
for "transparent" areas of the image, in which case no mask is
created. This is intended for backdrops and printing.
The observable is an opaque pointer that is passed back to observer
callback functions.
The following flags may be set when calling IL_GetImage:
- IL_HIGH_PRIORITY - For important images, like backdrops.
- IL_STICKY - Don't throw this image out of cache.
- IL_BYPASS_CACHE - Don't get image out of image cache.
- IL_ONLY_FROM_CACHE - Don't load if image cache misses.
The net_group_context is passed back to netlib functions. It must
encapsulate the notion of disk cache reload policy which, in
previous incarnations of this function, was passed in explicitly.
There is also an assumption being made here that there is some way to
create a Net Context from this Net Group Context in which Navigator UI
(animation, status, progress, etc.) can be suppressed.*/
IL_EXTERN(IL_ImageReq *)
IL_GetImage(const char* url,
IL_GroupContext *image_context,
XP_ObserverList observer_list,
IL_IRGB *background_color,
PRUint32 width, PRUint32 height,
PRUint32 flags,
void *net_context,
nsIImageRequestObserver * aObserver);
/* Release a reference to an image lib request. If there are no other
clients of the request's associated pixmap, any related netlib
activity is terminated and pixmap storage may be reclaimed. */
IL_EXTERN(void)
IL_DestroyImage (IL_ImageReq *image_req);
/* XXX - This is a new API call to reload all images associated with a
given IL_GroupContext. The purpose of this call is to allow all images
in a document to be reloaded and redecoded to a different bit depth based
on memory considerations. This process involves the destruction of the
old IL_Pixmap structures and the allocation of new structures corresponding
to the new bit depth. */
IL_EXTERN(void)
IL_ReloadImages(IL_GroupContext *image_context, void *net_context);
/* Halt decoding of images or animation without destroying associated
pixmap data. This may abort any associated netlib streams. All
IL_ImageReq's created with the given IL_GroupContext are interrupted. */
IL_EXTERN(void)
IL_InterruptContext(IL_GroupContext *image_context);
/* Halt decoding or animation of a specific image request without
destroying associated pixmap data. */
IL_EXTERN(void)
IL_InterruptRequest(IL_ImageReq *image_req);
/* Display a rectangular portion of an image. x and y refer to the top left
corner of the image, measured in pixels, with respect to the document
origin. x_offset and y_offset are measured in pixels, with the
upper-left-hand corner of the pixmap as the origin, increasing
left-to-right, top-to-bottom.
If the width and height values would otherwise cause the sub-image
to extend off the edge of the source image, the function should
perform tiling of the source image. This is used to draw document,
layer and table cell backdrops. (Note: it is assumed this case will
apply only to images which do not require any scaling.)
If at any time the image library determines that an image request cannot
be fulfilled or that the image has been delayed, it will notify the client
synchronously through the observer mechanism. The client may then choose to
request that an icon be drawn instead by making a call to IL_DisplayIcon. */
IL_EXTERN(void)
IL_DisplaySubImage(IL_ImageReq *image_req, int x, int y, int x_offset,
int y_offset, int width, int height);
/* Display an icon. x and y refer to the top left corner of the icon, measured
in pixels, with respect to the document origin. */
IL_EXTERN(void)
IL_DisplayIcon(IL_GroupContext *img_cx, int icon_number, int x, int y);
/* Return the dimensions of an icon. */
IL_EXTERN(void)
IL_GetIconDimensions(IL_GroupContext *img_cx, int icon_number, int *width,
int *height);
/********************* Pixmap access functions *******************************/
/* Return the image IL_Pixmap associated with an image request. */
IL_EXTERN(IL_Pixmap *)
IL_GetImagePixmap(IL_ImageReq *image_req);
/* Return the mask IL_Pixmap associated with an image request. */
IL_EXTERN(IL_Pixmap *)
IL_GetMaskPixmap(IL_ImageReq *image_req);
/********************* Image query functions *******************************/
/* Return the natural dimensions of the image. Returns 0,0 if the dimensions
are unknown. */
IL_EXTERN(void)
IL_GetNaturalDimensions(IL_ImageReq *image_req, int *width, int *height);
/*********************** Per-context Preferences and Settings ****************/
/* Instruct the Image Library how to render images to the Display Front End.
The display_flags argument indicates which display settings are to be
affected. Flags which may be set include:
- IL_DISPLAY_CONTEXT - Set the display context. Must be compatible with
the one used to create the IL_GroupContext.
- IL_DISPLAY_TYPE - Set the display type.
- IL_COLOR_SPACE - Set the display colorspace.
- IL_PROGRESSIVE_DISPLAY - Turn progressive display on or off.
- IL_DITHER_MODE - Set dither mode.
The display_data argument provides the required data for the new settings.
- display_context - An opaque pointer to the FE's display context.
- display_type - IL_Console, IL_Printer, IL_PostScript or
IL_MetaFile.
- color_space - A pointer to the Display FE's colorspace.
- progressive_display - Toggle for progressive image display.
- dither_mode - IL_ClosestColor, IL_Dither or IL_Auto. */
IL_EXTERN(void)
IL_SetDisplayMode(IL_GroupContext *image_context, PRUint32 display_flags,
IL_DisplayData *display_data);
/************************ Image format identification ************************/
/* Determine the type of the image, based on the first few bytes of data. */
IL_EXTERN(int)
IL_Type(const char *buf, int32 len);
/************************ Global imagelib settings ***************************/
/* Set limit on approximate size, in bytes, of all pixmap storage used by the
Image Library. */
IL_EXTERN(void)
IL_SetCacheSize(PRUint32 new_size);
/************************ Memory management **********************************/
/* Free num_bytes of memory by flushing the Least Recently Used (LRU) images
from the image cache. */
IL_EXTERN(void)
IL_FreeMemory(IL_GroupContext *image_context, PRUint32 num_bytes);
/********************** Mac-specific memory-management ***********************/
/* Attempt to release the memory used by a specific image in the image
cache. The memory won't be released if the image is still in use
by one or more clients. XXX - Can we get rid of this call ? Why
the hell do we need this ? */
IL_EXTERN(void)
IL_UnCache(IL_Pixmap *pixmap);
/* Attempts to release some memory by freeing an image from the image
cache. This may not always be possible either because all images
in the cache are in use or because the cache is empty. Returns the
new approximate size of the imagelib cache. */
IL_EXTERN(PRUint32)
IL_ShrinkCache(void);
/* Remove as many images as possible from the image cache. The only
images not removed are those that are in use. */
IL_EXTERN(void)
IL_FlushCache(PRUint8 img_catagory);
/* Return the approximate storage consumed by the imagelib cache, in bytes */
IL_EXTERN(PRUint32)
IL_GetCacheSize(void);
/************************ Miscellaneous garbage ******************************/
/* Returns a pointer to a string containing HTML appropriate for displaying
in a DocInfo window. The caller may dispose of the string using XP_FREE. */
IL_EXTERN(char *)
IL_HTMLImageInfo(char *url_address);
/* This is a legacy "safety-valve" routine, called each time a new HTML page
is loaded. It causes remaining references to images in the given group
context to be freed, i.e. like calling IL_DestroyImage on each of them.
This is primarily required because layout sometimes leaks images, and it
should go away when we can fix layout. */
IL_EXTERN(void)
IL_DestroyImageGroup(IL_GroupContext *image_context);
PR_END_EXTERN_C
#endif /* _LIBIMG_H */

View File

@ -1,62 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ..\..\..
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
#//------------------------------------------------------------------------
#//
#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...)
#// (these must come before the common makefiles are included)
#//
#// DIRS - There is a subdirectory to process
#// INSTALL_FILES - Files to be installed in the distribution area
#//
#//------------------------------------------------------------------------
INSTALL_FILE_LIST=*.h
INSTALL_DIR=$(XPDIST)\include
LCFLAGS = $(LCFLAGS) /TP
MODULE=img
DEPTH=..\..\..
EXPORTS=il_types.h ni_pixmp.h libimg.h il_icons.h il_strm.h il_util.h \
ilErrors.h ilINetContext.h ilIURL.h ilINetReader.h ilIImageRenderer.h \
ilISystemServices.h
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include <$(DEPTH)/config/rules.mak>
export:: INSTALL_FILES

View File

@ -1,195 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* ni_pixmp.h --- Cross platform pixmap data structure.
* $Id: ni_pixmp.h,v 3.6 2001-06-19 08:46:30 pavlov%netscape.com Exp $
*/
#ifndef _NI_PIXMAP_H
#define _NI_PIXMAP_H
#include "xp_mem.h"
/************** Colorimetry/Gamma Correction Information. ********************
* This doesn't need to be implemented initially, but it's here for future *
* usage. */
/* The chrominance part of a CIE xyY color specification */
typedef struct CIEchroma {
float x;
float y;
} CIEchroma;
/* Define a device-independent color space using the white point and
primary colors of a gamut formed by RGB tristimulus values. */
typedef struct NI_RGBColorSpace {
CIEchroma white_point;
CIEchroma primary_red;
CIEchroma primary_green;
CIEchroma primary_blue;
} NI_RGBColorSpace;
typedef struct NI_ColorSpec {
double gamma;
NI_RGBColorSpace rgb_colorspace;
} NI_ColorSpec;
/***************** Colorspace and Colormap Information ***********************/
/* Possible colorspace types. */
typedef enum _NI_ColorSpaceType
{
NI_TrueColor = 0x01, /* RGB data. */
NI_PseudoColor = 0x02, /* Indexed data. */
NI_GreyScale = 0x04 /* Greyscale data. */
} NI_ColorSpaceType;
/* RGB bit allocation and offsets. */
typedef struct _NI_RGBBits {
PRUint8 red_bits; /* Number of bits assigned to red channel. */
PRUint8 red_shift; /* Offset for red channel bits. */
PRUint8 green_bits; /* Number of bits assigned to green channel. */
PRUint8 green_shift; /* Offset for green channel bits. */
PRUint8 blue_bits; /* Number of bits assigned to blue channel. */
PRUint8 blue_shift; /* Offset for blue channel bits. */
} NI_RGBBits;
/* An indexed RGB triplet. */
typedef struct _NI_IRGB {
PRUint8 index;
PRUint8 red, green, blue;
} NI_IRGB;
/* A RGB triplet representing a single pixel in the image's colormap
(if present.) */
typedef struct _NI_RGB
{
PRUint8 red, green, blue, pad; /* Windows requires the fourth byte &
many compilers pad it anyway. */
PRUint16 hist_count; /* Histogram frequency count. */
} NI_RGB;
/* Colormap information. */
typedef struct _NI_ColorMap {
int32 num_colors; /* Number of colors in the colormap.
A negative value can be used to denote a
possibly non-unique set. */
NI_RGB *map; /* Colormap colors. */
PRUint8 *index; /* NULL, if map is in index order. Otherwise
specifies the indices of the map entries. */
void *table; /* Lookup table for this colormap. Private to
the Image Library. */
} NI_ColorMap;
/* Special purpose flags for OS-specific problems. */
typedef enum {
WIN95_ROUNDING = 0x01 /* Windows 95 color quantization bug. */
} NI_OSFlags;
/* Colorspace information. */
typedef struct _NI_ColorSpace {
NI_ColorSpaceType type; /* NI_Truecolor, NI_Pseudocolor or
NI_Greyscale. */
/* The dimensions of the colorspace. */
union {
NI_RGBBits rgb; /* For TrueColor. */
PRUint8 index_depth; /* For PseudoColor and GreyScale. */
} bit_alloc; /* Allocation of bits. */
PRUint8 pixmap_depth; /* Total bit depth (including alpha or pad.) */
/* Colormap information. This may be used for one of three purposes:
- If the colorspace belongs to a PseudoColor source image, then the
colormap represents the mapping from the source image indices to
the corresponding RGB components.
- If the colorspace belongs to a TrueColor source image, then a
colormap may be provided as a suggested palette for displaying the
image on PseudoColor displays.
- If the colorspace belongs to a PseudoColor Display Front End or a
destination image for a PseudoColor Display Front End, then the
colormap represents the mapping from the display's palette indices
to the corresponding RGB components. */
NI_ColorMap cmap;
/* Image Library private data for this colorspace. */
void *private_data;
/* Special purpose flags for OS-specific problems. */
PRUint8 os_flags; /* Flags are of type NI_OSFlags. */
/* Reference counter. */
PRUint32 ref_count;
} NI_ColorSpace;
/* A pixmap's header information. */
typedef struct _NI_PixmapHeader
{
/* Size. */
PRUint32 width; /* Width. */
PRUint32 height; /* Height. */
PRUint32 widthBytes; /* width * depth / 8. May be aligned for
optimizations. */
/* Colorspace. */
NI_ColorSpace *color_space; /* Colorspace and colormap information. */
/* Transparency. */
NI_IRGB *transparent_pixel; /* The image's transparent pixel
(if present.) */
PRUint8 alpha_bits; /* Number of bits assigned to alpha channel. */
PRUint8 alpha_shift; /* Offset for alpha channel bits. */
int32 is_interleaved_alpha; /* Is alpha channel interleaved with
image data? */
PRPackedBool is_mask; /* Is this image a mask? (Boolean) */
/* Gamma/color correction. */
NI_ColorSpec color_spec;
} NI_PixmapHeader;
/* A pixmap. */
typedef struct _NI_Pixmap
{
NI_PixmapHeader header; /* Header information. */
void XP_HUGE *bits; /* Pointer to the bits. */
PRBool haveBits; /* true if we successfully allocated bits. Can't just
test the bits ptr directly, because this pointer
is only really valid between Lock and Unlock calls
on the pixels of the image */
void *client_data; /* Pixmap-specific data opaque to the Image
Library e.g. display front-ends which
support scaling may use this to store the
actual size at which the image is to be
displayed. */
} NI_Pixmap;
#endif /* _NI_PIXMAP_H */

View File

@ -1,103 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* The purpose of this file is to help phase out XP_ library
* from the image library. In general, XP_ data structures and
* functions will be replaced with the PR_ or PL_ equivalents.
* In cases where the PR_ or PL_ equivalents don't yet exist,
* this file (and its source equivalent) will play the role
* of the XP_ library.
*/
#ifndef xpcompat_h___
#define xpcompat_h___
#include "xp_core.h"
#include "prtypes.h"
#include "nsCom.h"
#define XP_HUGE
#define XP_HUGE_ALLOC(SIZE) malloc(SIZE)
#define XP_HUGE_FREE(SIZE) free(SIZE)
#define XP_HUGE_MEMCPY(DEST, SOURCE, LEN) memcpy(DEST, SOURCE, LEN)
#define XP_HUGE_CHAR_PTR char XP_HUGE *
typedef void
(*TimeoutCallbackFunction) (void * closure);
PR_BEGIN_EXTERN_C
/*
* XP_GetString is a mechanism for getting localized strings from a
* resource file. It needs to be replaced with a PR_ equivalent.
*/
extern char *XP_GetString(int i);
/*
* I don't know if qsort will ever be in NSPR, so this might have
* to stay here indefinitely. Mac is completely broken and should use
* mozilla/include/xp_qsort.h, mozilla/lib/xp/xp_qsort.c.
*/
#if defined(XP_MAC_NEVER)
extern void XP_QSORT(void *, size_t, size_t,
int (*)(const void *, const void *));
#endif /* XP_MAC */
NS_EXPORT void* IL_SetTimeout(TimeoutCallbackFunction func, void * closure, PRUint32 msecs);
NS_EXPORT void IL_ClearTimeout(void *timer_id);
#define MK_UNABLE_TO_LOCATE_FILE -1
#define MK_OUT_OF_MEMORY -2
#define XP_MSG_IMAGE_PIXELS -7
#define XP_MSG_IMAGE_NOT_FOUND -8
#define XP_MSG_XBIT_COLOR -9
#define XP_MSG_1BIT_MONO -10
#define XP_MSG_XBIT_GREYSCALE -11
#define XP_MSG_XBIT_RGB -12
#define XP_MSG_DECODED_SIZE -13
#define XP_MSG_WIDTH_HEIGHT -14
#define XP_MSG_SCALED_FROM -15
#define XP_MSG_IMAGE_DIM -16
#define XP_MSG_COLOR -17
#define XP_MSG_NB_COLORS -18
#define XP_MSG_NONE -19
#define XP_MSG_COLORMAP -20
#define XP_MSG_BCKDRP_VISIBLE -21
#define XP_MSG_SOLID_BKGND -22
#define XP_MSG_JUST_NO -23
#define XP_MSG_TRANSPARENCY -24
#define XP_MSG_COMMENT -25
#define XP_MSG_UNKNOWN -26
#define XP_MSG_COMPRESS_REMOVE -27
PR_END_EXTERN_C
#endif

View File

@ -1,10 +0,0 @@
#
# This is a list of local files which get copied to the mozilla:dist:libimg directory
#
if_struct.h
il.h
il_utilp.h
nsIImgDecoder.h
nsImgDCallbk.h
nsIImgDCallbk.h

View File

@ -1,48 +0,0 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = img
# XXX nsImgDCallbk.h should go into libimg/src instead of being here
EXPORTS = \
il.h \
if_struct.h \
il_utilp.h \
nsIImgDecoder.h \
nsIImgDCallbk.h \
nsImgDCallbk.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
include $(topsrcdir)/config/rules.mk

View File

@ -1,344 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* if.h --- Top-level image library internal routines
*
* $Id: if_struct.h,v 1.19 2001-06-19 11:15:45 pavlov%netscape.com Exp $
*/
#ifndef _if_h
#ifndef _ifstruct_h
#define _ifstruct_h
#define M12N
#define IL_INTERNAL
#include "prtypes.h"
#include "prlog.h"
#include "prmem.h"
#include "plstr.h"
#include "prtime.h"
#include "prlong.h"
#include "nsIPresContext.h"
#include "nsIImgDecoder.h"
typedef struct _IL_GroupContext IL_GroupContext;
typedef struct _IL_ImageReq IL_ImageReq;
typedef struct il_context_list il_context_list;
typedef struct il_container_list il_container_list;
typedef struct il_container_struct il_container;
#include "il_icons.h" /* Image icons. */
#include "libimg.h" /* Public API to Image Library. */
#include "il_utilp.h" /* Private header for colormap/colorspaces. */
#include "il_util.h" /* Public API for colormaps/colorspaces. */
#include "ilINetContext.h"
#include "ilIURL.h"
#include "ilINetReader.h"
#include "ilIImageRenderer.h"
#include "il.h"
#ifdef XP_WIN
#define _USD 1 /* scanlines upside-down */
#endif
/* For debugging counts of loading, looping and aborted images, needed for
group observer notification. */
/* #define DEBUG_GROUP_OBSERVER */
#define FREE_IF_NOT_NULL(x) do {if (x) {PR_FREEIF(x); (x) = NULL;}} while (0)
#include "prtypes.h" /* for IS_LITTLE_ENDIAN / IS_BIG_ENDIAN */
/* The imagelib labels bits in a 32-bit word from 31 on the left to 0 on the right.
This macro performs the necessary conversion to make that definition work on
little-endian platforms */
#if defined(IS_LITTLE_ENDIAN)
# define M32(bit) ((bit) ^ 0x18)
#elif defined(IS_BIG_ENDIAN)
# define M32(bit) (bit)
#else
ENDIANNESS UNKNOWN!
#endif
/* Don't change these unless you know what you're doing or you will
break 16-bit binaries. */
#define MAX_IMAGE_WIDTH 8000
#define MAX_IMAGE_HEIGHT 8000
/* MAX and MIN are almost universal, but be paranoid and use our
definitions. */
#ifdef MAX
#undef MAX
#endif
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#ifdef MIN
#undef MIN
#endif
#define MIN(x, y) ((x) < (y) ? (x) : (y))
/* Last output pass of an image */
#define IL_FINAL_PASS -1
/* Nature of the conversion from source image colorspace to target image
colorspace. */
typedef enum _IL_ConversionType {
IL_TrueToTrue = 0x09,
IL_TrueToPseudo = 0x0a,
IL_TrueToGrey = 0x0c,
IL_PseudoToTrue = 0x11,
IL_PseudoToPseudo = 0x12,
IL_PseudoToGrey = 0x14,
IL_GreyToTrue = 0x21,
IL_GreyToPseudo = 0x22,
IL_GreyToGrey = 0x24
} IL_ConversionType;
typedef void (*il_converter)(il_container *ic, const PRUint8 *mask,
const PRUint8 *sp, int x_offset,
int num, void XP_HUGE *out);
enum icstate {
IC_VIRGIN = 0x00, /* Newly-created container */
IC_START = 0x01, /* Requested stream from netlib, but no data yet */
IC_STREAM = 0x02, /* Stream opened, but insufficient data
received to determine image size */
IC_SIZED = 0x04, /* Image size determined - still loading */
IC_MULTI = 0x06, /* Same as IC_SIZED, but for second or
subsequent images in multipart MIME */
IC_NOCACHE = 0x11, /* Image deferred for loading later */
IC_COMPLETE = 0x20, /* Image loaded - no errors */
IC_BAD = 0x21, /* Corrupt or illegal image data */
IC_INCOMPLETE = 0x22, /* Partially loaded image data */
IC_MISSING = 0x23, /* No such file on server */
IC_ABORT_PENDING= 0x24 /* Image download abort in progress */
};
/* Still receiving data from the netlib ? */
#define IMAGE_CONTAINER_ACTIVE(ic) ((ic)->state <= IC_MULTI)
/* Force memory cache to be flushed ? */
#define FORCE_RELOAD(reload_method) \
(reload_method = DONT_USE_IMG_CACHE)
/* Simple list of image contexts. */
struct il_context_list {
IL_GroupContext *img_cx;
struct il_context_list *next;
};
/* Simple list of image containers. */
struct il_container_list {
il_container *ic;
struct il_container_list *next;
};
/* There is one il_container per real image */
struct il_container_struct {
il_container *next; /* Cache bidirectional linked list */
il_container *prev;
ilIURL *url;
char *url_address; /* Same as url->address if there is no redirection*/
PRUint32 hash;
PRUint32 urlhash;
enum icstate state;
int sized;
int moz_type; /* TYPE_CHROME, etc. */
int is_alone; /* only image on a page */
int is_in_use; /* Used by some context */
int32 loop_count; /* Remaining number of times to repeat image,
-1 means loop infinitely */
int is_looping; /* TRUE if this is the second or subsequent
pass of an animation. */
nsImageAnimation animate_request; /* Set in nsPresContext.
normal = 0; one frame = 1; one loop = 2 */
int is_aborted; /* True if aborted by NetLib. */
PRPackedBool is_url_loading;/* TRUE if NetLib is currently loading the URL. */
int is_multipart; /* TRUE if stream is known to be multipart. */
int multi; /* Known to be either multipart-MIME
or multi-image format */
int new_data_for_fe; /* Any Scanlines that FE doesn't know about ? */
int update_start_row; /* Scanline range to send to FE */
int update_end_row;
PRUint32 bytes_consumed; /* Bytes read from the stream so far */
NI_PixmapHeader *src_header; /* Source image header information. */
IL_Pixmap *image; /* Destination image pixmap structure. */
IL_Pixmap *mask; /* Destination mask pixmap structure. */
char* type;
void *ds; /* decoder's private data */
il_converter converter;
void *quantize; /* quantizer's private data */
class nsIImgDecoder *imgdec;
class nsIImgDCallbk *imgdcb;
void *row_output_timeout;
PRUint8 *scalerow;
int pass; /* pass (scan #) of a multi-pass image.
Used for interlaced GIFs & p-JPEGs */
int forced;
PRUint32 content_length;
int dest_width, dest_height; /* Target dimensions of the image */
PRPackedBool natural_size; /* True if the image is decoded to its natural
size. */
PRPackedBool aspect_distorted; /* True if the image undergoes aspect ratio
distortion during decoding. */
IL_IRGB *background_color; /* The requested background color for this
image (only applies if the image is
determined to be transparent.) A mask will
be created for a transparent image only if
no background color was requested. */
char *comment; /* Human-readable text stored in image */
int comment_length;
int colormap_serial_num; /* serial number of last installed colormap */
int dont_use_custom_palette;
int rendered_with_custom_palette;
IL_DitherMode dither_mode; /* ilDither or ilClosestColor */
IL_GroupContext *img_cx; /* The context in which this image was created.
Used during image decoding only. */
IL_DisplayType display_type; /* Type of display for which the container
is created. */
ilIImageRenderer *img_cb;
ilINetContext *net_cx; /* Context which initiated this transfer. */
IL_ImageReq *clients; /* List of clients of this container. */
IL_ImageReq *lclient; /* Last client in the client list. */
il_context_list *img_cx_list; /* List of contexts which have clients of
this container. */
IL_Rect displayable_rect; /* The area of the image pixmap which is in a
displayable state. Used as a filter
between client calls to IL_DisplaySubImage
and Image Library calls to DisplayPixmap, in
the event that the client requests us to
draw a part of the pixmap that has yet to
be decoded. */
time_t expires; /* Expiration date for the corresponding URL */
#ifdef DEBUG
PRTime start_time;
#endif
char *fetch_url; /* actual url address used */
};
typedef enum { ilUndefined, ilCI, ilGrey, ilRGB } il_mode;
typedef enum il_draw_mode
{
ilErase, /* Transparent areas are reset to background */
ilOverlay /* Transparent areas overlay existing data */
} il_draw_mode;
/* A context for a group of images. */
struct _IL_GroupContext {
ilIImageRenderer *img_cb;
void *dpy_cx; /* An opaque pointer passed back to all
callbacks in the interface vtable. */
IL_DisplayType display_type; /* IL_Console, IL_Printer or IL_PostScript. */
IL_ColorSpace *color_space; /* Display colorspace. */
/* Preferences */
PRPackedBool progressive_display; /* If TRUE, images are displayed while
loading */
IL_DitherMode dither_mode; /* IL_ClosestColor, IL_Dither or IL_Auto. */
int dontscale; /* Used for Macs, which do their own scaling */
int nolowsrc; /* If TRUE, never display LOSRC images */
/* Per-context state */
il_container_list *container_list;/* List of containers in this context. */
int32 num_containers; /* Number of containers in this context. */
int32 num_loading; /* Number of containers which are currently
loading. */
int32 num_looping; /* Number of containers which are currently
looping i.e. on second or subsequent
iteration of an animation. */
int32 num_aborted; /* Number of containers which have aborted
so far. */
XP_ObserverList obs_list; /* List of observers for this image group. */
struct _IL_GroupContext *next; /* Next entry in a list of image group
contexts. */
};
/* Tag to indicate whether a request represents an image or an icon. */
typedef enum
{
IL_IMAGE,
IL_ICON
} IL_ImageType;
/* This is Image Library's internal representation of a client's image request.
It represents a handle on a specific instance of an image container. */
struct _IL_ImageReq {
il_container *ic; /* The image container for this request (may
be shared with other requests.) */
IL_ImageType image_type; /* Image or icon. */
IL_GroupContext *img_cx; /* The group context to which this request
belongs. */
ilINetContext *net_cx; /* A clone of the net context which the image
library was given when this image handle was
created. This serves as a backup in case
the image container's net_cx becomes invalid,
(for example, when the client for which the
container was initially created is destroyed.) */
PRPackedBool stopped; /* TRUE - if user hit "Stop" button */
int is_view_image; /* non-zero if client is
internal-external-reconnect */
XP_ObserverList obs_list; /* List of observers for this request. */
struct _IL_ImageReq *next; /* Next entry in a list of image requests. */
};
#endif
#endif

View File

@ -1,58 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* il.h --- Exported image library interface
*
* $Id: il.h,v 1.6 2001-06-19 11:15:46 pavlov%netscape.com Exp $
*/
/*
* global defines for image lib users
*/
#ifndef _IL_H
#define _IL_H
/* attr values */
#define IL_ATTR_RDONLY 0
#define IL_ATTR_RW 1
#define IL_ATTR_TRANSPARENT 2
#define IL_ATTR_HONOR_INDEX 4
#undef ABS
#define ABS(x) (((x) < 0) ? -(x) : (x))
/* A fast but limited, perceptually-weighted color distance function */
#define IL_COLOR_DISTANCE(r1, r2, g1, g2, b1, b2) \
((ABS((g1) - (g2)) << 2) + (ABS((r1) - (r2)) << 1) + (ABS((b1) - (b2))))
/* We don't distinguish between colors that are "closer" together
than this. The appropriate setting is a subjective matter. */
#define IL_CLOSE_COLOR_THRESHOLD 6
#endif /* _IL_H */

View File

@ -1,82 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_utilp.h Colormap and colorspace utilities - types and definitions
* private to Image Library.
*
* $Id: il_utilp.h,v 1.6 2001-06-19 11:15:49 pavlov%netscape.com Exp $
*/
/************************* Colormap utilities ********************************/
/* Parameters for building a color cube and its associated lookup table. */
#define LOOKUP_TABLE_SIZE 32768
#define LOOKUP_TABLE_RED 32
#define LOOKUP_TABLE_GREEN 32
#define LOOKUP_TABLE_BLUE 32
#define CUBE_MAX_SIZE 256
/* Macro to convert 8-bit/channel RGB data into an 8-bit colormap index. */
#define COLORMAP_INDEX(lookup_table, red, green, blue) \
lookup_table[LOOKUP_TABLE_INDEX(red, green, blue)]
/* Macro to convert 8-bit/channel RGB data into a 16-bit lookup table index.
The lookup table value is the index to the colormap. */
#define LOOKUP_TABLE_INDEX(red, green, blue) \
((USE_5_BITS(red) << 10) | \
(USE_5_BITS(green) << 5) | \
USE_5_BITS(blue))
/* Take the 5 most significant bits of an 8-bit value. */
#define USE_5_BITS(x) ((x) >> 3)
/* Scaling macro for creating color cubes. */
#define CUBE_SCALE(val, double_new_size_minus1, old_size_minus1, \
double_old_size_minus1) \
((val) * (double_new_size_minus1) + (old_size_minus1)) / \
(double_old_size_minus1)
/************************** Colorspace utilities *****************************/
/* Image Library private part of an IL_ColorSpace structure. */
typedef struct il_ColorSpaceData {
/* RGB24 to RGBN depth conversion maps. Each of these maps take an
8-bit input for a color channel and converts it into that channel's
contribution to a depth N pixmap e.g. for a 24 to 16-bit color
conversion, the output pixel is given by
PRUint8 red, green, blue;
PRUint16 output_pixel;
output_pixel = r8torgbn[red] + g8torgbn[green] + b8torgbn[blue];
Depth conversion maps are created for the following destination image
pixmap depths: N = 8, 16 and 32. The type of the array elements is a
PRUintn. */
void *r8torgbn;
void *g8torgbn;
void *b8torgbn;
} il_ColorSpaceData;

View File

@ -1,52 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ..\..\..
#//------------------------------------------------------------------------
#//
#// Specify any "command" targets. (ie. DIRS, INSTALL_FILES, ...)
#// (these must come before the common makefiles are included)
#//
#// DIRS - There is a subdirectory to process
#// INSTALL_FILES - Files to be installed in the distribution area
#//
#//------------------------------------------------------------------------
INSTALL_FILE_LIST=*.h
INSTALL_DIR=$(XPDIST)\include
LCFLAGS = $(LCFLAGS) /TP
MODULE=img
DEPTH=..\..\..
EXPORTS= if_struct.h il.h il_utilp.h \
nsIImgDecoder.h nsIImgDCallbk.h nsImgDCallbk.h
include <$(DEPTH)/config/rules.mak>
export:: INSTALL_FILES

View File

@ -1,61 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIImgDCallbk_h___
#define nsIImgDCallbk_h___
#include "xpcompat.h" // for TimeoutCallbackFunction
#include "nsISupports.h"
/* d34a2f20-cd9f-11d2-802c-0060088f91a3 */
#define NS_IIMGDCALLBK_IID \
{ 0xd34a2f20, 0xcd9f, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
class nsIImgDCallbk : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMGDCALLBK_IID)
NS_IMETHOD ImgDCBFlushImage()=0;
NS_IMETHOD ImgDCBImageSize()=0;
NS_IMETHOD ImgDCBResetPalette()=0;
NS_IMETHOD ImgDCBInitTransparentPixel()=0;
NS_IMETHOD ImgDCBDestroyTransparentPixel()=0;
NS_IMETHOD ImgDCBSetupColorspaceConverter()=0;
NS_IMETHOD ImgDCBCreateGreyScaleColorSpace()=0;
NS_IMETHOD_(void*) ImgDCBSetTimeout(TimeoutCallbackFunction func, void* closure, PRUint32 msecs)=0;
NS_IMETHOD ImgDCBClearTimeout(void *timer_id)=0;
NS_IMETHOD ImgDCBHaveHdr(int destwidth, int destheight )=0;
NS_IMETHOD ImgDCBHaveRow(PRUint8 *rowbuf, PRUint8* rgbrow, int x_offset, int len,
int row, int dup_rowcnt, PRUint8 draw_mode,
int pass )=0;
NS_IMETHOD ImgDCBHaveImageFrame()=0;
NS_IMETHOD ImgDCBHaveImageAll()=0;
NS_IMETHOD ImgDCBError()=0;
};
#endif /* nsIImgDCallbk_h___ */

View File

@ -1,56 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef _nsIImgDecoder_h
#define _nsIImgDecoder_h
#include "if_struct.h" // for il_container
#include "ni_pixmp.h"
#include "nsISupports.h"
/* f00c22b0-bbd2-11d2-802c-0060088f91a3 */
#define NS_IIMGDECODER_IID \
{ 0xf00c22b0, 0xbbd2, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
#define NS_IIMGDECODER_BASE_CONTRACTID "@mozilla.org/image/decoder;1?type="
class nsIImgDecoder : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IIMGDECODER_IID)
NS_IMETHOD ImgDInit()=0;
NS_IMETHOD ImgDWriteReady(PRUint32 *max_read)=0;
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len)=0;
NS_IMETHOD ImgDComplete()=0;
NS_IMETHOD ImgDAbort()=0;
// XXX Need to fix this to make sure return type is nsresult
NS_IMETHOD_(il_container *) SetContainer(il_container *ic) = 0;
NS_IMETHOD_(il_container *) GetContainer() = 0;
};
#endif

View File

@ -1,85 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsImgDCallbk_h___
#define nsImgDCallbk_h___
// XXX This file needs to move to libimg/src - dp
#include "nsIImgDCallbk.h"
/*---------------------------------------------*/
/*-----------------class-----------------------*/
class ImgDCallbk : public nsIImgDCallbk
{
public:
ImgDCallbk(il_container *aContainer) {
NS_INIT_ISUPPORTS();
ilContainer = aContainer;
};
virtual ~ImgDCallbk();
NS_DECL_ISUPPORTS
NS_IMETHOD ImgDCBFlushImage();
NS_IMETHOD ImgDCBImageSize();
NS_IMETHOD ImgDCBResetPalette();
NS_IMETHOD ImgDCBInitTransparentPixel();
NS_IMETHOD ImgDCBDestroyTransparentPixel();
NS_IMETHOD ImgDCBSetupColorspaceConverter();
NS_IMETHOD ImgDCBCreateGreyScaleColorSpace();
NS_IMETHOD_(void*) ImgDCBSetTimeout(TimeoutCallbackFunction func,
void* closure, PRUint32 msecs);
NS_IMETHOD ImgDCBClearTimeout(void *timer_id);
/* callbacks from the decoder */
NS_IMETHOD ImgDCBHaveHdr(int destwidth, int destheight);
NS_IMETHOD ImgDCBHaveRow(PRUint8*, PRUint8*,
int, int, int, int,
PRUint8 , int);
NS_IMETHOD ImgDCBHaveImageFrame();
NS_IMETHOD ImgDCBHaveImageAll();
NS_IMETHOD ImgDCBError();
NS_IMETHODIMP CreateInstance(const nsCID &aClass,
il_container* ic,
const nsIID &aIID,
void **ppv) ;
il_container *GetContainer() {
return ilContainer;
};
il_container *SetContainer(il_container *ic) {
ilContainer=ic;
return ic;
};
private:
il_container* ilContainer;
};
#endif /* nsImgDCallbk_h___ */

View File

@ -1,64 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#if 0 // OBSOLETE
#ifndef nsImgDecCIID_h__
#define nsImgDecCIID_h__
#include "nsRepository.h"
/* f00c22b0-bbd2-11d2-802c-0060088f91a3 */
#define NS_IIMGDECODER_IID \
{ 0xf00c22b0, 0xbbd2, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/***************************************************/
#define NS_IMGDECODER_CID \
{ 0xc9089cc0, 0xbaf4, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/* bc60b730-bbcf-11d2-802c-0060088f91a3 */
#define NS_IMGDECODER_IID \
{ 0xbc60730, 0xbbcf, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
NS_DEFINE_IID(kImgDecoderIID, NS_IMGDECODER_IID);
NS_DEFINE_IID(kImgDecoderCID, NS_IMGDECODER_CID);
/***************************************************/
/* e41ac650-cd9f-11d2-802c-0060088f91a3 */
#define NS_IMGDCALLBK_CID \
{ 0xe41ac650, 0xcd9f, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/* d34a2f20-cd9f-11d2-802c-0060088f91a3 */
#define NS_IMGDCALLBK_IID \
{ 0xd34a2f20, 0xcd9f, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
#endif
#endif /* 0 */

View File

@ -1,32 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#if 0 // OBSOLETE
#ifndef nsImgDec_h___
#define nsImgDec_h___
#include "nsIFactory.h"
#endif
#endif /* 0 */

View File

@ -1,4 +0,0 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#

View File

@ -1,64 +0,0 @@
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = img
LIBRARY_NAME = img_s
REQUIRES = xpcom string layout util cookie necko timer
CPPSRCS = \
ilNetReader.cpp \
color.cpp \
colormap.cpp \
dither.cpp \
if.cpp \
ilclient.cpp \
il_util.cpp \
scale.cpp \
xpcompat.cpp \
$(NULL)
LOCAL_INCLUDES = -I$(srcdir)
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
FORCE_STATIC_LIB = 1
include $(topsrcdir)/config/rules.mk
ifeq ($(OS_ARCH),Linux)
DEFINES += -D_BSD_SOURCE -D_XOPEN_SOURCE=500
endif
ifeq ($(OS_ARCH)$(OS_RELEASE),SunOS5)
ifeq ($(shell uname -r),5.3)
# In this special case (dither.cpp), the compiler has to know
# the OS version to a finer granularity than normal.
DEFINES += -DOSMINOR=3
endif
endif

View File

@ -1,965 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*
*
* This Original Code has been modified by IBM Corporation.
* Modifications made by IBM described herein are
* Copyright (c) International Business Machines
* Corporation, 2000
*
* Modifications to Mozilla code or documentation
* identified per MPL Section 3.3
*
* Date Modified by Description of modification
* 03/27/2000 IBM Corp. Added PR_CALLBACK for Optlink
* use in OS2
*/
/* -*- Mode: C; tab-width: 4 -*-
color.c --- Responsible for conversion from image depth to screen depth.
Includes dithering for B&W displays, but not dithering
for PseudoColor displays which can be found in dither.c.
$Id: color.cpp,v 3.19 2001-06-19 08:46:54 pavlov%netscape.com Exp $
*/
#include "if.h"
#include "nsQuickSort.h"
#include "xp_str.h" //for XP_RANDOM
#ifdef PROFILE
#pragma profile on
#endif
PRUint8 il_identity_index_map[] = { 0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55,
56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118,
119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133,
134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148,
149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178,
179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193,
194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208,
209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223,
224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238,
239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253,
254, 255 };
static void
ConvertRGBToCI(il_container *ic,
const PRUint8 *mask,
const PRUint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
PRUint8 red, green, blue, map_index;
PRUint8 XP_HUGE *out = (PRUint8 XP_HUGE *) vout + x_offset;
const PRUint8 *end = sp + 3*num;
IL_ColorMap *cmap = &ic->image->header.color_space->cmap;
PRUint8 *lookup_table = (PRUint8 *)cmap->table;
PRUint8 *index_map = cmap->index;
if (index_map == NULL)
{
index_map = il_identity_index_map;
}
if (!mask)
{
while (sp < end)
{
red = sp[0];
green = sp[1];
blue = sp[2];
map_index = COLORMAP_INDEX(lookup_table, red, green, blue);
*out = index_map[map_index];
out++;
sp += 3;
}
}
else
{
while (sp < end)
{
if (*mask++) {
red = sp[0];
green = sp[1];
blue = sp[2];
map_index = COLORMAP_INDEX(lookup_table, red, green, blue);
*out = index_map[map_index];
}
out++;
sp += 3;
}
}
}
static void
DitherConvertRGBToCI(il_container *ic,
const PRUint8 *mask,
const PRUint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
PRUint8 XP_HUGE *out = (PRUint8 XP_HUGE *) vout + x_offset;
const PRUint8 XP_HUGE *end = out + num;
PRUint8 *index_map = ic->image->header.color_space->cmap.index;
if (index_map == NULL)
{
index_map = il_identity_index_map;
}
il_quantize_fs_dither(ic, mask, sp, x_offset, (PRUint8 XP_HUGE *) vout, num);
if (mask) {
while (out < end) {
if (*mask++)
*out = index_map[*out];
out++;
}
} else {
while (out < end) {
*out = index_map[*out];
out++;
}
}
}
struct fs_data {
long* err1;
long* err2;
long* err3;
PRUint8 *greypixels;
PRUint8 *bwpixels;
int width;
int direction;
long threshval, sum;
};
static struct fs_data *
init_fs_dither(il_container *ic)
{
struct fs_data *fs;
fs = PR_NEWZAP(struct fs_data);
if (! fs)
return NULL;
fs->width = ic->image->header.width;
fs->direction = 1;
fs->err1 = (long*) PR_Calloc(fs->width+2, sizeof(long));
fs->err2 = (long*) PR_Calloc(fs->width+2, sizeof(long));
fs->greypixels = (PRUint8 *)PR_Calloc(fs->width+7, 1);
fs->bwpixels = (PRUint8 *)PR_Calloc(fs->width+7, 1);
#ifdef XP_UNIX
{
int i;
/* XXX should not be unix only */
for(i=0; i<fs->width+2; i++)
{
fs->err1[i] = (XP_RANDOM() % 1024 - 512)/4;
}
}
#endif
fs->threshval = 512;
ic->quantize = (void *)fs;
return fs;
}
static void
ConvertRGBToBW(il_container *ic,
const PRUint8 *mask,
const PRUint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
PRUint32 fgmask32, bgmask32;
PRUint32 *m;
int mask_bit;
struct fs_data *fs = (struct fs_data *)ic->quantize;
PRUint8 XP_HUGE *out = (PRUint8 XP_HUGE *)vout;
PRUint8 *gp, *bp;
int col, limitcol;
long grey;
long sum;
if(!fs)
fs = init_fs_dither(ic);
/* Silently fail if memory exhausted */
if (! fs)
return;
gp = fs->greypixels;
for(col=0; col<fs->width; col++)
{
/* CCIR 709 */
PRUint8 r = *sp++;
PRUint8 g = *sp++;
PRUint8 b = *sp++;
grey = ((PRUintn)(0.299 * 4096) * r +
(PRUintn)(0.587 * 4096) * g +
(PRUintn)(0.114 * 4096) * b) / 4096;
*gp++ = (PRUint8)grey;
}
#if 0
/* thresholding */
gp = fs->greypixels;
bp = fs->bwpixels;
for(col=0; col<fs->width; col++)
{
*bp++ = (*gp++<128);
}
#else
for(col=0; col<fs->width+2; col++)
{
fs->err2[col] =0;
}
if (fs->direction)
{
col = 0;
limitcol = fs->width;
gp = fs->greypixels;
bp = fs->bwpixels;
}
else
{
col = fs->width - 1;
limitcol = -1;
gp = &(fs->greypixels[col]);
bp = &(fs->bwpixels[col]);
}
do
{
sum = ( (long) *gp * 1024 ) / 256 + fs->err1[col + 1];
if ( sum >= 512)
{
*bp = 0;
sum = sum - 1024;
}
else
*bp = 1;
if ( fs->direction )
{
fs->err1[col + 2] += ( sum * 7 ) / 16;
fs->err2[col ] += ( sum * 3 ) / 16;
fs->err2[col + 1] += ( sum * 5 ) / 16;
fs->err2[col + 2] += ( sum ) / 16;
col++; gp++; bp++;
}
else
{
fs->err1[col ] += ( sum * 7 ) / 16;
fs->err2[col + 2] += ( sum * 3 ) / 16;
fs->err2[col + 1] += ( sum * 5 ) / 16;
fs->err2[col ] += ( sum ) / 16;
col--; gp--; bp--;
}
}
while ( col != limitcol );
fs->err3 = fs->err1;
fs->err1 = fs->err2;
fs->err2 = fs->err3;
fs->direction = !fs->direction;
#endif
bp = fs->bwpixels;
bgmask32 = 0; /* 32-bit temporary mask accumulators */
fgmask32 = 0;
m = ((PRUint32*)out) + (x_offset >> 5);
mask_bit = ~x_offset & 0x1f; /* next bit to write in 32-bit mask */
/* Add a bit to the row of mask bits. Flush accumulator to memory if full. */
#define SHIFT_IMAGE_MASK(opaqueness, pixel) \
{ \
fgmask32 |= ((PRUint32)pixel & opaqueness) << M32(mask_bit); \
bgmask32 |= ((PRUint32)((pixel ^ 1) & opaqueness)) << M32(mask_bit); \
\
/* Filled up 32-bit mask word. Write it to memory. */ \
if (mask_bit-- == 0) { \
PRUint32 mtmp = *m; \
mtmp |= fgmask32; \
mtmp &= ~bgmask32; \
*m++ = mtmp; \
mask_bit = 31; \
bgmask32 = 0; \
fgmask32 = 0; \
} \
}
for(col=0; col < num; col++)
{
int opaqueness = 1;
int pixel = *bp++;
if (mask)
opaqueness = *mask++;
SHIFT_IMAGE_MASK(opaqueness, pixel);
}
/* End of scan line. Write out any remaining mask bits. */
if (mask_bit < 31) {
PRUint32 mtmp = *m;
mtmp |= fgmask32;
mtmp &= ~bgmask32;
*m = mtmp;
}
}
static void
ConvertRGBToGrey8(il_container *ic,
const PRUint8 *mask,
const PRUint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
PRUintn r, g, b;
PRUint8 XP_HUGE *out = (PRUint8 XP_HUGE *)vout + x_offset;
const PRUint8 *end = sp + num*3;
PRUint32 grey;
if (!mask)
{
while (sp < end)
{
/* CCIR 709 */
r = sp[0];
g = sp[1];
b = sp[2];
grey = ((PRUintn)(0.299 * 4096) * r +
(PRUintn)(0.587 * 4096) * g +
(PRUintn)(0.114 * 4096) * b) / 4096;
*out = (PRUint8)grey;
out++;
sp += 3;
}
}
else
{
while (sp < end)
{
if (*mask++)
{
/* CCIR 709 */
r = sp[0];
g = sp[1];
b = sp[2];
grey = ((PRUintn)(0.299 * 4096) * r +
(PRUintn)(0.587 * 4096) * g +
(PRUintn)(0.114 * 4096) * b) / 4096;
*out = (PRUint8)grey;
}
out++;
sp += 3;
}
}
}
static void
ConvertRGBToRGB8(il_container *ic,
const PRUint8 *mask,
const PRUint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
PRUintn r, g, b, pixel;
PRUint8 XP_HUGE *out = (PRUint8 XP_HUGE *) vout + x_offset;
const PRUint8 *end = sp + num*3;
il_ColorSpaceData *private_data =
(il_ColorSpaceData *)ic->image->header.color_space->private_data;
PRUint8 *rm = (PRUint8*)private_data->r8torgbn;
PRUint8 *gm = (PRUint8*)private_data->g8torgbn;
PRUint8 *bm = (PRUint8*)private_data->b8torgbn;
if (!mask)
{
while (sp < end)
{
r = sp[0];
g = sp[1];
b = sp[2];
pixel = rm[r] + gm[g] + bm[b];
*out = pixel;
out++;
sp+=3;
}
}
else
{
while (sp < end)
{
if (*mask++) {
r = sp[0];
g = sp[1];
b = sp[2];
pixel = rm[r] + gm[g] + bm[b];
*out = pixel;
}
out++;
sp += 3;
}
}
}
static void
ConvertRGBToRGB16(il_container *ic,
const PRUint8 *mask,
const PRUint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
PRUintn r, g, b, pixel;
PRUint16 XP_HUGE *out = (PRUint16 XP_HUGE *) vout + x_offset;
const PRUint8 *end = sp + num*3;
il_ColorSpaceData *private_data =
(il_ColorSpaceData *)ic->image->header.color_space->private_data;
PRUint16 *rm = (PRUint16*)private_data->r8torgbn;
PRUint16 *gm = (PRUint16*)private_data->g8torgbn;
PRUint16 *bm = (PRUint16*)private_data->b8torgbn;
if (!mask)
{
while (sp < end)
{
r = sp[0];
g = sp[1];
b = sp[2];
pixel = rm[r] + gm[g] + bm[b];
*out = pixel;
out++;
sp+=3;
}
}
else
{
while (sp < end)
{
if (*mask++) {
r = sp[0];
g = sp[1];
b = sp[2];
pixel = rm[r] + gm[g] + bm[b];
*out = pixel;
}
out++;
sp += 3;
}
}
}
static void
ConvertRGBToRGB24(il_container *ic,
const PRUint8 *mask,
const PRUint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
PRUint8 XP_HUGE *out = (PRUint8 XP_HUGE *) vout + (3 * x_offset);
const PRUint8 *end = sp + num*3;
/* XXX this is a hack because it ignores the shifts */
// The XP_UNIX define down here is needed because the unix gtk
// image munging code expects the image data to be in RGB format.
//
// The conversion below is obviously a waste of time on unix and
// probably mac.
//
// Unfortunately, the alternative seems to require significant IMGLIB
// work. Simply seeting to ic->converter to NULL for the 24 bit case
// did not work as expected.
//
// The correct fix might be to not do any conversion if the image data
// is already in the format expected on the nsIImage end.
//
// -ramiro
if (!mask)
{
while (sp < end) {
#if !defined(XP_UNIX) || defined(MOZ_WIDGET_PHOTON)
out[2] = sp[0];
out[1] = sp[1];
out[0] = sp[2];
#else
out[0] = sp[0];
out[1] = sp[1];
out[2] = sp[2];
#endif
out+=3;
sp+=3;
}
} else {
while (sp < end) {
if (*mask++)
{
#if !defined(XP_UNIX) || defined(MOZ_WIDGET_PHOTON)
out[2] = sp[0];
out[1] = sp[1];
out[0] = sp[2];
#else
out[0] = sp[0];
out[1] = sp[1];
out[2] = sp[2];
#endif
}
out+=3;
sp+=3;
}
}
}
static void
ConvertRGBToRGB32(il_container *ic,
const PRUint8 *mask,
const PRUint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
PRUintn r, g, b, pixel;
PRUint32 XP_HUGE *out = (PRUint32 XP_HUGE *) vout + x_offset;
const PRUint8 *end = sp + num*3;
il_ColorSpaceData *private_data =
(il_ColorSpaceData *)ic->image->header.color_space->private_data;
PRUint32 *rm = (PRUint32*)private_data->r8torgbn;
PRUint32 *gm = (PRUint32*)private_data->g8torgbn;
PRUint32 *bm = (PRUint32*)private_data->b8torgbn;
if (!mask)
{
while (sp < end)
{
r = sp[0];
g = sp[1];
b = sp[2];
pixel = rm[r] + gm[g] + bm[b];
*out = pixel;
out++;
sp+=3;
}
}
else
{
while (sp < end)
{
if (*mask++) {
r = sp[0];
g = sp[1];
b = sp[2];
pixel = rm[r] + gm[g] + bm[b];
*out = pixel;
}
out++;
sp += 3;
}
}
}
/* Sorting predicate for NS_QuickSort() */
int PR_CALLBACK compare_PRUint32(const void *a, const void *b, void *unused)
{
PRUint32 a1 = *(PRUint32*)a;
PRUint32 b1 = *(PRUint32*)b;
return (a1 < b1) ? -1 : ((a1 > b1) ? 1 : 0);
}
/* Count colors in the source image's color map. Remove duplicate colors. */
static void
unique_map_colors(NI_ColorMap *cmap)
{
PRUintn i;
PRUint32 ind[256];
int32 num_colors = cmap->num_colors;
IL_RGB *map = cmap->map;
PRUintn max_colors;
PRUintn unique_colors = 1;
/* A -ve value for cmap->num_colors indicates that the colors may be
non-unique. */
if (num_colors > 0) /* Colors are unique. */
return;
max_colors = -num_colors;
PR_ASSERT(max_colors <= 256);
PR_ASSERT(map);
/* Convert RGB values into indices. */
for (i = 0; i < max_colors; i++) {
ind[i] = (map[i].red << 16) + (map[i].green << 8) + map[i].blue;
}
/* Sort by color, so identical colors will be grouped together. */
NS_QuickSort(ind, max_colors, sizeof(*ind), compare_PRUint32, NULL);
/* Look for adjacent colors with different values */
for (i = 0; i < max_colors-1; i++)
if (ind[i] != ind[i + 1])
unique_colors++;
cmap->num_colors = unique_colors;
}
/* Create RGB24 to RGBN depth conversion tables for a TrueColor destination
image colorspace. N is the pixmap_depth of the colorspace, which is the
sum of the bits assigned to the three color channels, plus any additional
allowance that might be necessary, e.g. for an alpha channel, or for
alignment. Possible pixmap depths are N = 8, 16, or 32 bits. */
static int32
il_init_rgb_depth_tables(IL_ColorSpace *color_space)
{
register PRUint8 red_bits, green_bits, blue_bits;
register PRUint8 red_shift, green_shift, blue_shift;
int32 j, k;
int32 pixmap_depth = color_space->pixmap_depth;
IL_RGBBits *rgb = &color_space->bit_alloc.rgb;
il_ColorSpaceData *private_data =
(il_ColorSpaceData *)color_space->private_data;
/* If depth conversion tables exist already, we have nothing to do. */
if (private_data->r8torgbn &&
private_data->g8torgbn &&
private_data->b8torgbn)
return PR_TRUE;
red_bits = rgb->red_bits;
red_shift = rgb->red_shift;
green_bits = rgb->green_bits;
green_shift = rgb->green_shift;
blue_bits = rgb->blue_bits;
blue_shift = rgb->blue_shift;
switch(pixmap_depth) {
case 8: /* 8-bit TrueColor. */
{
PRUint8 *tmp_map; /* Array type corresponds to pixmap depth. */
private_data->r8torgbn = PR_MALLOC(256);
private_data->g8torgbn = PR_MALLOC(256);
private_data->b8torgbn = PR_MALLOC(256);
if (!(private_data->r8torgbn &&
private_data->g8torgbn &&
private_data->b8torgbn)) {
ILTRACE(0,("il: MEM il_init_rgb_tables"));
return PR_FALSE;
}
/* XXXM12N These could be optimized. */
tmp_map = (PRUint8*)private_data->r8torgbn;
for (j = 0; j < (1 << red_bits); j++)
for (k = 0; k < (1 << (8 - red_bits)); k++)
*tmp_map++ = (PRUint8)(j << red_shift);
tmp_map = (PRUint8*)private_data->g8torgbn;
for (j = 0; j < (1 << green_bits); j++)
for (k = 0; k < (1 << (8 - green_bits)); k++)
*tmp_map++ = (PRUint8)(j << green_shift);
tmp_map = (PRUint8*)private_data->b8torgbn;
for (j = 0; j < (1 << blue_bits); j++)
for (k = 0; k < (1 << (8 - blue_bits)); k++)
*tmp_map++ = (PRUint8)(j << blue_shift);
break;
}
case 16: /* Typically 15 or 16-bit TrueColor. */
{
PRBool win95_rounding; /* True if Win95 color quatization bug is
present. */
PRUint16 *tmp_map; /* Array type corresponds to pixmap depth. */
private_data->r8torgbn = PR_MALLOC(sizeof(PRUint16) * 256);
private_data->g8torgbn = PR_MALLOC(sizeof(PRUint16) * 256);
private_data->b8torgbn = PR_MALLOC(sizeof(PRUint16) * 256);
if (!(private_data->r8torgbn &&
private_data->g8torgbn &&
private_data->b8torgbn)) {
ILTRACE(0,("il: MEM il_init_rgb_tables"));
return PR_FALSE;
}
/* Compensate for Win95's sometimes-weird color quantization. */
win95_rounding = (PRBool)((color_space->os_flags & WIN95_ROUNDING) != 0);
#define _W1(v, b) ((v) - (1 << (7 - (b))))
#define WACKY(v, b) ((_W1(v, b) < 0) ? 0 : _W1(v, b))
#define ROUND(v, b) (win95_rounding ? WACKY(v, b) : (v))
/* XXXM12N These could be optimized. */
tmp_map = (PRUint16*)private_data->r8torgbn;
for (j = 0; j < 256; j++)
*tmp_map++ = (PRUint16)(ROUND(j, red_bits) >> (8 - red_bits) <<
red_shift);
tmp_map = (PRUint16*)private_data->g8torgbn;
for (j = 0; j < 256; j++)
*tmp_map++ = (PRUint16)(ROUND(j, green_bits) >> (8 - green_bits) <<
green_shift);
tmp_map = (PRUint16*)private_data->b8torgbn;
for (j = 0; j < 256; j++)
*tmp_map++ = (PRUint16)(ROUND(j, blue_bits) >> (8 - blue_bits) <<
blue_shift);
#undef _W1
#undef WACKY
#undef ROUND
break;
}
case 32: /* Typically 24-bit TrueColor with an 8-bit
(leading) pad. */
{
PRUint32 *tmp_map; /* Array type corresponds to pixmap depth. */
private_data->r8torgbn = PR_MALLOC(sizeof(PRUint32) * 256);
private_data->g8torgbn = PR_MALLOC(sizeof(PRUint32) * 256);
private_data->b8torgbn = PR_MALLOC(sizeof(PRUint32) * 256);
if (!(private_data->r8torgbn &&
private_data->g8torgbn &&
private_data->b8torgbn)) {
ILTRACE(0,("il: MEM il_init_rgb_tables"));
return PR_FALSE;
}
tmp_map = (PRUint32*)private_data->r8torgbn;
for (j = 0; j < (1 << red_bits); j++)
*tmp_map++ = j << red_shift;
tmp_map = (PRUint32*)private_data->g8torgbn;
for (j = 0; j < (1 << green_bits); j++)
*tmp_map++ = j << green_shift;
tmp_map = (PRUint32*)private_data->b8torgbn;
for (j = 0; j < (1 << blue_bits); j++)
*tmp_map++ = j << blue_shift;
break;
}
default:
ILTRACE(0,("il: unsupported truecolor pixmap_depth: %d bpp",
pixmap_depth));
PR_ASSERT(0);
}
return PR_TRUE;
}
/*
* A greater number of colors than this causes dithering to be used
* rather than closest-color rendering if dither_mode == ilAuto.
*/
#define AUTO_DITHER_COLOR_THRESHOLD 16
/* XXX - need to do this for every client of a container*/
PRBool
il_setup_color_space_converter(il_container *ic)
{
PRUint8 conversion_type;
IL_GroupContext *img_cx = ic->img_cx;
IL_DitherMode dither_mode = img_cx->dither_mode;
il_converter converter = NULL;
NI_ColorSpace *img_color_space = ic->image->header.color_space;
NI_ColorSpace *src_color_space = ic->src_header->color_space;
/* Make sure that the num_colors field of the source image's colormap
represents the number of unique colors. In the case of GIFs, for
example, colormap sizes are actually rounded up to a power of two. */
if (src_color_space->type == NI_PseudoColor)
unique_map_colors(&src_color_space->cmap);
#ifndef M12N /* XXXM12N Fix me. */
#ifdef XP_MAC
if ((ic->type == IL_GIF) && (ic->image->depth != 1)) {
ic->converter = NULL;
/* Allow for custom color palettes */
il_set_color_palette(ic->cx, ic);
return;
}
#endif
#endif /* M12N */
conversion_type = (src_color_space->type << 3) | img_color_space->type;
switch (conversion_type) {
/* Always dither when converting from truecolor to pseudocolor. */
case IL_TrueToPseudo:
dither_mode = IL_Dither;
/* Build the range limit table if it doesn't exist. */
if (!il_setup_quantize())
return PR_FALSE;
converter = DitherConvertRGBToCI;
break;
/* These conversions are accomplished by first converting to RGB,
followed by closest color matching or dithering. */
case IL_GreyToPseudo:
case IL_PseudoToPseudo:
if (src_color_space == img_color_space) {
ic->converter = NULL;
return PR_TRUE;
} else
/* Resolve dither_mode if necessary. */
if (dither_mode == IL_Auto) {
int num_colors = src_color_space->cmap.num_colors;
/* Use a simple heuristic to decide whether or not we dither. */
if ((num_colors <= AUTO_DITHER_COLOR_THRESHOLD) &&
(num_colors <= (img_color_space->cmap.num_colors / 2))) {
dither_mode = IL_ClosestColor;
ILTRACE(1,("Dithering turned off; Image has %d colors: %s",
num_colors, ic->url ? ic->url_address : ""));
}
else {
dither_mode = IL_Dither;
}
}
switch (dither_mode) {
case IL_ClosestColor:
converter = ConvertRGBToCI;
break;
case IL_Dither:
/* Build the range limit table if it doesn't exist. */
if (!il_setup_quantize())
return PR_FALSE;
converter = DitherConvertRGBToCI;
break;
default:
break;
}
break;
/* These conversions are accomplished by first converting to RGB24,
followed by conversion to the actual image pixmap depth. */
case IL_TrueToTrue:
case IL_PseudoToTrue:
case IL_GreyToTrue:
switch (img_color_space->pixmap_depth) {
case 8:
/* Build the depth conversion tables if they do not exist. */
if (!il_init_rgb_depth_tables(img_color_space))
return PR_FALSE;
converter = ConvertRGBToRGB8;
break;
case 16:
/* Build the depth conversion tables if they do not exist. */
if (!il_init_rgb_depth_tables(img_color_space))
return PR_FALSE;
converter = ConvertRGBToRGB16;
break;
case 24:
converter = ConvertRGBToRGB24;
break;
case 32:
/* Build the depth conversion tables if they do not exist. */
if (!il_init_rgb_depth_tables(img_color_space))
return PR_FALSE;
converter = ConvertRGBToRGB32;
break;
default:
PR_ASSERT(0);
break;
}
break;
/* These conversions are accomplished by first converting to RGB24,
followed by conversion to the actual image pixmap depth. */
case IL_TrueToGrey:
case IL_PseudoToGrey:
case IL_GreyToGrey:
switch (img_color_space->pixmap_depth) {
case 1:
dither_mode = IL_Dither;
converter = ConvertRGBToBW;
break;
case 8:
converter = ConvertRGBToGrey8;
break;
}
break;
default:
converter = NULL;
PR_ASSERT(0);
break;
}
ic->dither_mode = dither_mode;
ic->converter = converter;
#ifndef M12N /* XXXM12N Fix me. */
/* Allow for custom color palettes */
if (img_header->cs_type == NI_Pseudocolor)
il_set_color_palette(ic->cx, ic);
#endif /* M12N */
return PR_TRUE;
}
#ifdef PROFILE
#pragma profile off
#endif

View File

@ -1,60 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* colormap.c
*
* $Id: colormap.cpp,v 3.5 2001-06-19 08:46:56 pavlov%netscape.com Exp $
*/
#include "if.h"
/* Force il_set_color_palette() to load a new colormap for an image */
PRBool
il_reset_palette(il_container *ic)
{
PRBool ret = PR_TRUE;
NI_ColorMap *cmap;
if(ic->src_header){
if(ic->src_header->color_space){
cmap = &ic->src_header->color_space->cmap;
if(cmap->num_colors > 0){
cmap->num_colors=0;
}
}else{
ret = PR_FALSE;
}
}else{
ret = PR_FALSE;
}
ic->colormap_serial_num = -1;
ic->dont_use_custom_palette = PR_FALSE;
ic->rendered_with_custom_palette = PR_FALSE;
return ret;
}

View File

@ -1,398 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "if.h"
#include "il.h"
/* This is a lame hack to get around a problem with boolean on Solaris 2.3 */
#if defined(__sun) && defined(__sparc) && defined(__svr4__) && (OSMINOR == 3)
#define HAVE_BOOLEAN
#undef MUST_UNDEF_HAVE_BOOLEAN_AFTER_INCLUDES
#endif
#include "jpeglib.h"
#include "jerror.h"
#include "nsCRT.h"
/* cope with brain-damaged compilers that don't make sizeof return a size_t */
#ifdef SIZEOF
#undef SIZEOF
#endif
#define SIZEOF(object) ((size_t) sizeof(object))
/* just in case someone needs it */
#ifdef RIGHT_SHIFT_IS_UNSIGNED
#define SHIFT_TEMPS INT32 shift_temp;
#define RIGHT_SHIFT(x,shft) \
((shift_temp = (x)) < 0 ? \
(shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
(shift_temp >> (shft)))
#else
#define SHIFT_TEMPS
#define RIGHT_SHIFT(x,shft) ((x) >> (shft))
#endif
/* BEGIN code adapted from jpeg library */
typedef INT32 FSERROR; /* 16 bits should be enough */
typedef int LOCFSERROR; /* use 'int' for calculation temps */
typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
typedef struct my_cquantize_str {
/* Variables for Floyd-Steinberg dithering */
FSERRPTR fserrors[3]; /* accumulated errors */
boolean on_odd_row; /* flag to remember which row we are on */
} my_cquantize;
typedef my_cquantize *my_cquantize_ptr;
static JSAMPLE *the_sample_range_limit = NULL;
/* allocate and fill in the sample_range_limit table */
int
il_setup_quantize(void)
{
JSAMPLE *table;
int i;
if(the_sample_range_limit)
return TRUE;
/* lost for ever */
table = (JSAMPLE *)PR_MALLOC((5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
if (!table)
{
ILTRACE(1,("il: range limit table lossage"));
return FALSE;
}
table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
the_sample_range_limit = table;
/* First segment of "simple" table: limit[x] = 0 for x < 0 */
nsCRT::zero(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
/* Main part of "simple" table: limit[x] = x */
for (i = 0; i <= MAXJSAMPLE; i++)
table[i] = (JSAMPLE) i;
table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
/* End of simple table, rest of first half of post-IDCT table */
for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
table[i] = MAXJSAMPLE;
/* Second half of post-IDCT table */
nsCRT::zero(table + (2 * (MAXJSAMPLE+1)),
(2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
nsCRT::memcpy(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
the_sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
return TRUE;
}
/* Must remain idempotent. Also used to make sure that the ic->quantize has the same
colorSpace info as the rest of ic. */
int
il_init_quantize(il_container *ic)
{
size_t arraysize;
int i, j;
my_cquantize_ptr cquantize;
if (ic->quantize)
il_free_quantize(ic);
ic->quantize = PR_NEWZAP(my_cquantize);
if (!ic->quantize)
{
loser:
ILTRACE(0,("il: MEM il_init_quantize"));
return FALSE;
}
cquantize = (my_cquantize_ptr) ic->quantize;
arraysize = (size_t) ((ic->image->header.width + 2) * SIZEOF(FSERROR));
for (i = 0; i < 3; i++)
{
cquantize->fserrors[i] = (FSERRPTR) PR_Calloc(1, arraysize);
if (!cquantize->fserrors[i])
{
/* ran out of memory part way thru */
for (j = 0; j < i; j++)
{
if (cquantize->fserrors[j])
{
PR_FREEIF(cquantize->fserrors[j]);
cquantize->fserrors[j]=0;
}
}
if (cquantize)
{
PR_FREEIF(cquantize);
ic->quantize = 0;
}
goto loser;
}
}
return TRUE;
}
/*
** Free up quantizer information attached to ic. If this is the last
** quantizer then free up the sample range limit table.
*/
void
il_free_quantize(il_container *ic)
{
my_cquantize_ptr cquantize = (my_cquantize_ptr) ic->quantize;
int i;
if (cquantize)
{
#ifdef DEBUG
if (il_debug > 5)
ILTRACE(1,("il: 0x%x: free quantize", ic));
#endif
for (i = 0; i < 3; i++)
{
if (cquantize->fserrors[i])
{
PR_FREEIF(cquantize->fserrors[i]);
cquantize->fserrors[i] = 0;
}
}
PR_FREEIF(cquantize);
ic->quantize = 0;
}
}
/* floyd-steinberg dithering */
#ifdef XP_MAC
#ifndef powerc
#pragma peephole on
#endif
#endif
void
il_quantize_fs_dither(il_container *ic, const PRUint8 *mask,
const PRUint8 *input_buf, int x_offset,
PRUint8 XP_HUGE *output_buf, int width)
{
my_cquantize_ptr cquantize;
register LOCFSERROR r_cur, g_cur, b_cur; /* current error or pixel
value */
LOCFSERROR r_belowerr, g_belowerr, b_belowerr; /* error for pixel below
cur */
LOCFSERROR r_bpreverr, g_bpreverr, b_bpreverr; /* error for below/prev
col */
LOCFSERROR r_bnexterr, g_bnexterr, b_bnexterr; /* error for below/next
col */
LOCFSERROR delta;
FSERRPTR r_errorptr, g_errorptr, b_errorptr; /* fserrors[] at column
before current */
const JSAMPLE* input_ptr;
JSAMPLE XP_HUGE * output_ptr;
IL_ColorMap *cmap = &ic->image->header.color_space->cmap;
IL_RGB *map = cmap->map; /* The colormap array. */
IL_RGB *map_entry; /* Current entry in the colormap. */
PRUint8 *lookup_table = (PRUint8 *)cmap->table; /* Lookup table for the colormap. */
const PRUint8 *maskp;
PRUint8 map_index;
int dir; /* 1 for left-to-right, -1 for right-to-left */
JDIMENSION col;
JSAMPLE *range_limit = the_sample_range_limit;
SHIFT_TEMPS
cquantize = (my_cquantize_ptr) ic->quantize;
output_buf += x_offset;
/* Initialize output values to 0 so can process components separately */
if (mask) {
output_ptr = output_buf;
maskp = mask;
for (col = width; col > 0; col--)
*output_ptr++ &= ~*maskp++;
} else {
nsCRT::zero((void XP_HUGE *) output_buf,
(size_t) (width * SIZEOF(JSAMPLE)));
}
input_ptr = input_buf;
output_ptr = output_buf;
maskp = mask;
if (cquantize->on_odd_row) {
int total_offset;
/* work right to left in this row */
input_ptr += 3 * width - 1; /* so point to the blue sample of the
rightmost pixel */
output_ptr += width-1;
dir = -1;
/* => entry after last column */
total_offset = x_offset + (width + 1);
r_errorptr = cquantize->fserrors[0] + total_offset;
g_errorptr = cquantize->fserrors[1] + total_offset;
b_errorptr = cquantize->fserrors[2] + total_offset;
maskp += (width - 1);
}
else {
/* work left to right in this row */
dir = 1;
/* => entry before first column */
r_errorptr = cquantize->fserrors[0] + x_offset;
g_errorptr = cquantize->fserrors[1] + x_offset;
b_errorptr = cquantize->fserrors[2] + x_offset;
}
/* Preset error values: no error propagated to first pixel from left */
r_cur = g_cur = b_cur = 0;
/* and no error propagated to row below yet */
r_belowerr = g_belowerr = b_belowerr = 0;
r_bpreverr = g_bpreverr = b_bpreverr = 0;
for (col = width; col > 0; col--) {
/* cur holds the error propagated from the previous pixel on the
* current line. Add the error propagated from the previous line
* to form the complete error correction term for this pixel, and
* round the error term (which is expressed * 16) to an integer.
* RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
* for either sign of the error value.
* Note: errorptr points to *previous* column's array entry.
*/
r_cur = RIGHT_SHIFT(r_cur + r_errorptr[dir] + 8, 4);
g_cur = RIGHT_SHIFT(g_cur + g_errorptr[dir] + 8, 4);
b_cur = RIGHT_SHIFT(b_cur + b_errorptr[dir] + 8, 4);
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
* The maximum error is +- MAXJSAMPLE; this sets the required size
* of the range_limit array.
*/
if (dir > 0) {
r_cur += GETJSAMPLE(*input_ptr);
r_cur = GETJSAMPLE(range_limit[r_cur]);
input_ptr++;
g_cur += GETJSAMPLE(*input_ptr);
g_cur = GETJSAMPLE(range_limit[g_cur]);
input_ptr++;
b_cur += GETJSAMPLE(*input_ptr);
b_cur = GETJSAMPLE(range_limit[b_cur]);
input_ptr++;
}
else {
b_cur += GETJSAMPLE(*input_ptr);
b_cur = GETJSAMPLE(range_limit[b_cur]);
input_ptr--;
g_cur += GETJSAMPLE(*input_ptr);
g_cur = GETJSAMPLE(range_limit[g_cur]);
input_ptr--;
r_cur += GETJSAMPLE(*input_ptr);
r_cur = GETJSAMPLE(range_limit[r_cur]);
input_ptr--;
}
/* Select output value, accumulate into output code for this pixel */
map_index = COLORMAP_INDEX(lookup_table, r_cur, g_cur, b_cur);
if (mask) {
if (*maskp)
*output_ptr = map_index;
maskp += dir;
} else {
*output_ptr = map_index;
}
/* Compute the actual representation error at this pixel */
map_entry = map + map_index;
r_cur -= GETJSAMPLE(map_entry->red);
g_cur -= GETJSAMPLE(map_entry->green);
b_cur -= GETJSAMPLE(map_entry->blue);
/* Compute error fractions to be propagated to adjacent pixels.
* Add these into the running sums, and simultaneously shift the
* next-line error sums left by 1 column.
*/
r_bnexterr = r_cur;
delta = r_cur * 2;
r_cur += delta; /* form error * 3 */
r_errorptr[0] = (FSERROR) (r_bpreverr + r_cur);
r_cur += delta; /* form error * 5 */
r_bpreverr = r_belowerr + r_cur;
r_belowerr = r_bnexterr;
r_cur += delta; /* form error * 7 */
g_bnexterr = g_cur;
delta = g_cur * 2;
g_cur += delta; /* form error * 3 */
g_errorptr[0] = (FSERROR) (g_bpreverr + g_cur);
g_cur += delta; /* form error * 5 */
g_bpreverr = g_belowerr + g_cur;
g_belowerr = g_bnexterr;
g_cur += delta; /* form error * 7 */
b_bnexterr = b_cur;
delta = b_cur * 2;
b_cur += delta; /* form error * 3 */
b_errorptr[0] = (FSERROR) (b_bpreverr + b_cur);
b_cur += delta; /* form error * 5 */
b_bpreverr = b_belowerr + b_cur;
b_belowerr = b_bnexterr;
b_cur += delta; /* form error * 7 */
/* At this point cur contains the 7/16 error value to be propagated
* to the next pixel on the current line, and all the errors for the
* next line have been shifted over. We are therefore ready to move on.
* Note: the input_ptr has already been advanced.
*/
output_ptr += dir; /* advance output ptr to next column */
r_errorptr += dir; /* advance errorptr to current column */
g_errorptr += dir; /* advance errorptr to current column */
b_errorptr += dir; /* advance errorptr to current column */
}
/* Post-loop cleanup: we must unload the final error value into the
* final fserrors[] entry. Note we need not unload belowerr because
* it is for the dummy column before or after the actual array.
*/
r_errorptr[0] = (FSERROR) r_bpreverr; /* unload prev err into array */
g_errorptr[0] = (FSERROR) g_bpreverr; /* unload prev err into array */
b_errorptr[0] = (FSERROR) b_bpreverr; /* unload prev err into array */
cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
}
#ifdef XP_MAC
#ifndef powerc
#pragma peephole reset
#endif
#endif
/* END code adapted from jpeg library */

File diff suppressed because it is too large Load Diff

View File

@ -1,502 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* if.h --- Top-level image library internal routines
*
* $Id: if.h,v 3.28 2001-06-19 08:47:00 pavlov%netscape.com Exp $
*/
#ifndef _if_h
#define _if_h
/*************************************************/
#ifndef _ifstruct_h
#define M12N
#define IL_INTERNAL
#include "prtypes.h"
#include "prlog.h"
#include "prmem.h"
#include "plstr.h"
#include "prtime.h"
#include "prlong.h"
#include "nsIPresContext.h"
typedef struct _IL_GroupContext IL_GroupContext;
typedef struct _IL_ImageReq IL_ImageReq;
typedef struct il_context_list il_context_list;
typedef struct il_container_list il_container_list;
typedef struct il_container_struct il_container;
#include "il_icons.h" /* Image icons. */
#include "libimg.h" /* Public API to Image Library. */
#include "il_utilp.h" /* Private header for colormap/colorspaces. */
#include "il_util.h" /* Public API for colormaps/colorspaces. */
#include "ilINetContext.h"
#include "ilIURL.h"
#include "ilINetReader.h"
#include "ilIImageRenderer.h"
#include "il.h"
#if defined(XP_WIN) || defined(XP_OS2)
#define _USD 1 /* scanlines upside-down */
#endif
/* For debugging counts of loading, looping and aborted images, needed for
group observer notification. */
/* #define DEBUG_GROUP_OBSERVER */
#ifdef DEBUG
extern int il_debug;
#define ILTRACE(l,t) { if(il_debug>l) {PR_LOG(il_log_module, 1, t);} }
#else
#define ILTRACE(l,t) {}
#endif
extern PRLogModuleInfo *il_log_module;
#define FREE_IF_NOT_NULL(x) do {if (x) {PR_FREEIF(x); (x) = NULL;}} while (0)
#include "prtypes.h" /* for IS_LITTLE_ENDIAN / IS_BIG_ENDIAN */
/* The imagelib labels bits in a 32-bit word from 31 on the left to 0 on the right.
This macro performs the necessary conversion to make that definition work on
little-endian platforms */
#if defined(IS_LITTLE_ENDIAN)
# define M32(bit) ((bit) ^ 0x18)
#elif defined(IS_BIG_ENDIAN)
# define M32(bit) (bit)
#else
ENDIANNESS UNKNOWN!
#endif
/* Don't change these unless you know what you're doing or you will
break 16-bit binaries. */
#define MAX_IMAGE_WIDTH 8000
#define MAX_IMAGE_HEIGHT 8000
/* MAX and MIN are almost universal, but be paranoid and use our
definitions. */
#ifdef MAX
#undef MAX
#endif
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#ifdef MIN
#undef MIN
#endif
#define MIN(x, y) ((x) < (y) ? (x) : (y))
/* types that can be used to, for example, differentiate chrome
images from others */
#define TYPE_DEFAULT 0 // unspecified
#define TYPE_CHROME 1 // chrome URL
/* Conversion of imglib errors to XPCOM errors */
#define NS_CONVERT_ERROR_CODE(e) \
(NS_ERROR_GENERATE((e) ? NS_ERROR_SEVERITY_ERROR : NS_ERROR_SEVERITY_SUCCESS, NS_ERROR_MODULE_IMGLIB, (e) & 0xFFFF))
/* Last output pass of an image */
#define IL_FINAL_PASS -1
/* Nature of the conversion from source image colorspace to target image
colorspace. */
typedef enum _IL_ConversionType {
IL_TrueToTrue = 0x09,
IL_TrueToPseudo = 0x0a,
IL_TrueToGrey = 0x0c,
IL_PseudoToTrue = 0x11,
IL_PseudoToPseudo = 0x12,
IL_PseudoToGrey = 0x14,
IL_GreyToTrue = 0x21,
IL_GreyToPseudo = 0x22,
IL_GreyToGrey = 0x24
} IL_ConversionType;
typedef void (*il_converter)(il_container *ic, const PRUint8 *mask,
const PRUint8 *sp, int x_offset,
int num, void XP_HUGE *out);
enum icstate {
IC_VIRGIN = 0x00, /* Newly-created container */
IC_START = 0x01, /* Requested stream from netlib, but no data yet */
IC_STREAM = 0x02, /* Stream opened, but insufficient data
received to determine image size */
IC_SIZED = 0x04, /* Image size determined - still loading */
IC_MULTI = 0x06, /* Same as IC_SIZED, but for second or
subsequent images in multipart MIME */
IC_NOCACHE = 0x11, /* Image deferred for loading later */
IC_COMPLETE = 0x20, /* Image loaded - no errors */
IC_BAD = 0x21, /* Corrupt or illegal image data */
IC_INCOMPLETE = 0x22, /* Partially loaded image data */
IC_MISSING = 0x23, /* No such file on server */
IC_ABORT_PENDING= 0x24 /* Image download abort in progress */
};
/* Still receiving data from the netlib ? */
#define IMAGE_CONTAINER_ACTIVE(ic) ((ic)->state <= IC_MULTI)
/* Force memory cache to be flushed ? */
#define FORCE_RELOAD(reload_method) \
(reload_method = DONT_USE_IMG_CACHE)
/* Simple list of image contexts. */
struct il_context_list {
IL_GroupContext *img_cx;
struct il_context_list *next;
};
/* Simple list of image containers. */
struct il_container_list {
il_container *ic;
struct il_container_list *next;
};
/* There is one il_container per real image */
struct il_container_struct {
il_container *next; /* Cache bidirectional linked list */
il_container *prev;
ilIURL *url;
char *url_address; /* Same as url->address if there is no redirection*/
PRUint32 hash;
PRUint32 urlhash;
enum icstate state;
int sized;
int moz_type; /* TYPE_CHROME, etc. */
int is_alone; /* only image on a page */
int is_in_use; /* Used by some context */
int32 loop_count; /* Remaining number of times to repeat image,
-1 means loop infinitely */
int is_looping; /* TRUE if this is the second or subsequent
pass of an animation. */
nsImageAnimation animate_request; /* Set in nsPresContext.
normal = 0; one frame = 1; one loop = 2 */
int is_aborted; /* True if aborted by NetLib. */
PRPackedBool is_url_loading;/* TRUE if NetLib is currently loading the URL. */
int is_multipart; /* TRUE if stream is known to be multipart. */
int multi; /* Known to be either multipart-MIME
or multi-image format */
int new_data_for_fe; /* Any Scanlines that FE doesn't know about ? */
int update_start_row; /* Scanline range to send to FE */
int update_end_row;
PRUint32 bytes_consumed; /* Bytes read from the stream so far */
NI_PixmapHeader *src_header; /* Source image header information. */
IL_Pixmap *image; /* Destination image pixmap structure. */
IL_Pixmap *mask; /* Destination mask pixmap structure. */
char* type; /* mimetype string ptn 10.13.99*/
void *ds; /* decoder's private data */
il_converter converter;
void *quantize; /* quantizer's private data */
class nsIImgDecoder *imgdec;
class ImgDCallbk *imgdcb;
void *row_output_timeout;
PRUint8 *scalerow;
int pass; /* pass (scan #) of a multi-pass image.
Used for interlaced GIFs & p-JPEGs */
int forced;
PRUint32 content_length;
PRUint32 dest_width, dest_height; /* Target dimensions of the image */
PRPackedBool natural_size; /* True if the image is decoded to its natural
size. */
PRPackedBool aspect_distorted; /* True if the image undergoes aspect ratio
distortion during decoding. */
IL_IRGB *background_color; /* The requested background color for this
image (only applies if the image is
determined to be transparent.) A mask will
be created for a transparent image only if
no background color was requested. */
char *comment; /* Human-readable text stored in image */
int comment_length;
int colormap_serial_num; /* serial number of last installed colormap */
int dont_use_custom_palette;
int rendered_with_custom_palette;
IL_DitherMode dither_mode; /* ilDither or ilClosestColor */
IL_GroupContext *img_cx; /* The context in which this image was created.
Used during image decoding only. */
IL_DisplayType display_type; /* Type of display for which the container
is created. */
ilIImageRenderer *img_cb;
ilINetContext *net_cx; /* Context which initiated this transfer. */
IL_ImageReq *clients; /* List of clients of this container. */
IL_ImageReq *lclient; /* Last client in the client list. */
il_context_list *img_cx_list; /* List of contexts which have clients of
this container. */
IL_Rect displayable_rect; /* The area of the image pixmap which is in a
displayable state. Used as a filter
between client calls to IL_DisplaySubImage
and Image Library calls to DisplayPixmap, in
the event that the client requests us to
draw a part of the pixmap that has yet to
be decoded. */
time_t expires; /* Expiration date for the corresponding URL */
#ifdef DEBUG
PRTime start_time;
#endif
char *fetch_url; /* actual url address used */
};
typedef enum { ilUndefined, ilCI, ilGrey, ilRGB } il_mode;
typedef enum il_draw_mode
{
ilErase, /* Transparent areas are reset to background */
ilOverlay /* Transparent areas overlay existing data */
} il_draw_mode;
/* A context for a group of images. */
struct _IL_GroupContext {
ilIImageRenderer *img_cb;
void *dpy_cx; /* An opaque pointer passed back to all
callbacks in the interface vtable. */
IL_DisplayType display_type; /* IL_Console, IL_Printer or IL_PostScript. */
IL_ColorSpace *color_space; /* Display colorspace. */
/* Preferences */
PRPackedBool progressive_display; /* If TRUE, images are displayed while
loading */
IL_DitherMode dither_mode; /* IL_ClosestColor, IL_Dither or IL_Auto. */
int dontscale; /* Used for Macs, which do their own scaling */
int nolowsrc; /* If TRUE, never display LOSRC images */
/* Per-context state */
il_container_list *container_list;/* List of containers in this context. */
int32 num_containers; /* Number of containers in this context. */
int32 num_loading; /* Number of containers which are currently
loading. */
int32 num_looping; /* Number of containers which are currently
looping i.e. on second or subsequent
iteration of an animation. */
int32 num_aborted; /* Number of containers which have aborted
so far. */
XP_ObserverList obs_list; /* List of observers for this image group. */
struct _IL_GroupContext *next; /* Next entry in a list of image group
contexts. */
};
/* Tag to indicate whether a request represents an image or an icon. */
typedef enum
{
IL_IMAGE,
IL_ICON
} IL_ImageType;
/* This is Image Library's internal representation of a client's image request.
It represents a handle on a specific instance of an image container. */
struct _IL_ImageReq {
il_container *ic; /* The image container for this request (may
be shared with other requests.) */
IL_ImageType image_type; /* Image or icon. */
IL_GroupContext *img_cx; /* The group context to which this request
belongs. */
ilINetContext *net_cx; /* A clone of the net context which the image
library was given when this image handle was
created. This serves as a backup in case
the image container's net_cx becomes invalid,
(for example, when the client for which the
container was initially created is destroyed.) */
PRPackedBool stopped; /* TRUE - if user hit "Stop" button */
int is_view_image; /* non-zero if client is
internal-external-reconnect */
XP_ObserverList obs_list; /* List of observers for this request. */
struct _IL_ImageReq *next; /* Next entry in a list of image requests. */
};
/********************** end of ifstruct_h test *********************************************************/
#endif
extern int il_debug;
extern PRUint8 il_identity_index_map[];
extern void il_delete_container(il_container *ic);
extern il_container *il_removefromcache(il_container *ic);
extern void il_image_abort(il_container *ic);
extern void il_image_complete(il_container *ic);
extern PRBool il_image_stopped(il_container *ic);
extern ilINetReader *IL_NewNetReader(il_container *ic);
extern il_container *IL_GetNetReaderContainer(ilINetReader *reader);
extern int IL_StreamWriteReady(il_container *ic);
extern int IL_StreamFirstWrite(il_container *ic, const unsigned char *str, int32 len);
extern int IL_StreamWrite(il_container *ic, const unsigned char *str, int32 len);
extern void IL_StreamAbort(il_container *ic, int status);
extern void IL_StreamComplete(il_container *ic, PRBool is_multipart);
extern void IL_NetRequestDone(il_container *ic, ilIURL *urls, int status);
extern PRBool IL_StreamCreated(il_container *ic, ilIURL *urls, char* type);
/* Allocate and initialize the destination image's transparent_pixel with
the Image Library's preferred transparency color i.e. the background color
passed into IL_GetImage. The image decoder is encouraged to use this
color, but may opt not to do so. */
extern int il_init_image_transparent_pixel(il_container *ic);
/* Destroy the destination image's transparent pixel. */
extern void il_destroy_image_transparent_pixel(il_container *ic);
/* Inform the Image Library of the source image's dimensions. This function
determines the size of the destination image, and calls the front end to
allocate storage for the destination image's bits. If the source image's
transparent pixel is set, and a background color was not specified for this
image request, then a mask will also be allocated for the destination
image. */
extern int il_size(il_container *);
extern void il_dimensions_notify(il_container *ic, int dest_width, int dest_height);
extern int il_setup_quantize(void);
extern int il_init_quantize(il_container *ic);
extern void il_free_quantize(il_container *ic);
extern void il_quantize_fs_dither(il_container * ic,
const PRUint8* mask,
const PRUint8 *samp_in,
int x_offset,
PRUint8 XP_HUGE *samp_out,
int width);
extern PRBool il_emit_row(il_container *ic, PRUint8 *buf, PRUint8 *rgbbuf,
int start_column, int len, int row, int row_count,
il_draw_mode draw_mode, int ipass);
extern void il_flush_image_data(il_container *ic);
extern PRBool il_setup_color_space_converter(il_container *ic);
extern void il_convert_image_to_default_colormap(il_container *ic);
#ifndef M12N /* XXXM12N Fix custom colormaps. */
extern int il_set_color_palette(MWContext *cx, il_container *ic);
#endif /* M12N */
extern PRBool il_reset_palette(il_container *ic);
extern void il_reverse_bits(PRUint8 *buf, int n);
extern void il_reconnect(il_container *cx);
extern void il_abort_reconnect(void);
/* Get an image container from the image cache. If no cache entry exists,
then create and return a new container. */
extern il_container
*il_get_container(IL_GroupContext *image_context,
ImgCachePolicy reload_cache_policy,
const char *image_url,
IL_IRGB *background_color,
IL_DitherMode dither_mode,
int req_depth,
int req_width,
int req_height);
/* Destroy an IL_Pixmap. */
extern void
il_destroy_pixmap(ilIImageRenderer *img_cb, IL_Pixmap *pixmap);
extern PRUint32 il_hash(const char *ubuf);
extern void il_partial(il_container *ic, int row, int row_count, int pass);
extern void il_scour_container(il_container *ic);
extern void il_adjust_cache_fullness(int32 bytes);
extern PRBool il_add_client(IL_GroupContext *img_cx, il_container *ic,
IL_ImageReq *image_req, int is_view_image);
extern PRBool il_delete_client(il_container *ic, IL_ImageReq *image_req);
extern void il_reduce_image_cache_size_to(PRUint32 new_size);
/************************ Image observer notifiers ***************************/
/* Notify observers of image progress. */
extern void
il_progress_notify(il_container *ic);
/* Notify observers that the image pixmap has been updated. */
extern void
il_pixmap_update_notify(il_container *ic);
/* Notify observers that the image has finished decoding. */
extern void
il_image_complete_notify(il_container *ic);
/* Notify observers that one frame of image/animation has finished decoding. */
extern void
il_frame_complete_notify(il_container *ic);
/* Notify observers of a cached image that has already completed decoding.
Note that this notification is per image request and not per image
container. */
extern void
il_cache_return_notify(IL_ImageReq *image_req);
/* Notify observers that the image request is being destroyed. This
provides an opportunity for observers to remove themselves from the
observer callback list and to do any related cleanup. */
extern void
il_image_destroyed_notify(IL_ImageReq *image_req);
/********************* Image group observer notifier *************************/
/* Notify observers that images have started/stopped loading in the context,
or started/stopped looping in the context. */
extern void
il_group_notify(IL_GroupContext *img_cx, XP_ObservableMsg message);
#endif /* _if_h */

View File

@ -1,200 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "if.h"
#include "ilINetReader.h"
#include "nsCRT.h"
class NetReaderImpl : public ilINetReader {
public:
NetReaderImpl(il_container *aContainer);
virtual ~NetReaderImpl();
NS_DECL_ISUPPORTS
NS_IMETHOD WriteReady(PRUint32 *max_read);
NS_IMETHOD FirstWrite(const unsigned char *str, int32 len, char* url);
NS_IMETHOD Write(const unsigned char *str, int32 len);
NS_IMETHOD StreamAbort(int status);
NS_IMETHOD StreamComplete(PRBool is_multipart);
NS_IMETHOD NetRequestDone(ilIURL *urls, int status);
virtual PRBool StreamCreated(ilIURL *urls, char* type);
virtual PRBool IsMulti();
NS_IMETHOD FlushImgBuffer();
// XXX Need to fix this to make sure return type is nsresult
il_container *GetContainer() {return ilContainer;};
// il_container *SetContainer(il_container *ic) {ilContainer=ic; return ic;};
private:
il_container *ilContainer;
};
NetReaderImpl::NetReaderImpl(il_container *aContainer)
{
NS_INIT_REFCNT();
ilContainer = aContainer;
}
NetReaderImpl::~NetReaderImpl()
{
}
NS_IMPL_THREADSAFE_ISUPPORTS1(NetReaderImpl, ilINetReader)
NS_IMETHODIMP
NetReaderImpl::WriteReady(PRUint32* max_read)
{
if (ilContainer != NULL) {
*max_read =IL_StreamWriteReady(ilContainer);
}
return NS_OK;
}
NS_IMETHODIMP
NetReaderImpl::FirstWrite(const unsigned char *str, int32 len, char* url)
{
int ret = 0;
if (ilContainer != NULL) {
FREE_IF_NOT_NULL(ilContainer->fetch_url);
if (url) {
ilContainer->fetch_url = nsCRT::strdup(url);
}
else {
ilContainer->fetch_url = NULL;
}
ret = IL_StreamFirstWrite(ilContainer, str, len);
if(ret == 0)
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
NetReaderImpl::Write(const unsigned char *str, int32 len)
{
int ret = 0;
if (ilContainer != NULL) {
ret= IL_StreamWrite(ilContainer, str, len);
if(ret >= 0)
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
NetReaderImpl::StreamAbort(int status)
{
if (ilContainer != NULL) {
IL_StreamAbort(ilContainer, status);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
NetReaderImpl::StreamComplete(PRBool is_multipart)
{
if (ilContainer != NULL) {
IL_StreamComplete(ilContainer, is_multipart);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
NS_IMETHODIMP
NetReaderImpl::NetRequestDone(ilIURL *urls, int status)
{
if (ilContainer != NULL) {
IL_NetRequestDone(ilContainer, urls, status);
return NS_OK;
}
return NS_ERROR_FAILURE;
}
PRBool
NetReaderImpl::StreamCreated(ilIURL *urls, char* type)
{
if (ilContainer != NULL) {
return IL_StreamCreated(ilContainer, urls, type);
}
else {
return PR_FALSE;
}
}
PRBool
NetReaderImpl::IsMulti()
{
if (ilContainer != NULL) {
return (PRBool)(ilContainer->multi > 0);
}
else {
return PR_FALSE;
}
}
NS_IMETHODIMP
NetReaderImpl::FlushImgBuffer()
{
if (ilContainer != NULL) {
il_flush_image_data(ilContainer);
return NS_OK;
}
else
return NS_ERROR_FAILURE;
}
ilINetReader *
IL_NewNetReader(il_container *ic)
{
ilINetReader *reader = new NetReaderImpl(ic);
if (reader != NULL) {
NS_ADDREF(reader);
}
return reader;
}
il_container *
IL_GetNetReaderContainer(ilINetReader *reader)
{
if (reader != NULL) {
return ((NetReaderImpl *)reader)->GetContainer();
}
else {
return NULL;
}
}

View File

@ -1,498 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_util.c Colormap and colorspace utilities.
*
* $Id: il_util.cpp,v 3.9 2001-06-19 08:47:03 pavlov%netscape.com Exp $
*/
#include "nsCRT.h"
#include "prtypes.h"
#include "prmem.h"
#include "il_util.h" /* Public API. */
#include "il_utilp.h" /* Private header file. */
/************************* Colormap utilities ********************************/
/* Create a new color cube with the specified dimensions, starting at the
given base_offset. The total number of colors in the colormap will be
base_offset + red_size * green_size * blue_size. The caller is
responsible for filling in its reserved colors, 0, 1, ..., base_offset-1.
Note: the lookup table used here is of the form we will use when dithering
to an arbitrary palette. */
static IL_ColorMap *
il_NewColorCube(PRUint32 red_size, PRUint32 green_size, PRUint32 blue_size,
PRUint32 base_offset)
{
PRUint8 r, g, b, map_index;
PRUint32 i, j, k, size, red_offset, green_offset, dmax_val;
PRUint32 trm1, tgm1, tbm1, dtrm1, dtgm1, dtbm1;
PRUint32 crm1, cgm1, cbm1, dcrm1, dcgm1, dcbm1;
PRUint8 *lookup_table, *ptr, *done;
IL_RGB *map;
IL_ColorMap *cmap;
/* Colormap size and offsets for computing the colormap indices. */
size = base_offset + red_size * green_size * blue_size;
if (size > CUBE_MAX_SIZE)
return PR_FALSE;
red_offset = green_size * blue_size;
green_offset = blue_size;
/* Operation on lookup table dimensions. */
trm1 = LOOKUP_TABLE_RED - 1; dtrm1 = trm1 << 1;
tgm1 = LOOKUP_TABLE_GREEN - 1; dtgm1 = tgm1 << 1;
tbm1 = LOOKUP_TABLE_BLUE - 1; dtbm1 = tbm1 << 1;
/* Operations on color cube dimensions. */
crm1 = red_size - 1; dcrm1 = crm1 << 1;
cgm1 = green_size - 1; dcgm1 = cgm1 << 1;
cbm1 = blue_size - 1; dcbm1 = cbm1 << 1;
/* Operation on target RGB color space dimensions. */
dmax_val = 255 << 1;
/* We may want to add entries to the map array subsequently, so always
allocate space for a full palette. */
map = (IL_RGB *)PR_Calloc(256, sizeof(IL_RGB));
if (!map)
return PR_FALSE;
lookup_table = (PRUint8 *)PR_Calloc(LOOKUP_TABLE_SIZE, 1);
if (!lookup_table)
return PR_FALSE;
done = (PRUint8 *)PR_Calloc(size, 1);
if (!done)
return PR_FALSE;
ptr = lookup_table;
for (i = 0; i < LOOKUP_TABLE_RED; i++)
for (j = 0; j < LOOKUP_TABLE_GREEN; j++)
for (k = 0; k < LOOKUP_TABLE_BLUE; k++) {
/* Scale indices down to cube coordinates. */
r = (PRUint8) (CUBE_SCALE(i, dcrm1, trm1, dtrm1));
g = (PRUint8) (CUBE_SCALE(j, dcgm1, tgm1, dtgm1));
b = (PRUint8) (CUBE_SCALE(k, dcbm1, tbm1, dtbm1));
/* Compute the colormap index. */
map_index =(PRUint8)( r * red_offset + g * green_offset + b +
base_offset);
/* Fill out the colormap entry for this index if we haven't
already done so. */
if (!done[map_index]) {
/* Scale from cube coordinates up to 8-bit RGB values. */
map[map_index].red =
(PRUint8) (CUBE_SCALE(r, dmax_val, crm1, dcrm1));
map[map_index].green =
(PRUint8) (CUBE_SCALE(g, dmax_val, cgm1, dcgm1));
map[map_index].blue =
(PRUint8) (CUBE_SCALE(b, dmax_val, cbm1, dcbm1));
/* Mark as done. */
done[map_index] = 1;
}
/* Fill in the lookup table entry with the colormap index. */
*ptr++ = map_index;
}
PR_FREEIF(done);
cmap = PR_NEWZAP(IL_ColorMap);
if (!cmap) {
PR_FREEIF(map);
PR_FREEIF(lookup_table);
return NULL;
}
cmap->num_colors = size;
cmap->map = map;
cmap->index = NULL;
cmap->table = (void *)lookup_table;
return cmap;
}
/* Determine allocation of desired colors to components, and fill in Ncolors[]
array to indicate choice. Return value is total number of colors (product
of Ncolors[] values). */
static int
select_ncolors(int Ncolors[],
int out_color_components,
int desired_number_of_colors)
{
int nc = out_color_components; /* number of color components */
int max_colors = desired_number_of_colors;
int total_colors, iroot, i, j;
long temp;
/* XXX - fur . Is this right ? */
static const int RGB_order[3] = { 2, 1, 0 };
/* We can allocate at least the nc'th root of max_colors per component. */
/* Compute floor(nc'th root of max_colors). */
iroot = 1;
do {
iroot++;
temp = iroot; /* set temp = iroot ** nc */
for (i = 1; i < nc; i++)
temp *= iroot;
} while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
iroot--; /* now iroot = floor(root) */
/* Must have at least 2 color values per component */
if (iroot < 2)
return -1;
/* Initialize to iroot color values for each component */
total_colors = 1;
for (i = 0; i < nc; i++)
{
Ncolors[i] = iroot;
total_colors *= iroot;
}
/* We may be able to increment the count for one or more components without
* exceeding max_colors, though we know not all can be incremented.
* In RGB colorspace, try to increment G first, then R, then B.
*/
for (i = 0; i < nc; i++)
{
j = RGB_order[i];
/* calculate new total_colors if Ncolors[j] is incremented */
temp = total_colors / Ncolors[j];
temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
if (temp > (long) max_colors)
break; /* won't fit, done */
Ncolors[j]++; /* OK, apply the increment */
total_colors = (int) temp;
}
return total_colors;
}
/* Create a new color map consisting of a given set of reserved colors, and
a color cube. num_colors represents the requested size of the colormap,
including the reserved colors. The actual number of colors in the colormap
could be less depending on the color cube that is allocated.
The Image Library will only make use of entries in the color cube. This
function represents the current state of affairs, and it will eventually
be replaced when the Image Library has the capability to dither to an
arbitrary palette. */
IL_IMPLEMENT(IL_ColorMap *)
IL_NewCubeColorMap(IL_RGB *reserved_colors, PRUint16 num_reserved_colors,
PRUint16 num_colors)
{
int i;
IL_RGB *map;
IL_ColorMap *cmap;
int Ncolors[3]; /* Size of the color cube. */
int num_cube_colors;
/* Determine the size of the color cube. */
num_cube_colors = select_ncolors(Ncolors, 3,
num_colors - num_reserved_colors);
/* Create the color cube. */
cmap = il_NewColorCube(Ncolors[0], Ncolors[1], Ncolors[2],
num_reserved_colors);
if(!cmap)
return NULL;
/* Fill in the reserved colors. */
map = cmap->map;
for (i = 0; i < num_reserved_colors; i++) {
map[i].red = reserved_colors[i].red;
map[i].green = reserved_colors[i].green;
map[i].blue = reserved_colors[i].blue;
}
return cmap;
}
/* Create an optimal fixed palette of the specified size, starting with
the given set of reserved colors. */
IL_IMPLEMENT(IL_ColorMap *)
IL_NewOptimalColorMap(IL_RGB *reserved_colors, PRUint16 num_reserved_colors,
PRUint16 num_colors)
{
/* XXXM12N Implement me. */
return NULL;
}
/* Create an empty colormap. The caller is responsible for filling in the
colormap entries. */
IL_IMPLEMENT(IL_ColorMap *)
IL_NewColorMap(void)
{
IL_RGB *map;
IL_ColorMap *cmap;
cmap = PR_NEWZAP(IL_ColorMap);
if (!cmap)
return NULL;
/* We always allocate space for a full palette. */
map = (IL_RGB *)PR_Calloc(256, sizeof(IL_RGB));
if (!map) {
PR_FREEIF(cmap);
return NULL;
}
cmap->num_colors = 0;
cmap->map = map;
cmap->index = NULL;
cmap->table = NULL;
return cmap;
}
/* Append the specified color to an existing IL_ColorMap, returning TRUE if
successful. The position of the new color in the IL_ColorMap's map array
is returned in new_color->index. The caller should also update the
corresponding entry in the IL_ColorMap's index array,
cmap->index[new_color->index], if the actual colormap indices do not
correspond to the order of the entries in the map array.
Note: For now, at least, this function does not cause the Image Library's
lookup table to be altered, so the Image Library will continue to dither
to the old colormap. Therefore, the current purpose of this function is
to add colors (such as a background color for transparent images) which
are not a part of the Image Library's color cube. */
IL_IMPLEMENT(int)
IL_AddColorToColorMap(IL_ColorMap *cmap, IL_IRGB *new_color)
{
int max_colors = 256;
int32 num_colors = cmap->num_colors;
IL_RGB *map = cmap->map;
IL_RGB *map_entry;
if (num_colors > max_colors)
return PR_FALSE;
map_entry = map + num_colors;
map_entry->red = new_color->red;
map_entry->green = new_color->green;
map_entry->blue = new_color->blue;
new_color->index = (PRUint8) num_colors;
cmap->num_colors++;
return PR_TRUE;
}
/* Free all memory associated with a given colormap.
Note: This should *not* be used to destroy a colormap once it has been
passed into IL_CreatePseudoColorSpace. Use IL_ReleaseColorSpace instead */
IL_IMPLEMENT(void)
IL_DestroyColorMap (IL_ColorMap *cmap)
{
if (cmap) {
PR_FREEIF(cmap->map);
PR_FREEIF(cmap->index);
PR_FREEIF(cmap->table);
PR_FREEIF(cmap);
}
}
/* Reorder the entries in a colormap. new_order is an array mapping the old
indices to the new indices. */
IL_IMPLEMENT(void)
IL_ReorderColorMap(IL_ColorMap *cmap, PRUint16 *new_order)
{
}
/************************** Colorspace utilities *****************************/
/* Create a new True-colorspace of the dimensions specified by IL_RGBBits and
set the reference count to 1. The pixmap_depth is the sum of the bits
assigned to the three color channels, plus any additional allowance that
might be necessary, e.g. for an alpha channel, or for alignment. Note: the
contents of the IL_RGBBits structure will be copied, so they need not be
preserved after the call to IL_CreateTrueColorSpace. */
IL_IMPLEMENT(IL_ColorSpace *)
IL_CreateTrueColorSpace(IL_RGBBits *rgb, PRUint8 pixmap_depth)
{
IL_ColorSpace *color_space;
color_space = PR_NEWZAP(IL_ColorSpace);
if (!color_space)
return NULL;
color_space->type = NI_TrueColor;
/* RGB bit allocation and offsets. */
nsCRT::memcpy(&color_space->bit_alloc.rgb, rgb, sizeof(IL_RGBBits));
color_space->pixmap_depth = pixmap_depth; /* Destination image depth. */
/* Create the private part of the color_space */
color_space->private_data = (void *)PR_NEWZAP(il_ColorSpaceData);
if (!color_space->private_data) {
PR_FREEIF(color_space);
return NULL;
}
color_space->ref_count = 1;
return color_space;
}
/* Create a new Pseudo-colorspace using the given colormap and set the
reference count to 1. The index_depth is the bit-depth of the colormap
indices (typically 8), while the pixmap_depth is the index_depth plus any
additional allowance that might be necessary e.g. for an alpha channel, or
for alignment. Note: IL_ColorMaps passed into IL_CreatePseudoColorSpace
become a part of the IL_ColorSpace structure. The IL_ColorMap pointer is
invalid after the the call to IL_CreatePseudoColorSpace, so it should
neither be accessed, nor destroyed using IL_DestroyColorMap. Access to
the colormap, *is* available through the colormap member of the
IL_ColorSpace. Memory associated with the colormap will be freed by
IL_ReleaseColorSpace when the reference count reaches zero. */
IL_IMPLEMENT(IL_ColorSpace *)
IL_CreatePseudoColorSpace(IL_ColorMap *cmap, PRUint8 index_depth,
PRUint8 pixmap_depth)
{
IL_ColorSpace *color_space;
color_space = PR_NEWZAP(IL_ColorSpace);
if (!color_space)
return NULL;
color_space->type = NI_PseudoColor;
color_space->bit_alloc.index_depth = index_depth;
color_space->pixmap_depth = pixmap_depth;
/* Copy the contents of the IL_ColorMap structure. This copies the map
and table pointers, not the arrays themselves. */
nsCRT::memcpy(&color_space->cmap, cmap, sizeof(IL_ColorMap));
PR_FREEIF(cmap);
/* Create the private part of the color_space */
color_space->private_data = (void *)PR_NEWZAP(il_ColorSpaceData);
if (!color_space->private_data) {
PR_FREEIF(color_space);
return NULL;
}
color_space->ref_count = 1;
return color_space;
}
/* Create a new Greyscale-colorspace of depth specified by index_depth and
set the reference count to 1. The pixmap_depth is the index_depth plus
any additional allowance that might be necessary e.g. for an alpha channel,
or for alignment. */
PRBool
IL_CreateGreyScaleColorSpace(PRUint8 index_depth, PRUint8 pixmap_depth, IL_ColorSpace **color_space_ptr)
{
IL_ColorSpace *color_space;
*color_space_ptr = PR_NEWZAP(IL_ColorSpace);
if (!*color_space_ptr)
return PR_FALSE;
color_space = *color_space_ptr;
color_space->type = NI_GreyScale;
color_space->bit_alloc.index_depth = index_depth;
color_space->pixmap_depth = pixmap_depth;
color_space->cmap.num_colors = (1 << index_depth);
/* Create the private part of the color_space */
color_space->private_data = (void *)PR_NEWZAP(il_ColorSpaceData);
if (!color_space->private_data) {
PR_FREEIF(*color_space_ptr);
return PR_FALSE;
}
color_space->ref_count = 1;
return PR_TRUE;
}
/* Decrements the reference count for an IL_ColorSpace. If the reference
count reaches zero, all memory associated with the colorspace (including
any colormap associated memory) will be freed. */
IL_IMPLEMENT(void)
IL_ReleaseColorSpace(IL_ColorSpace *color_space)
{
color_space->ref_count--;
if (color_space->ref_count == 0) {
IL_ColorMap *cmap = &color_space->cmap;
il_ColorSpaceData *private_data =
(il_ColorSpaceData *)color_space->private_data;
/* Free any colormap associated memory. */
if (cmap->map) {
PR_FREEIF(cmap->map);
cmap->map = NULL;
}
if (cmap->index) {
PR_FREEIF(cmap->index);
cmap->index = NULL;
}
if (cmap->table) {
PR_FREEIF(cmap->table);
cmap->table = NULL;
}
if (private_data) {
/* Free any RGB depth conversion maps. */
if (private_data->r8torgbn) {
PR_FREEIF(private_data->r8torgbn);
private_data->r8torgbn = NULL;
}
if (private_data->g8torgbn) {
PR_FREEIF(private_data->g8torgbn);
private_data->g8torgbn = NULL;
}
if (private_data->b8torgbn) {
PR_FREEIF(private_data->b8torgbn);
private_data->b8torgbn = NULL;
}
/* Free the il_ColorSpaceData */
PR_FREEIF(private_data);
color_space->private_data = NULL;
}
/* Free the IL_ColorSpace structure. */
PR_FREEIF(color_space);
}
}
/* Increment the reference count for an IL_ColorSpace. */
IL_IMPLEMENT(void)
IL_AddRefToColorSpace(IL_ColorSpace *color_space)
{
color_space->ref_count++;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,111 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape 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/NPL/
#
# 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 Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
#
#------------------------------------------------------------------------
#
# Makefile to build the IMGLIB LIB
#
#------------------------------------------------------------------------
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
#
# Make sure we have MOZILLA_CLIENT defined so we get the
# proper JS includes
#
LCFLAGS = $(LCFLAGS) -DMOZILLA_CLIENT
!ifdef BUILD_DEBUG_GC
LCFLAGS = $(LCFLAGS) -DDEBUG_GC
!endif
LCFLAGS = $(LCFLAGS) /TP
LLIBS= $(LIBNSPR) \
$(DIST)\lib\util.lib \
$(DIST)\lib\xpcom.lib \
!ifdef NU_CACHE
$(DIST)\lib\cache.lib \
!endif
$(NULL)
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
LIBRARY_NAME=img$(MOZ_BITS)$(VERSION_NUMBER)
LIBRARY_1NAME=img$(MOZ_BITS)$(VERSION_NUMBER)
PDBFILE=$(LIBRARY_NAME).pdb
MAPFILE=$(LIBRARY_NAME).map
!if "$(MOZ_BITS)" == "16"
DEFFILE=$(LIBRARY_1NAME).def
!endif
EXPORT_LIBRARY=1
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
MODULE=img
DEPTH=..\..\..
LOCAL_INCLUDES=-I../public_com -I.
###
CPPSRCS=color.cpp colormap.cpp dither.cpp if.cpp ilclient.cpp il_util.cpp \
ilNetReader.cpp scale.cpp xpcompat.cpp
CPP_OBJS=.\$(OBJDIR)\color.obj .\$(OBJDIR)\colormap.obj \
.\$(OBJDIR)\dither.obj .\$(OBJDIR)\if.obj \
.\$(OBJDIR)\ilclient.obj .\$(OBJDIR)\il_util.obj \
.\$(OBJDIR)\ilNetReader.obj \
.\$(OBJDIR)\scale.obj \
.\$(OBJDIR)\xpcompat.obj \
#
#note: jpeg export directory needed for dithering in imglib.
##
!if "$(MOZ_BITS)" != "16"
LINCS= -I$(XPDIST)\public\nspr -I$(XPDIST)\public\jpeg \
-I$(XPDIST)\public\util -I$(XPDIST)\public\img \
-I$(XPDIST)\public\raptor \
!ifdef NU_CACHE
-I$(XPDIST)\public\cache \
!endif
-I$(XPDIST)\public\xpcom
!endif
include <$(DEPTH)\config\rules.mak>

View File

@ -1,166 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
#include "nsISupports.h"
#include "nsImgDecCID.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
NS_DEFINE_CID(kGIFDecoderCID, NS_IMGDECODER_CID);
NS_DEFINE_CID(kJPGDecoderCID, NS_IMGDECODER_CID);
class ImgFactoryImpl : public nsIFactory
{
public:
ImgFactoryImpl(const nsCID &aClass, const char* className, const char* contractID);
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~ImgFactoryImpl();
protected:
nsCID mClassID;
const char* mClassName;
const char* mContractID;
};
/*---------------------*/
ImgFactoryImpl::ImgFactoryImpl(const nsCID &aClass,
const char* className,
const char* contractID)
: mClassID(aClass), mClassName(className), mContractID(contractID)
{
NS_INIT_REFCNT();
}
ImgFactoryImpl::~ImgFactoryImpl()
{
}
NS_IMETHODIMP
ImgFactoryImpl::QueryInterface(const nsIID &aIID, void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aResult = nsnull;
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(ImgFactoryImpl);
NS_IMPL_RELEASE(ImgFactoryImpl);
extern nsresult
NS_NewDefaultResource(nsIRDFResource** aResult);
NS_IMETHODIMP
ImgFactoryImpl::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
if (aOuter)
return NS_ERROR_NO_AGGREGATION;
*aResult = nsnull;
nsresult rv;
PRBool wasRefCounted = PR_TRUE;
nsISupports *inst = nsnull;
if (mClassID.Equals(kGIFDecoderCID)) {
if (NS_FAILED(rv = NS_NewGIFDecoder((nsIGIFDecoder**) &inst)))
return rv;
}
if (mClassID.Equals(kJPEGDecoderCID)) {
if (NS_FAILED(rv = NS_NewJPGDecoder((nsIJPGDecoder**) &inst)))
return rv;
}
else {
return NS_ERROR_NO_INTERFACE;
}
if (! inst)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
delete inst;
if (wasRefCounted)
NS_IF_RELEASE(inst);
return rv;
}
nsresult ImgFactoryImpl::LockFactory(PRBool aLock)
{
return NS_OK;
}
/*---------------------*/
/* return the proper factory to the caller */
extern "C" PR_IMPLEMENT(nsresult)
NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aContractID,
nsIFactory **aFactory)
{
if (! aFactory)
return NS_ERROR_NULL_POINTER;
ImgFactoryImpl* factory = new ImgFactoryImpl(aClass, aClassName, aContractID);
if (factory == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*aFactory = factory;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,95 +0,0 @@
?il_partial@@YAXPAUil_container_struct@@HHH@Z ; 1357286
?il_emit_row@@YAHPAUil_container_struct@@PAE1HHHHW4il_draw_mode@@H@Z ; 1357286
?ImgDCBHaveRow@ImgDCallbk@@UAGIPAE0HHHHEH@Z ; 1357286
IL_AddRefToColorSpace ; 138105
IL_ReleaseColorSpace ; 138094
XP_NotifyObservers ; 97013
IL_GetImagePixmap ; 96561
?il_progress_notify@@YAXPAUil_container_struct@@@Z ; 44047
?il_flush_image_data@@YAXPAUil_container_struct@@@Z ; 43843
?ImgDCBInitTransparentPixel@ImgDCallbk@@UAGIXZ ; 42416
?il_init_image_transparent_pixel@@YAHPAUil_container_struct@@@Z ; 42416
?il_destroy_image_transparent_pixel@@YAXPAUil_container_struct@@@Z ; 42341
IL_SetTimeout ; 41179
?il_pixmap_update_notify@@YAXPAUil_container_struct@@@Z ; 41074
?ImgDCBFlushImage@ImgDCallbk@@UAGIXZ ; 41070
?il_frame_complete_notify@@YAXPAUil_container_struct@@@Z ; 41069
?ImgDCBHaveImageFrame@ImgDCallbk@@UAGIXZ ; 41069
?ImgDCBSetTimeout@ImgDCallbk@@UAGPAXP6AXPAX@Z0I@Z ; 41069
?ImgDCBDestroyTransparentPixel@ImgDCallbk@@UAGIXZ ; 41039
?compare_PRUint32@@YAHPBX0PAX@Z ; 13734
?AddRef@NetReaderImpl@@UAGKXZ ; 7119
?Release@NetReaderImpl@@UAGKXZ ; 7119
?il_image_stopped@@YAHPAUil_container_struct@@@Z ; 4275
?IL_StreamWrite@@YAHPAUil_container_struct@@PBEJ@Z ; 2973
?IL_StreamWriteReady@@YAHPAUil_container_struct@@@Z ; 2973
?Write@NetReaderImpl@@UAGIPBEJ@Z ; 2973
?WriteReady@NetReaderImpl@@UAGIPAI@Z ; 2973
?il_reset_palette@@YAHPAUil_container_struct@@@Z ; 2709
?il_compute_percentage_complete@@YAHHPAUil_container_struct@@@Z ; 1455
??0NetReaderImpl@@QAE@PAUil_container_struct@@@Z ; 1418
?StreamCreated@NetReaderImpl@@UAEHPAVilIURL@@PAD@Z ; 1418
?IL_NewNetReader@@YAPAVilINetReader@@PAUil_container_struct@@@Z ; 1418
?FlushImgBuffer@NetReaderImpl@@UAGIXZ ; 1418
??1NetReaderImpl@@UAE@XZ ; 1418
?NetRequestDone@NetReaderImpl@@UAGIPAVilIURL@@H@Z ; 1418
?IL_StreamCreated@@YAHPAUil_container_struct@@PAVilIURL@@PAD@Z ; 1418
?IL_NetRequestDone@@YAXPAUil_container_struct@@PAVilIURL@@H@Z ; 1418
??_GNetReaderImpl@@UAEPAXI@Z ; 1418
?StreamComplete@NetReaderImpl@@UAGIH@Z ; 1409
?sniffout_mimetype@@YAHPBDJPAD@Z ; 1409
?il_setup_color_space_converter@@YAHPAUil_container_struct@@@Z ; 1409
?IL_StreamComplete@@YAXPAUil_container_struct@@H@Z ; 1409
?il_size@@YAHPAUil_container_struct@@@Z ; 1409
?FirstWrite@NetReaderImpl@@UAGIPBEJPAD@Z ; 1409
?ImgDCBSetupColorspaceConverter@ImgDCallbk@@UAGIXZ ; 1409
?ImgDCBImageSize@ImgDCallbk@@UAGIXZ ; 1409
?IL_StreamFirstWrite@@YAHPAUil_container_struct@@PBEJ@Z ; 1409
?ImgDCBResetPalette@ImgDCallbk@@UAGIXZ ; 1407
?il_image_complete_notify@@YAXPAUil_container_struct@@@Z ; 1352
?il_image_complete@@YAXPAUil_container_struct@@@Z ; 1352
?ImgDCBHaveImageAll@ImgDCallbk@@UAGIXZ ; 1352
XP_DisposeObserverList ; 271
?il_group_notify@@YAXPAU_IL_GroupContext@@J@Z ; 232
?il_image_destroyed_notify@@YAXPAU_IL_ImageReq@@@Z ; 220
?il_add_client@@YAHPAU_IL_GroupContext@@PAUil_container_struct@@PAU_IL_ImageReq@@H@Z ; 220
IL_GetImage ; 220
?il_hash@@YAIPBD@Z ; 220
IL_DestroyImage ; 220
?il_PermitLoad@@YAHPBDPAVnsIImageRequestObserver@@@Z ; 220
?il_get_container@@YAPAUil_container_struct@@PAU_IL_GroupContext@@W4ImgCachePolicy@@PBDPAU_NI_IRGB@@W4IL_DitherMode@@HHH@Z ; 220
?il_delete_client@@YAHPAUil_container_struct@@PAU_IL_ImageReq@@@Z ; 220
?il_check_requested_animation@@YA?AW4nsImageAnimation@@PAVnsIImageRequestObserver@@@Z ; 220
XP_SetObserverListObservable ; 220
XP_GetString ; 211
?il_removefromcache@@YAPAUil_container_struct@@PAU1@@Z ; 182
?il_image_abort@@YAXPAUil_container_struct@@@Z ; 174
?il_destroy_pixmap@@YAXPAVilIImageRenderer@@PAU_NI_Pixmap@@@Z ; 127
?QueryInterface@ImgDCallbk@@UAGIABUnsID@@PAPAX@Z ; 116
?AddRef@ImgDCallbk@@UAGKXZ ; 116
IL_ClearTimeout ; 114
?il_reduce_image_cache_size_to@@YAXI@Z ; 108
?il_dimensions_notify@@YAXPAUil_container_struct@@HH@Z ; 107
?il_adjust_cache_fullness@@YAXJ@Z ; 107
?ImgDCBHaveHdr@ImgDCallbk@@UAGIHH@Z ; 107
?il_cache_return_notify@@YAXPAU_IL_ImageReq@@@Z ; 104
IL_DestroyGroupContext ; 90
?il_delete_container@@YAXPAUil_container_struct@@@Z ; 87
IL_CreateGreyScaleColorSpace ; 70
?il_scour_container@@YAXPAUil_container_struct@@@Z ; 69
??1ImgDCallbk@@UAE@XZ ; 69
?Release@ImgDCallbk@@UAGKXZ ; 69
??_GImgDCallbk@@UAEPAXI@Z ; 69
?assign_assuming_AddRef@nsCOMPtr_base@@IAEXPAVnsISupports@@@Z ; 68
IL_SetDisplayMode ; 64
XP_NewObserverList ; 64
IL_NewGroupContext ; 64
?ImgDCBClearTimeout@ImgDCallbk@@UAGIPAX@Z ; 57
IL_InterruptContext ; 51
IL_CreateTrueColorSpace ; 50
?IL_StreamAbort@@YAXPAUil_container_struct@@H@Z ; 27
?StreamAbort@NetReaderImpl@@UAGIH@Z ; 27
IL_ShrinkCache ; 11
IL_SetCacheSize ; 1
IL_FlushCache ; 1
IL_Init ; 1

View File

@ -1,122 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape 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/NPL/
*
* 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 Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/*
* The purpose of this file is to help phase out XP_ library
* from the image library. In general, XP_ data structures and
* functions will be replaced with the PR_ or PL_ equivalents.
* In cases where the PR_ or PL_ equivalents don't yet exist,
* this file (and its header equivalent) will play the role
* of the XP_ library.
*/
#include "xpcompat.h"
#if TARGET_CARBON
# include <time.h>
#endif
#include <stdlib.h>
#include <time.h>
#include "prlog.h"
#include "prmem.h"
#include "plstr.h"
#include "ilISystemServices.h"
#include "nsCRT.h"
extern ilISystemServices *il_ss;
char *XP_GetString(int i)
{
return ("XP_GetString replacement needed");
}
#ifdef XP_MAC
#ifndef UNIXMINUSMACTIME
#define UNIXMINUSMACTIME 2082844800UL
#endif
#include <OSUtils.h>
static void MyReadLocation(MachineLocation * loc)
{
static MachineLocation storedLoc; // InsideMac, OSUtilities, page 4-20
static Boolean didReadLocation = FALSE;
if (!didReadLocation)
{
ReadLocation(&storedLoc);
didReadLocation = TRUE;
}
*loc = storedLoc;
}
// current local time = GMTDelta() + GMT
// GMT = local time - GMTDelta()
static long GMTDelta()
{
MachineLocation loc;
long gmtDelta;
MyReadLocation(&loc);
gmtDelta = loc.u.gmtDelta & 0x00FFFFFF;
if ((gmtDelta & 0x00800000) != 0)
gmtDelta |= 0xFF000000;
return gmtDelta;
}
// This routine simulates stdclib time(), time in seconds since 1.1.1970
// The time is in GMT
time_t GetTimeMac()
{
unsigned long maclocal;
// Get Mac local time
GetDateTime(&maclocal);
// Get Mac GMT
maclocal -= GMTDelta();
// return unix GMT
return (maclocal - UNIXMINUSMACTIME);
}
// Returns the GMT times
time_t Mactime(time_t *timer)
{
time_t t = GetTimeMac();
if (timer != NULL)
*timer = t;
return t;
}
#endif /* XP_MAC */
NS_EXPORT void*
IL_SetTimeout(TimeoutCallbackFunction func, void * closure, PRUint32 msecs)
{
return il_ss->SetTimeout((ilTimeoutCallbackFunction)func,
closure, msecs);
}
NS_EXPORT void
IL_ClearTimeout(void *timer_id)
{
il_ss->ClearTimeout(timer_id);
}