diff --git a/mozilla/gfx/public/nsIImageGroup.h b/mozilla/gfx/public/nsIImageGroup.h deleted file mode 100644 index d07842fce9f..00000000000 --- a/mozilla/gfx/public/nsIImageGroup.h +++ /dev/null @@ -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 -#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 diff --git a/mozilla/gfx/public/nsIImageManager.h b/mozilla/gfx/public/nsIImageManager.h deleted file mode 100644 index 2b7be1a78c9..00000000000 --- a/mozilla/gfx/public/nsIImageManager.h +++ /dev/null @@ -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 -#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 diff --git a/mozilla/gfx/public/nsIImageObserver.h b/mozilla/gfx/public/nsIImageObserver.h deleted file mode 100644 index ee3a7a3678f..00000000000 --- a/mozilla/gfx/public/nsIImageObserver.h +++ /dev/null @@ -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 -#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 diff --git a/mozilla/gfx/public/nsIImageRequest.h b/mozilla/gfx/public/nsIImageRequest.h deleted file mode 100644 index 6df3515c17a..00000000000 --- a/mozilla/gfx/public/nsIImageRequest.h +++ /dev/null @@ -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 -#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 - * GetImage method of the nsIImageGroup - * 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 diff --git a/mozilla/gfx/src/nsImageGroup.cpp b/mozilla/gfx/src/nsImageGroup.cpp deleted file mode 100644 index e97f8bfaf8b..00000000000 --- a/mozilla/gfx/src/nsImageGroup.cpp +++ /dev/null @@ -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 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); -} diff --git a/mozilla/gfx/src/nsImageManager.cpp b/mozilla/gfx/src/nsImageManager.cpp deleted file mode 100644 index 1a8e83df5ca..00000000000 --- a/mozilla/gfx/src/nsImageManager.cpp +++ /dev/null @@ -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 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 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 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); -} diff --git a/mozilla/gfx/src/nsImageNet.h b/mozilla/gfx/src/nsImageNet.h deleted file mode 100644 index 8af4917fa83..00000000000 --- a/mozilla/gfx/src/nsImageNet.h +++ /dev/null @@ -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); diff --git a/mozilla/gfx/src/nsImageNetContextAsync.cpp b/mozilla/gfx/src/nsImageNetContextAsync.cpp deleted file mode 100644 index 145e9523cfe..00000000000 --- a/mozilla/gfx/src/nsImageNetContextAsync.cpp +++ /dev/null @@ -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 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 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 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 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 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 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 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 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 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 loadContext (do_QueryReferent(mLoadContext)); - nsCOMPtr 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 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 channel; - nsCOMPtr loadContext (do_QueryReferent(mLoadContext)); - nsCOMPtr group (do_GetInterface(loadContext)); - nsCOMPtr 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 httpChannel = do_QueryInterface(channel); - if (httpChannel) - { - // Get the defloadRequest from the loadgroup- - nsCOMPtr defLoadRequest; - if (NS_SUCCEEDED(group->GetDefaultLoadRequest( - getter_AddRefs(defLoadRequest))) && defLoadRequest) - { - nsCOMPtr reqchannel = do_QueryInterface(defLoadRequest); - - // Get the referrer from the loadchannel- - nsCOMPtr 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 window (do_QueryInterface(NS_STATIC_CAST(nsIStreamListener *, ic))); - - // let's try uri dispatching... - nsCOMPtr 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 group (do_GetInterface(aLoadContext)); - /*nsresult rv = */group->GetLoadFlags(&necko_attribs); -/* -Need code to check freshness of necko cache. -*/ - nsCOMPtr defLoadRequest; - nsCOMPtr 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); - -} diff --git a/mozilla/gfx/src/nsImageNetContextSync.cpp b/mozilla/gfx/src/nsImageNetContextSync.cpp deleted file mode 100644 index 3a8df4532b7..00000000000 --- a/mozilla/gfx/src/nsImageNetContextSync.cpp +++ /dev/null @@ -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 - */ - -#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 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); -} diff --git a/mozilla/gfx/src/nsImageRenderer.cpp b/mozilla/gfx/src/nsImageRenderer.cpp deleted file mode 100644 index d7175dfce6b..00000000000 --- a/mozilla/gfx/src/nsImageRenderer.cpp +++ /dev/null @@ -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); -} diff --git a/mozilla/gfx/src/nsImageRequest.cpp b/mozilla/gfx/src/nsImageRequest.cpp deleted file mode 100644 index b16a5000ce3..00000000000 --- a/mozilla/gfx/src/nsImageRequest.cpp +++ /dev/null @@ -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; - } -} diff --git a/mozilla/gfx/src/nsImageRequest.h b/mozilla/gfx/src/nsImageRequest.h deleted file mode 100644 index cd859eabeaf..00000000000 --- a/mozilla/gfx/src/nsImageRequest.h +++ /dev/null @@ -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 diff --git a/mozilla/gfx/src/nsImageSystemServices.cpp b/mozilla/gfx/src/nsImageSystemServices.cpp deleted file mode 100644 index 7e61a7812fc..00000000000 --- a/mozilla/gfx/src/nsImageSystemServices.cpp +++ /dev/null @@ -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); -} diff --git a/mozilla/gfx/src/nsImageURL.cpp b/mozilla/gfx/src/nsImageURL.cpp deleted file mode 100644 index 2fde7a74982..00000000000 --- a/mozilla/gfx/src/nsImageURL.cpp +++ /dev/null @@ -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); -} diff --git a/mozilla/modules/libimg/jpgcom/Makefile.in b/mozilla/modules/libimg/jpgcom/Makefile.in deleted file mode 100644 index f5845d3f668..00000000000 --- a/mozilla/modules/libimg/jpgcom/Makefile.in +++ /dev/null @@ -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 - diff --git a/mozilla/modules/libimg/jpgcom/jpeg.cpp b/mozilla/modules/libimg/jpgcom/jpeg.cpp deleted file mode 100644 index 22b1558bd99..00000000000 --- a/mozilla/modules/libimg/jpgcom/jpeg.cpp +++ /dev/null @@ -1,1012 +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): - */ - -/* - * jpeg.c --- Glue code to Independent JPEG Group decoder library - * $Id: jpeg.cpp,v 1.30 2001-06-19 11:11:40 pavlov%netscape.com Exp $ - */ - - - -#include "nsIImgDecoder.h" // include if_struct.h Needs to be first -#include "nsIImgDCallbk.h" -#include "nsCRT.h" -#include "nsJPGDecoder.h" -#include "jpeg.h" -#include "ilErrors.h" -#include "il.h" - -#include /* to declare isprint() */ -#ifndef XP_MAC -# include -#endif - -/* 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 - -PR_BEGIN_EXTERN_C -#include "jpeglib.h" -#include "jerror.h" -PR_END_EXTERN_C - -#ifdef XP_OS2 -/* IBM-MAS: We removed setjmp.h from XP_core.h, now we need it here. */ -/* We need to see if we can fix hwthreads/XP_CORE correctly.. */ -#include -#endif - -#ifdef PROFILE -# pragma profile on -#endif - -/* Normal JFIF markers can't have more bytes than this. */ -#define MAX_JPEG_MARKER_LENGTH (((PRUint32)1 << 16) - 1) - -#ifdef DEBUG -static int il_debug_jpg = 0; -static PRLogModuleInfo *il_log_module_jpg = NULL; -#define ILTRACE(l,t) { if(il_debug_jpg>l) {PR_LOG(il_log_module_jpg, 1, t);} } -#else -#define ILTRACE(l,t) {} -#endif - -/* - * States that the jpeg decoder might be in - */ -typedef enum { - JPEG_HEADER, /* Reading JFIF headers */ - JPEG_START_DECOMPRESS, - JPEG_DECOMPRESS_PROGRESSIVE, /* Output progressive pixels */ - JPEG_DECOMPRESS_SEQUENTIAL, /* Output sequential pixels */ - JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT, - JPEG_DONE, - JPEG_SINK_NON_JPEG_TRAILER, /* Some image files have a */ - /* non-JPEG trailer */ - JPEG_ERROR -} jstate; - -typedef struct { - struct jpeg_error_mgr pub; /* "public" fields for IJG library*/ - jmp_buf setjmp_buffer; /* For handling catastropic errors */ -} il_error_mgr; - -/* - * Structure used to manage the JPEG decoder stream. - */ -typedef struct jpeg_struct { - jstate state; /* Decoder FSM state */ - int pass_num; - int completed_output_passes; - - int rows_per_chunk; - void *timeout; - - /* One scanline's worth of post-processed sample data */ - JSAMPARRAY samples; - JSAMPARRAY samples3; - /* IJG JPEG library decompressor state */ - struct jpeg_decompress_struct jd; - il_error_mgr jerr; - il_container *ic; -} jpeg_struct; - - - - -/* Possible states for JPEG source manager */ -enum data_source_state { - dss_consuming_backtrack_buffer = 0, /* Must be zero for init purposes */ - dss_consuming_netlib_buffer -}; - -/* - * Implementation of a JPEG src object that understands our state machine - */ -typedef struct { - /* public fields; must be first in this struct! */ - struct jpeg_source_mgr pub; - - jpeg_struct *js; /* pointer to netlib stream object */ - - int bytes_to_skip; /* remaining bytes to skip */ - - enum data_source_state state; - - JOCTET *netlib_buffer; /* next buffer for fill_input_buffer */ - PRUint32 netlib_buflen; - - /* - * Buffer of "remaining" characters left over after a call to - * fill_input_buffer(), when no additional data is available. - */ - JOCTET *backtrack_buffer; - size_t backtrack_buffer_size; /* Allocated size of backtrack_buffer */ - size_t backtrack_buflen; /* Offset of end of active backtrack data */ - size_t backtrack_num_unread_bytes; /* Length of active backtrack data */ -} il_source_mgr; - - -/* Override the standard error method in the IJG JPEG decoder code. */ -void PR_CALLBACK -il_error_exit (j_common_ptr cinfo) -{ - int error_code; - il_error_mgr *err = (il_error_mgr *) cinfo->err; - -#ifdef DEBUG -#if 0 - /*ptn fix later */ - if (il_debug >= 1) { - char buffer[JMSG_LENGTH_MAX]; - - /* Create the message */ - (*cinfo->err->format_message) (cinfo, buffer); - - ILTRACE(1,("%s\n", buffer)); - } -#endif -#endif - - /* Convert error to a browser error code */ - if (cinfo->err->msg_code == JERR_OUT_OF_MEMORY) - error_code = MK_OUT_OF_MEMORY; - else - error_code = MK_IMAGE_LOSSAGE; - - /* Return control to the setjmp point. */ - longjmp(err->setjmp_buffer, error_code); -} - - -static void PR_CALLBACK -init_source (j_decompress_ptr jd) -{ -} - -/*----------------------------------------------------------------------------- - * This is the callback routine from the IJG JPEG library used to supply new - * data to the decompressor when its input buffer is exhausted. It juggles - * multiple buffers in an attempt to avoid unnecessary copying of input data. - * - * (A simpler scheme is possible: It's much easier to use only a single - * buffer; when fill_input_buffer() is called, move any unconsumed data - * (beyond the current pointer/count) down to the beginning of this buffer and - * then load new data into the remaining buffer space. This approach requires - * a little more data copying but is far easier to get right.) - * - * At any one time, the JPEG decompressor is either reading from the netlib - * input buffer, which is volatile across top-level calls to the IJG library, - * or the "backtrack" buffer. The backtrack buffer contains the remaining - * unconsumed data from the netlib buffer after parsing was suspended due - * to insufficient data in some previous call to the IJG library. - * - * When suspending, the decompressor will back up to a convenient restart - * point (typically the start of the current MCU). The variables - * next_input_byte & bytes_in_buffer indicate where the restart point will be - * if the current call returns FALSE. Data beyond this point must be - * rescanned after resumption, so it must be preserved in case the decompressor - * decides to backtrack. - * - * Returns: - * TRUE if additional data is available, FALSE if no data present and - * the JPEG library should therefore suspend processing of input stream - *---------------------------------------------------------------------------*/ -static boolean PR_CALLBACK -fill_input_buffer (j_decompress_ptr jd) -{ - il_source_mgr *src = (il_source_mgr *)jd->src; - enum data_source_state src_state = src->state; - PRUint32 bytesToSkip, new_backtrack_buflen, new_buflen, roundup_buflen; - unsigned char *new_buffer; - - ILTRACE(5,("il:jpeg: fill, state=%d, nib=0x%x, bib=%d", src_state, - src->pub.next_input_byte, src->pub.bytes_in_buffer)); - - switch (src_state) { - - /* Decompressor reached end of backtrack buffer. Return netlib buffer.*/ - case dss_consuming_backtrack_buffer: - new_buffer = (unsigned char *)src->netlib_buffer; - new_buflen = src->netlib_buflen; - if ((new_buffer == NULL) || (new_buflen == 0)) - goto suspend; - - /* - * Clear, so that repeated calls to fill_input_buffer() do not - * deliver the same netlib buffer more than once. - */ - src->netlib_buflen = 0; - - /* Discard data if asked by skip_input_data(). */ - bytesToSkip = src->bytes_to_skip; - if (bytesToSkip) { - if (bytesToSkip < new_buflen) { - /* All done skipping bytes; Return what's left. */ - new_buffer += bytesToSkip; - new_buflen -= bytesToSkip; - src->bytes_to_skip = 0; - } else { - /* Still need to skip some more data in the future */ - src->bytes_to_skip -= (size_t)new_buflen; - goto suspend; - } - } - - /* Save old backtrack buffer parameters, in case the decompressor - * backtracks and we're forced to restore its contents. - */ - src->backtrack_num_unread_bytes = src->pub.bytes_in_buffer; - - src->pub.next_input_byte = new_buffer; - src->pub.bytes_in_buffer = (size_t)new_buflen; - src->state = dss_consuming_netlib_buffer; - return TRUE; - - /* Reached end of netlib buffer. Suspend */ - case dss_consuming_netlib_buffer: - if (src->pub.next_input_byte != src->netlib_buffer) { - /* Backtrack data has been permanently consumed. */ - src->backtrack_num_unread_bytes = 0; - src->backtrack_buflen = 0; - } - - /* Save remainder of netlib buffer in backtrack buffer */ - new_backtrack_buflen = src->pub.bytes_in_buffer + src->backtrack_buflen; - - /* Make sure backtrack buffer is big enough to hold new data. */ - if (src->backtrack_buffer_size < new_backtrack_buflen) { - - /* Round up to multiple of 16 bytes. */ - roundup_buflen = ((new_backtrack_buflen + 15) >> 4) << 4; - if (src->backtrack_buffer_size) { - src->backtrack_buffer = - (JOCTET *)PR_REALLOC(src->backtrack_buffer, roundup_buflen); - } else { - src->backtrack_buffer = (JOCTET*)PR_MALLOC(roundup_buflen); - } - - /* Check for OOM */ - if (! src->backtrack_buffer) { - j_common_ptr cinfo = (j_common_ptr)(&src->js->jd); - cinfo->err->msg_code = JERR_OUT_OF_MEMORY; - il_error_exit(cinfo); - } - - src->backtrack_buffer_size = (size_t)roundup_buflen; - - /* Check for malformed MARKER segment lengths. */ - if (new_backtrack_buflen > MAX_JPEG_MARKER_LENGTH) - il_error_exit((j_common_ptr)(&src->js->jd)); - } - - /* Copy remainder of netlib buffer into backtrack buffer. */ - nsCRT::memmove(src->backtrack_buffer + src->backtrack_buflen, - src->pub.next_input_byte, - src->pub.bytes_in_buffer); - - /* Point to start of data to be rescanned. */ - src->pub.next_input_byte = src->backtrack_buffer + - src->backtrack_buflen - src->backtrack_num_unread_bytes; - src->pub.bytes_in_buffer += src->backtrack_num_unread_bytes; - src->backtrack_buflen = (size_t)new_backtrack_buflen; - - src->state = dss_consuming_backtrack_buffer; - goto suspend; - - default: - PR_ASSERT(0); - return FALSE; - } - - suspend: - ILTRACE(5,(" Suspending, bib=%d", src->pub.bytes_in_buffer)); - return FALSE; -} - -static void PR_CALLBACK -skip_input_data (j_decompress_ptr jd, long num_bytes) -{ - il_source_mgr *src = (il_source_mgr *)jd->src; - -#ifdef DEBUG - ILTRACE(5, ("il:jpeg: skip_input_data js->buf=0x%x js->buflen=%d skip=%d", - src->netlib_buffer, src->netlib_buflen, - num_bytes)); -#endif - - if (num_bytes > (long)src->pub.bytes_in_buffer) { - /* - * Can't skip it all right now until we get more data from - * network stream. Set things up so that fill_input_buffer - * will skip remaining amount. - */ - src->bytes_to_skip = (size_t)num_bytes - src->pub.bytes_in_buffer; - src->pub.next_input_byte += src->pub.bytes_in_buffer; - src->pub.bytes_in_buffer = 0; - } else { - /* Simple case. Just advance buffer pointer */ - src->pub.bytes_in_buffer -= (size_t)num_bytes; - src->pub.next_input_byte += num_bytes; - } -} - - -/* - * Terminate source --- called by jpeg_finish_decompress() after all - * data has been read to clean up JPEG source manager. - */ -static void PR_CALLBACK -term_source (j_decompress_ptr jd) -{ - /* No work necessary here */ -} - - -/*----------------------------------------------------------------------------- - * Setup a JPEG source object for streaming data in a demand-driven - * fashion into the IJG JPEG decompression library. A JPEG source - * object consists of a set of callback functions which the - * decompressor library calls when it needs more data or to seek ahead - * in the input stream. - * - * Returns: - * TRUE if setup succeeds, FALSE otherwise. - *---------------------------------------------------------------------------*/ -PRBool -setup_jpeg_src (j_decompress_ptr jd, jpeg_struct *js) -{ - il_source_mgr *src; - - if (jd->src == NULL) { - src = PR_NEWZAP(il_source_mgr); - if (!src) { - ILTRACE(1,("il:jpeg: src manager memory lossage")); - return PR_FALSE; - } - jd->src = (struct jpeg_source_mgr *) src; - } - - src = (il_source_mgr *)jd->src; - src->js = js; - - /* Setup callback functions. */ - src->pub.init_source = init_source; - src->pub.fill_input_buffer = fill_input_buffer; - src->pub.skip_input_data = skip_input_data; - src->pub.resync_to_restart = jpeg_resync_to_restart; - src->pub.term_source = term_source; - - return PR_TRUE; -} - - - -/* - * Macros for fetching data from the data source module. - * - * At all times, cinfo->src->next_input_byte and ->bytes_in_buffer reflect - * the current restart point; we update them only when we have reached a - * suitable place to restart if a suspension occurs. - */ - -/* Declare and initialize local copies of input pointer/count */ -#define INPUT_VARS(cinfo) \ - struct jpeg_source_mgr * datasrc = (cinfo)->src; \ - const JOCTET * next_input_byte = datasrc->next_input_byte; \ - size_t bytes_in_buffer = datasrc->bytes_in_buffer - -/* Unload the local copies --- do this only at a restart boundary */ -#define INPUT_SYNC(cinfo) \ - ( datasrc->next_input_byte = next_input_byte, \ - datasrc->bytes_in_buffer = bytes_in_buffer ) - -/* Reload the local copies --- seldom used except in MAKE_BYTE_AVAIL */ -#define INPUT_RELOAD(cinfo) \ - ( next_input_byte = datasrc->next_input_byte, \ - bytes_in_buffer = datasrc->bytes_in_buffer ) - -/* Internal macro for INPUT_BYTE and INPUT_2BYTES: make a byte available. - * Note we do *not* do INPUT_SYNC before calling fill_input_buffer, - * but we must reload the local copies after a successful fill. - */ -#define MAKE_BYTE_AVAIL(cinfo,action) \ - if (bytes_in_buffer == 0) { \ - if (! (*datasrc->fill_input_buffer) (cinfo)) \ - { action; } \ - INPUT_RELOAD(cinfo); \ - } \ - bytes_in_buffer-- - -/* Read a byte into variable V. - * If must suspend, take the specified action (typically "return FALSE"). - */ -#define INPUT_BYTE(cinfo,V,action) \ - MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ - V = GETJOCTET(*next_input_byte++); ) - -/* As above, but read two bytes interpreted as an unsigned 16-bit integer. - * V should be declared unsigned int or perhaps INT32. - */ -#define INPUT_2BYTES(cinfo,V,action) \ - MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \ - V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \ - MAKE_BYTE_AVAIL(cinfo,action); \ - V += GETJOCTET(*next_input_byte++); ) - - -/* Process the COM marker segment, which contains human-readable comments. */ -boolean PR_CALLBACK -il_jpeg_COM_handler (j_decompress_ptr cinfo) -{ - PRUintn length; - char *comment; - unsigned int ch; - - il_source_mgr *src = (il_source_mgr*) cinfo->src; - il_container *ic = src->js->ic; - static unsigned int lastch = 0; - - INPUT_VARS(cinfo); - - /* Get 16-bit comment length word. */ - INPUT_2BYTES(cinfo, length, return FALSE); - if (length < 2) { - cinfo->err->msg_code = JERR_BAD_LENGTH; - il_error_exit((j_common_ptr)cinfo); - } - length -= 2; /* discount the length word itself */ - - PR_FREEIF(ic->comment); - comment = ic->comment = (char *)PR_MALLOC(length + 1); - ic->comment_length = length; - - if (!ic->comment) { - skip_input_data(cinfo, length + 2); - return TRUE; - } - - /* Emit the character in a readable form. - * Newlines in CR, CR/LF, or LF form will be printed as one newline. - */ - while (length-- > 0) { - INPUT_BYTE(cinfo, ch, return FALSE); - - if (ch == '\r') { - *comment++ = '\n'; - } else if (ch == '\n') { - if (lastch != '\r') - *comment++ = '\n'; - } else if (isprint(ch) || !ch) { - *comment++ = ch; - } - lastch = ch; - } - - *comment = 0; - - INPUT_SYNC(cinfo); - - return TRUE; -} - -PRBool -il_jpeg_init(il_container *ic) -{ - jpeg_struct *js; - j_decompress_ptr jd; - NI_ColorSpace *src_color_space = ic->src_header->color_space; - NI_RGBBits *rgb = &src_color_space->bit_alloc.rgb; - - js = PR_NEWZAP(jpeg_struct); - if (!js) { - ILTRACE(1,("il:jpeg: jpeg_struct memory lossage")); - return PR_FALSE; - } - - /* Init jpeg_struct */ - ic->ds = js; - js->state = JPEG_HEADER; - js->samples = NULL; - js->samples3 = NULL; - js->ic = ic; - - jd = &js->jd; - - /* Install our error handler because the default is to exit(). */ - jd->err = jpeg_std_error(&js->jerr.pub); - js->jerr.pub.error_exit = il_error_exit; - - /* Control returns here if an error occurs before setup completes. */ - if(setjmp(js->jerr.setjmp_buffer)) { - /* Free up all the data structures */ - il_jpeg_abort(ic); - return PR_FALSE; - } - -#ifdef DEBUG -#if 0 - if (il_debug > 20) { - jd->err->trace_level = 99; - } -#endif -#endif - jpeg_create_decompress(jd); - - /* Setup jpeg data source object */ - if (!setup_jpeg_src(jd, js)) { - ILTRACE(1,("il:jpeg: jpeg source memory lossage")); - /* Free up all the data structures */ - il_jpeg_abort(ic); - return PR_FALSE; - } - - /* Insert custom COM comment marker processor. */ - jpeg_set_marker_processor(jd, JPEG_COM, il_jpeg_COM_handler); - - - /* Initialize the container's source image header. */ - src_color_space->type = NI_TrueColor; - src_color_space->pixmap_depth = 24; - rgb->red_bits = 8; - rgb->red_shift = 16; - rgb->green_bits = 8; - rgb->green_shift = 8; - rgb->blue_bits = 8; - rgb->blue_shift = 0; - - return PR_TRUE; -} - - -/*----------------------------------------------------------------------------- - * Calling this routine sends scanlines to the front-end for display. - * Scanlines will be emitted until the entire scan has been displayed or - * until insufficient input data is available to continue output. - * - * The maximum number of scanlines to be output is controlled by the - * `num_scanlines' parameter. Set num_scanlines to -1 to output scanlines - * until input data is exhausted. - * - * Returns: - * TRUE if output was discontinued due to lack of input data - * FALSE, otherwise - *---------------------------------------------------------------------------*/ -int -output_jpeg_scanlines(il_container *ic, int num_scanlines) -{ - jpeg_struct *js = (jpeg_struct *)ic->ds; - j_decompress_ptr jd = &js->jd; - int input_exhausted; - int pass; - -#ifdef DEBUG - PRUintn start_scanline = jd->output_scanline; -#endif - - if (js->state == JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT) - pass = IL_FINAL_PASS; - else - pass = js->completed_output_passes + 1; - - while ((jd->output_scanline < jd->output_height) && num_scanlines--) { - JSAMPROW samples; - - /* Request one scanline. Returns 0 or 1 scanlines. */ - int ns = jpeg_read_scanlines(jd, js->samples, 1); - ILTRACE(15,("il:jpeg: scanline %d, ns = %d", - jd->output_scanline, ns)); - if (ns != 1) { - ILTRACE(5,("il:jpeg: suspending scanline")); - input_exhausted = TRUE; - goto done; - } - - /* If grayscale image ... */ - if (jd->output_components == 1) { - JSAMPLE j, *j1, *j1end, *j3; - - /* Convert from grayscale to RGB. */ - j1 = js->samples[0]; - j1end = j1 + jd->output_width; - j3 = js->samples3[0]; - while (j1 < j1end) { - j = *j1++; - j3[0] = j; - j3[1] = j; - j3[2] = j; - j3 += 3; - } - samples = js->samples3[0]; - } else { /* 24-bit color image */ - samples = js->samples[0]; - } - - ic->imgdcb->ImgDCBHaveRow( 0, samples, 0, jd->output_width, jd->output_scanline-1, - 1, ilErase, pass); - } - - input_exhausted = FALSE; - - done: - -#ifdef DEBUG - if (start_scanline != jd->output_scanline) - ILTRACE(4, ("il: jpeg: Input pass=%2d, next input scanline=%3d," - " emitted %3d - %3d\n", - jd->input_scan_number, jd->input_iMCU_row * 16, - start_scanline, jd->output_scanline - 1)); - -#endif - - return input_exhausted; -} - -#define JPEG_OUTPUT_CHUNK_SIZE 150000 - -/* Timeout durations, in milliseconds */ - -/* Delay between displaying chunks of pixels for the first scan. */ -#define JPEG_TIMEOUT_INITIAL_DELAY 32 - -/* Delay between displaying chunks of pixels for subsequent scans */ -#define JPEG_TIMEOUT_DELAY 250 - -static void -jpeg_timeout_callback(void *closure) -{ - PRUint32 delay; - jpeg_struct *js = (jpeg_struct *)closure; - j_decompress_ptr jd = &js->jd; - - if (jd->input_scan_number == 1) - delay = JPEG_TIMEOUT_INITIAL_DELAY; - else - delay = JPEG_TIMEOUT_DELAY; - - /* - * Perform incremental display of progressive scans, - * except don't display unless enough time has elapsed - * since the previous scan was displayed. - */ - - if (js->pass_num != js->completed_output_passes + 1) { - if (! jpeg_start_output(jd, jd->input_scan_number)) { - ILTRACE(1, ("il: jpeg: jpeg_start_output returned" - "FALSE!\n")); - goto done; - } - js->pass_num = js->completed_output_passes + 1; - } - - js->timeout = NULL; - - /* If there's no more data to process for this scan, - wait until jpeg_write() wakes us up by scheduling a - new timeout */ - if (output_jpeg_scanlines(js->ic, js->rows_per_chunk)) - return; - - /* If we're at the end of this progressive scan ... */ - if (jd->output_scanline == jd->output_height) { - if (jpeg_finish_output(jd)) - js->completed_output_passes++; - } - - done: - js->timeout = js->ic->imgdcb->ImgDCBSetTimeout(jpeg_timeout_callback, js, delay); -} - -/* - * Force the display of scans, even if no data has entered the netlib - * buffer since jpeg_timeout_callback() was run. This will flush - * pixels to the screen during a long pause in a bursty data source. - */ -#if 0 -static void -jpeg_idle_callback(void *closure) -{ - il_container *ic = (il_container *)closure; - il_jpeg_write(ic, NULL, 0); -} -#endif - -int -il_jpeg_write(il_container *ic, const unsigned char *buf, int32 len) -{ - int row_stride, status; - int input_exhausted; - int error_code; - - jpeg_struct *js = (jpeg_struct *)ic->ds; - - - - /* If this js == NULL, chances are the netlib - continued to send data after the image stream was closed. */ - if (!js) { -#ifdef DEBUG - ILTRACE(1,("Netlib sent data after the image stream was closed\n")); -#endif - return MK_IMAGE_LOSSAGE; - } - - j_decompress_ptr jd = &js->jd; - il_source_mgr *src = (il_source_mgr*) js->jd.src; - NI_PixmapHeader *img_header = &ic->image->header; -#ifndef M12N /* XXXM12N Get rid of this */ - NI_PixmapHeader *src_header = ic->src_header; - NI_ColorMap *cmap = &src_header->color_space->cmap; -#endif /* M12N */ - - /* Return here if there is a fatal error. */ - if ((error_code = setjmp(js->jerr.setjmp_buffer)) != 0) { - /* Free up all the data structures */ - il_jpeg_abort(ic); - return error_code; - } - - /* Register new buffer contents with data source manager. */ - src->netlib_buffer = (JOCTET*)buf; - src->netlib_buflen = (PRUint32)len; - - input_exhausted = 0; - while (! input_exhausted) { - ILTRACE(5,("il:jpeg: write, state=%d, buf=0x%x, len=%d", - js->state, buf, len)); - - switch (js->state) { - case JPEG_HEADER: - if (jpeg_read_header(jd, TRUE) != JPEG_SUSPENDED) { -#ifndef M12N /* XXXM12N Get rid of this */ - cmap->map = 0; - cmap->num_colors = ic->cs->default_map_size; -#endif /* M12N */ - ic->src_header->width = jd->image_width; - ic->src_header->height = jd->image_height; - if ((status = ic->imgdcb->ImgDCBImageSize()) != 0) { - ILTRACE(1,("il:jpeg: MEM il_size")); - return status; - } - - ic->imgdcb->ImgDCBSetupColorspaceConverter(); /* XXXM12N Should check - return code. */ - if(!img_header->widthBytes) - return JPEG_ERROR; - else - js->rows_per_chunk = - JPEG_OUTPUT_CHUNK_SIZE / img_header->widthBytes; - - /* FIXME -- Should reset dct_method and dither mode - * for final pass of progressive JPEG - */ - jd->dct_method = JDCT_FASTEST; - jd->dither_mode = JDITHER_ORDERED; - jd->do_fancy_upsampling = FALSE; - jd->enable_2pass_quant = FALSE; - jd->do_block_smoothing = TRUE; - - /* - * Don't allocate a giant and superfluous memory buffer - * when the image is a sequential JPEG. - */ - jd->buffered_image = jpeg_has_multiple_scans(jd); - - /* Used to set up image size so arrays can be allocated */ - jpeg_calc_output_dimensions(jd); - - /* - * Make a one-row-high sample array that will go away - * when done with image. Always make it big enough to - * hold an RGB row. Since this uses the IJG memory - * manager, it must be allocated before the call to - * jpeg_start_compress(). - */ - row_stride = jd->output_width * jd->output_components; - js->samples = (*jd->mem->alloc_sarray)((j_common_ptr) jd, - JPOOL_IMAGE, - row_stride, 1); - - /* Allocate RGB buffer for conversion from greyscale. */ - if (jd->output_components != 3) { - row_stride = jd->output_width * 3; - js->samples3 = (*jd->mem->alloc_sarray)((j_common_ptr) jd, - JPOOL_IMAGE, - row_stride, 1); - } - js->state = JPEG_START_DECOMPRESS; - - } else { - ILTRACE(5,("il:jpeg: suspending header")); - input_exhausted = TRUE; - } - break; - - case JPEG_START_DECOMPRESS: - if (jpeg_start_decompress(jd)) { - - /* If this is a progressive JPEG ... */ - if (jd->buffered_image) { - js->state = JPEG_DECOMPRESS_PROGRESSIVE; - } else { - js->state = JPEG_DECOMPRESS_SEQUENTIAL; - } - } - - break; - - case JPEG_DECOMPRESS_SEQUENTIAL: - input_exhausted = output_jpeg_scanlines(ic, -1); - - /* If we've completed image output ... */ - if (jd->output_scanline == jd->output_height) - js->state = JPEG_DONE; - - break; - - case JPEG_DECOMPRESS_PROGRESSIVE: - - /* - * Set a timeout to trigger display of the next progressive scan. - * Any scans which arrive in the intervening time will be displayed - * instead. Thus, the decoder adapts to the data arrival rate. - */ - if (js->timeout == NULL) { - PRUint32 delay; - - /* - * First time around, display the scan a little - * quicker than in subsequent scans. - */ - if (jd->input_scan_number == 1) - delay = JPEG_TIMEOUT_INITIAL_DELAY; - else { - delay = JPEG_TIMEOUT_DELAY; - } - - js->timeout = ic->imgdcb->ImgDCBSetTimeout(jpeg_timeout_callback, js, delay); - - } - - /* Eat all the available input data in the netlib buffer. */ - do { - status = jpeg_consume_input(jd); - } while (!((status == JPEG_SUSPENDED) || - (status == JPEG_REACHED_EOI))); - - /* If we've parsed the whole input, do final display immediately. */ - if (status == JPEG_REACHED_EOI) { - js->state = JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT; - break; - } - - input_exhausted = TRUE; - - break; - - case JPEG_FINAL_PROGRESSIVE_SCAN_OUTPUT: - - if ((jd->input_scan_number == jd->output_scan_number) && - (js->pass_num == js->completed_output_passes + 1)) { - output_jpeg_scanlines(ic, -1); - jpeg_finish_output(jd); - } else { - - /* Abort the last output scan. - * We need to redraw the whole image. - */ - if (js->pass_num == js->completed_output_passes + 1) - jpeg_finish_output(jd); - - jpeg_start_output(jd, jd->input_scan_number); - output_jpeg_scanlines(ic, -1); - jpeg_finish_output(jd); - } - - js->state = JPEG_DONE; - - /* Fall through ... */ - - case JPEG_DONE: - status = jpeg_finish_decompress(jd); - - /* Clear any pending timeouts */ - if (js->timeout) { - ic->imgdcb->ImgDCBClearTimeout(js->timeout); - js->timeout = NULL; - } - - input_exhausted = TRUE; - js->state = JPEG_SINK_NON_JPEG_TRAILER; /* Be prepared for */ - /* non-JPEG data after */ - /* EOI marker. */ - break; - - case JPEG_SINK_NON_JPEG_TRAILER: /* Ignore non-JPEG trailer, if any */ - input_exhausted = TRUE; - break; - - default: - PR_ASSERT(0); - break; - } - } - - return 0; -} - -void -il_jpeg_abort(il_container *ic) -{ - jpeg_struct *js = (jpeg_struct *)ic->ds; - - if (js) { - il_source_mgr *src = (il_source_mgr*) js->jd.src; - - /* - * Free up the memory that we allocated ourselves (not memory we - * allocated using the IJG memory manager - it will be freed in - * a moment.) - */ - if (src) { - if (src->backtrack_buffer) { - PR_FREEIF(src->backtrack_buffer); - src->backtrack_buffer = NULL; - } - PR_FREEIF(src); - js->jd.src = NULL; - } - - /* Clear any pending timeouts */ - if (js->timeout) { - ic->imgdcb->ImgDCBClearTimeout(js->timeout); - js->timeout = NULL; - } - - /* - * Free all the ancillary memory used during JPEG decoding by the - * IJG JPEG library. This has the side effect of freeing up js->samples - * and js->samples3 which were allocated using the IJG memory manager. - */ - jpeg_destroy_decompress(&js->jd); - js->samples = NULL; - js->samples3 = NULL; - - /* Finally, free up our private decoder structure. */ - PR_FREEIF(js); - ic->ds = NULL; - } -} - -void -il_jpeg_complete(il_container *ic) -{ - il_jpeg_abort(ic); - ic->imgdcb->ImgDCBHaveImageAll(); -} - -#ifdef PROFILE -# pragma profile off -#endif - diff --git a/mozilla/modules/libimg/jpgcom/jpeg.h b/mozilla/modules/libimg/jpgcom/jpeg.h deleted file mode 100644 index 3829206af25..00000000000 --- a/mozilla/modules/libimg/jpgcom/jpeg.h +++ /dev/null @@ -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); - - diff --git a/mozilla/modules/libimg/jpgcom/makefile.win b/mozilla/modules/libimg/jpgcom/makefile.win deleted file mode 100644 index 2944f5b9325..00000000000 --- a/mozilla/modules/libimg/jpgcom/makefile.win +++ /dev/null @@ -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> diff --git a/mozilla/modules/libimg/jpgcom/nsJPGDecoder.cpp b/mozilla/modules/libimg/jpgcom/nsJPGDecoder.cpp deleted file mode 100644 index 52d978acc76..00000000000 --- a/mozilla/modules/libimg/jpgcom/nsJPGDecoder.cpp +++ /dev/null @@ -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; - -} - diff --git a/mozilla/modules/libimg/jpgcom/nsJPGDecoder.h b/mozilla/modules/libimg/jpgcom/nsJPGDecoder.h deleted file mode 100644 index da8a0ced018..00000000000 --- a/mozilla/modules/libimg/jpgcom/nsJPGDecoder.h +++ /dev/null @@ -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___ */ diff --git a/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp b/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp deleted file mode 100644 index db9c86047f0..00000000000 --- a/mozilla/modules/libimg/jpgcom/nsJPGModule.cpp +++ /dev/null @@ -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 - */ - -#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) diff --git a/mozilla/modules/libimg/jpgcom/nsJPGModule.h b/mozilla/modules/libimg/jpgcom/nsJPGModule.h deleted file mode 100644 index 2b14d4cf82c..00000000000 --- a/mozilla/modules/libimg/jpgcom/nsJPGModule.h +++ /dev/null @@ -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___ */ diff --git a/mozilla/modules/libimg/jpgcom/nsjpg.def b/mozilla/modules/libimg/jpgcom/nsjpg.def deleted file mode 100644 index ef91c571177..00000000000 --- a/mozilla/modules/libimg/jpgcom/nsjpg.def +++ /dev/null @@ -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 - diff --git a/mozilla/modules/libimg/jpgcom/win32.order b/mozilla/modules/libimg/jpgcom/win32.order deleted file mode 100644 index 9361a07086a..00000000000 --- a/mozilla/modules/libimg/jpgcom/win32.order +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/mngcom/Makefile.in b/mozilla/modules/libimg/mngcom/Makefile.in deleted file mode 100644 index 5a7188ee8d1..00000000000 --- a/mozilla/modules/libimg/mngcom/Makefile.in +++ /dev/null @@ -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 - diff --git a/mozilla/modules/libimg/mngcom/makefile.win b/mozilla/modules/libimg/mngcom/makefile.win deleted file mode 100644 index bc31257c9d5..00000000000 --- a/mozilla/modules/libimg/mngcom/makefile.win +++ /dev/null @@ -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> diff --git a/mozilla/modules/libimg/mngcom/nsMNGDecoder.cpp b/mozilla/modules/libimg/mngcom/nsMNGDecoder.cpp deleted file mode 100644 index 995ddcad5c3..00000000000 --- a/mozilla/modules/libimg/mngcom/nsMNGDecoder.cpp +++ /dev/null @@ -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; yrowbuf, - 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; -} - diff --git a/mozilla/modules/libimg/mngcom/nsMNGDecoder.h b/mozilla/modules/libimg/mngcom/nsMNGDecoder.h deleted file mode 100644 index 93b053415ee..00000000000 --- a/mozilla/modules/libimg/mngcom/nsMNGDecoder.h +++ /dev/null @@ -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___ */ diff --git a/mozilla/modules/libimg/mngcom/nsMNGModule.cpp b/mozilla/modules/libimg/mngcom/nsMNGModule.cpp deleted file mode 100644 index c8be4c6cbc9..00000000000 --- a/mozilla/modules/libimg/mngcom/nsMNGModule.cpp +++ /dev/null @@ -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) diff --git a/mozilla/modules/libimg/mngcom/nsmng.def b/mozilla/modules/libimg/mngcom/nsmng.def deleted file mode 100644 index cc6c70b783f..00000000000 --- a/mozilla/modules/libimg/mngcom/nsmng.def +++ /dev/null @@ -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 - diff --git a/mozilla/modules/libimg/mngcom/win32.order b/mozilla/modules/libimg/mngcom/win32.order deleted file mode 100644 index bf181a81d4a..00000000000 --- a/mozilla/modules/libimg/mngcom/win32.order +++ /dev/null @@ -1 +0,0 @@ -_NSGetModule ; 1 diff --git a/mozilla/modules/libimg/pngcom/Makefile.in b/mozilla/modules/libimg/pngcom/Makefile.in deleted file mode 100644 index 0a4a12d8926..00000000000 --- a/mozilla/modules/libimg/pngcom/Makefile.in +++ /dev/null @@ -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 - diff --git a/mozilla/modules/libimg/pngcom/ipng.cpp b/mozilla/modules/libimg/pngcom/ipng.cpp deleted file mode 100644 index 9afbb71018f..00000000000 --- a/mozilla/modules/libimg/pngcom/ipng.cpp +++ /dev/null @@ -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; iimage->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); -} diff --git a/mozilla/modules/libimg/pngcom/ipng.h b/mozilla/modules/libimg/pngcom/ipng.h deleted file mode 100644 index 883985adafc..00000000000 --- a/mozilla/modules/libimg/pngcom/ipng.h +++ /dev/null @@ -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; - diff --git a/mozilla/modules/libimg/pngcom/makefile.win b/mozilla/modules/libimg/pngcom/makefile.win deleted file mode 100644 index 74ebba7adf7..00000000000 --- a/mozilla/modules/libimg/pngcom/makefile.win +++ /dev/null @@ -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> diff --git a/mozilla/modules/libimg/pngcom/nsPNGDecoder.cpp b/mozilla/modules/libimg/pngcom/nsPNGDecoder.cpp deleted file mode 100644 index 169c08f7a1e..00000000000 --- a/mozilla/modules/libimg/pngcom/nsPNGDecoder.cpp +++ /dev/null @@ -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; -} - - diff --git a/mozilla/modules/libimg/pngcom/nsPNGDecoder.h b/mozilla/modules/libimg/pngcom/nsPNGDecoder.h deleted file mode 100644 index d8f1565324d..00000000000 --- a/mozilla/modules/libimg/pngcom/nsPNGDecoder.h +++ /dev/null @@ -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___ */ diff --git a/mozilla/modules/libimg/pngcom/nsPNGModule.cpp b/mozilla/modules/libimg/pngcom/nsPNGModule.cpp deleted file mode 100644 index 1c977d7de20..00000000000 --- a/mozilla/modules/libimg/pngcom/nsPNGModule.cpp +++ /dev/null @@ -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) - diff --git a/mozilla/modules/libimg/pngcom/nspng.def b/mozilla/modules/libimg/pngcom/nspng.def deleted file mode 100644 index 3459f7c64bb..00000000000 --- a/mozilla/modules/libimg/pngcom/nspng.def +++ /dev/null @@ -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 - diff --git a/mozilla/modules/libimg/pngcom/png_png.cpp b/mozilla/modules/libimg/pngcom/png_png.cpp deleted file mode 100644 index 40be6b1ebc1..00000000000 --- a/mozilla/modules/libimg/pngcom/png_png.cpp +++ /dev/null @@ -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(); -} - - - diff --git a/mozilla/modules/libimg/pngcom/pngdec.h b/mozilla/modules/libimg/pngcom/pngdec.h deleted file mode 100644 index f21c0a5b265..00000000000 --- a/mozilla/modules/libimg/pngcom/pngdec.h +++ /dev/null @@ -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); diff --git a/mozilla/modules/libimg/pngcom/win32.order b/mozilla/modules/libimg/pngcom/win32.order deleted file mode 100644 index b2b1fc2548b..00000000000 --- a/mozilla/modules/libimg/pngcom/win32.order +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/public/MANIFEST b/mozilla/modules/libimg/public/MANIFEST deleted file mode 100644 index 26680984d11..00000000000 --- a/mozilla/modules/libimg/public/MANIFEST +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/public/Makefile.in b/mozilla/modules/libimg/public/Makefile.in deleted file mode 100644 index 2dcc6ba0ba3..00000000000 --- a/mozilla/modules/libimg/public/Makefile.in +++ /dev/null @@ -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 - diff --git a/mozilla/modules/libimg/public/dummy_nc.h b/mozilla/modules/libimg/public/dummy_nc.h deleted file mode 100644 index 51111cd025a..00000000000 --- a/mozilla/modules/libimg/public/dummy_nc.h +++ /dev/null @@ -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 */ diff --git a/mozilla/modules/libimg/public/ilErrors.h b/mozilla/modules/libimg/public/ilErrors.h deleted file mode 100644 index eea10e42b23..00000000000 --- a/mozilla/modules/libimg/public/ilErrors.h +++ /dev/null @@ -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 */ diff --git a/mozilla/modules/libimg/public/ilIImageRenderer.h b/mozilla/modules/libimg/public/ilIImageRenderer.h deleted file mode 100644 index 20790923a96..00000000000 --- a/mozilla/modules/libimg/public/ilIImageRenderer.h +++ /dev/null @@ -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 -#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; - - /** - * (Probably temporary and subject to change). - * 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; - - - /** - * (Probably temporary and subject to change). - * 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 diff --git a/mozilla/modules/libimg/public/ilINetContext.h b/mozilla/modules/libimg/public/ilINetContext.h deleted file mode 100644 index 0211a29285e..00000000000 --- a/mozilla/modules/libimg/public/ilINetContext.h +++ /dev/null @@ -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 -#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 diff --git a/mozilla/modules/libimg/public/ilINetReader.h b/mozilla/modules/libimg/public/ilINetReader.h deleted file mode 100644 index 35f837ea060..00000000000 --- a/mozilla/modules/libimg/public/ilINetReader.h +++ /dev/null @@ -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 -#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 diff --git a/mozilla/modules/libimg/public/ilISystemServices.h b/mozilla/modules/libimg/public/ilISystemServices.h deleted file mode 100644 index c15dbbae66c..00000000000 --- a/mozilla/modules/libimg/public/ilISystemServices.h +++ /dev/null @@ -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 -#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 diff --git a/mozilla/modules/libimg/public/ilIURL.h b/mozilla/modules/libimg/public/ilIURL.h deleted file mode 100644 index 13c20fb25a3..00000000000 --- a/mozilla/modules/libimg/public/ilIURL.h +++ /dev/null @@ -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 -#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 diff --git a/mozilla/modules/libimg/public/il_icons.h b/mozilla/modules/libimg/public/il_icons.h deleted file mode 100644 index d2c1d35f46c..00000000000 --- a/mozilla/modules/libimg/public/il_icons.h +++ /dev/null @@ -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_ */ diff --git a/mozilla/modules/libimg/public/il_strm.h b/mozilla/modules/libimg/public/il_strm.h deleted file mode 100644 index 9c763217f99..00000000000 --- a/mozilla/modules/libimg/public/il_strm.h +++ /dev/null @@ -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 */ - - - diff --git a/mozilla/modules/libimg/public/il_types.h b/mozilla/modules/libimg/public/il_types.h deleted file mode 100644 index 5db18e9d948..00000000000 --- a/mozilla/modules/libimg/public/il_types.h +++ /dev/null @@ -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_ */ - diff --git a/mozilla/modules/libimg/public/il_util.h b/mozilla/modules/libimg/public/il_util.h deleted file mode 100644 index 6c025c42159..00000000000 --- a/mozilla/modules/libimg/public/il_util.h +++ /dev/null @@ -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 */ diff --git a/mozilla/modules/libimg/public/libimg.h b/mozilla/modules/libimg/public/libimg.h deleted file mode 100644 index e9dee4e79de..00000000000 --- a/mozilla/modules/libimg/public/libimg.h +++ /dev/null @@ -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 */ - - - diff --git a/mozilla/modules/libimg/public/makefile.win b/mozilla/modules/libimg/public/makefile.win deleted file mode 100644 index e55296bca0b..00000000000 --- a/mozilla/modules/libimg/public/makefile.win +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/public/ni_pixmp.h b/mozilla/modules/libimg/public/ni_pixmp.h deleted file mode 100644 index fe3c0f5a75d..00000000000 --- a/mozilla/modules/libimg/public/ni_pixmp.h +++ /dev/null @@ -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 */ diff --git a/mozilla/modules/libimg/public/xpcompat.h b/mozilla/modules/libimg/public/xpcompat.h deleted file mode 100644 index 2a14d879c57..00000000000 --- a/mozilla/modules/libimg/public/xpcompat.h +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/public_com/MANIFEST b/mozilla/modules/libimg/public_com/MANIFEST deleted file mode 100644 index 937d93f9222..00000000000 --- a/mozilla/modules/libimg/public_com/MANIFEST +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/public_com/Makefile.in b/mozilla/modules/libimg/public_com/Makefile.in deleted file mode 100644 index 8790c7ed009..00000000000 --- a/mozilla/modules/libimg/public_com/Makefile.in +++ /dev/null @@ -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 - diff --git a/mozilla/modules/libimg/public_com/if_struct.h b/mozilla/modules/libimg/public_com/if_struct.h deleted file mode 100644 index 2457280f574..00000000000 --- a/mozilla/modules/libimg/public_com/if_struct.h +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/public_com/il.h b/mozilla/modules/libimg/public_com/il.h deleted file mode 100644 index 65f5cf6ce96..00000000000 --- a/mozilla/modules/libimg/public_com/il.h +++ /dev/null @@ -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 */ - - diff --git a/mozilla/modules/libimg/public_com/il_utilp.h b/mozilla/modules/libimg/public_com/il_utilp.h deleted file mode 100644 index 414cdff0084..00000000000 --- a/mozilla/modules/libimg/public_com/il_utilp.h +++ /dev/null @@ -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; - - diff --git a/mozilla/modules/libimg/public_com/makefile.win b/mozilla/modules/libimg/public_com/makefile.win deleted file mode 100644 index a9d1833cc8a..00000000000 --- a/mozilla/modules/libimg/public_com/makefile.win +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/public_com/nsIImgDCallbk.h b/mozilla/modules/libimg/public_com/nsIImgDCallbk.h deleted file mode 100644 index 80543b382c1..00000000000 --- a/mozilla/modules/libimg/public_com/nsIImgDCallbk.h +++ /dev/null @@ -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___ */ diff --git a/mozilla/modules/libimg/public_com/nsIImgDecoder.h b/mozilla/modules/libimg/public_com/nsIImgDecoder.h deleted file mode 100644 index 662a6db30f0..00000000000 --- a/mozilla/modules/libimg/public_com/nsIImgDecoder.h +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/public_com/nsImgDCallbk.h b/mozilla/modules/libimg/public_com/nsImgDCallbk.h deleted file mode 100644 index dd642f1a0e8..00000000000 --- a/mozilla/modules/libimg/public_com/nsImgDCallbk.h +++ /dev/null @@ -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___ */ diff --git a/mozilla/modules/libimg/public_com/nsImgDecCID.h b/mozilla/modules/libimg/public_com/nsImgDecCID.h deleted file mode 100644 index adb90c260c4..00000000000 --- a/mozilla/modules/libimg/public_com/nsImgDecCID.h +++ /dev/null @@ -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 */ diff --git a/mozilla/modules/libimg/public_com/nsImgDecoder.h b/mozilla/modules/libimg/public_com/nsImgDecoder.h deleted file mode 100644 index 77555018d70..00000000000 --- a/mozilla/modules/libimg/public_com/nsImgDecoder.h +++ /dev/null @@ -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 */ diff --git a/mozilla/modules/libimg/src/MANIFEST b/mozilla/modules/libimg/src/MANIFEST deleted file mode 100644 index 51fc96dd9c1..00000000000 --- a/mozilla/modules/libimg/src/MANIFEST +++ /dev/null @@ -1,4 +0,0 @@ -# -# This is a list of local files which get copied to the mozilla:dist directory -# - diff --git a/mozilla/modules/libimg/src/Makefile.in b/mozilla/modules/libimg/src/Makefile.in deleted file mode 100644 index 8259482aae4..00000000000 --- a/mozilla/modules/libimg/src/Makefile.in +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/src/color.cpp b/mozilla/modules/libimg/src/color.cpp deleted file mode 100644 index 38b2432481b..00000000000 --- a/mozilla/modules/libimg/src/color.cpp +++ /dev/null @@ -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; iwidth+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; colwidth; 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; colwidth; col++) - { - *bp++ = (*gp++<128); - } - -#else - - for(col=0; colwidth+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 diff --git a/mozilla/modules/libimg/src/colormap.cpp b/mozilla/modules/libimg/src/colormap.cpp deleted file mode 100644 index 0dcaa64afae..00000000000 --- a/mozilla/modules/libimg/src/colormap.cpp +++ /dev/null @@ -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; - -} - diff --git a/mozilla/modules/libimg/src/dither.cpp b/mozilla/modules/libimg/src/dither.cpp deleted file mode 100644 index 77aa965dfc2..00000000000 --- a/mozilla/modules/libimg/src/dither.cpp +++ /dev/null @@ -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 */ - diff --git a/mozilla/modules/libimg/src/if.cpp b/mozilla/modules/libimg/src/if.cpp deleted file mode 100644 index 56ffc884567..00000000000 --- a/mozilla/modules/libimg/src/if.cpp +++ /dev/null @@ -1,2324 +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 -*- - * if.c --- Top-level image library routines - */ - -#include "if.h" - -#include "ilErrors.h" - -#include "nsIImgDecoder.h" -#include "nsImgDCallbk.h" -#include "nsIComponentManager.h" -#include "xpcompat.h" //temporary, for timers - -#include "prtypes.h" -#include "prprf.h" -#include "nsCRT.h" -#include "nsNetUtil.h" - -#include "nsIPresContext.h" -#include "nsIImgManager.h" -#include "nsIServiceManager.h" -#include "nsIURL.h" -#include "nsString.h" -#include "nsXPIDLString.h" - -#define HOWMANY(x, r) (((x) + ((r) - 1)) / (r)) -#define ROUNDUP(x, r) (HOWMANY(x, r) * (r)) - -#if defined( DEBUG ) -int il_debug=100; -#else -int il_debug=0; -#endif -PRLogModuleInfo *il_log_module = NULL; - -/* Global list of image group contexts. */ -static IL_GroupContext *il_global_img_cx_list = NULL; - -static NS_DEFINE_IID(kImgManagerCID, NS_IMGMANAGER_CID); - -/*-----------------------------------------*/ -NS_IMETHODIMP ImgDCallbk::ImgDCBSetupColorspaceConverter() -{ - PRBool ret=PR_FALSE; - if( ilContainer != NULL ) { - ret = il_setup_color_space_converter(ilContainer); - } - if(ret) - return NS_OK; - else - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -ImgDCallbk::ImgDCBCreateGreyScaleColorSpace() -{ - PRBool ret=PR_FALSE; - if( ilContainer != NULL ) { - NI_PixmapHeader *maskhdr = &ilContainer->mask->header; - ret = IL_CreateGreyScaleColorSpace(1,1, &(maskhdr->color_space)); - } - if(ret) - return NS_OK; - else - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -ImgDCallbk::ImgDCBResetPalette() -{ - PRBool ret=PR_FALSE; - if( ilContainer != NULL ) { - ret = il_reset_palette(ilContainer); - } - if(ret) - return NS_OK; - else - return NS_ERROR_FAILURE; -} - - -NS_IMETHODIMP -ImgDCallbk::ImgDCBHaveHdr(int destwidth, int destheight) -{ - if( ilContainer != NULL ) { - il_dimensions_notify(ilContainer, destwidth, destheight); - } - return NS_OK; //no mem allocated here. -} - -NS_IMETHODIMP -ImgDCallbk::ImgDCBInitTransparentPixel() -{ - PRBool ret=PR_FALSE; - - if( ilContainer != NULL ) { - ret = il_init_image_transparent_pixel(ilContainer); - } - if(ret) - return NS_OK; - else - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -ImgDCallbk::ImgDCBDestroyTransparentPixel() -{ - if( ilContainer != NULL ) { - il_destroy_image_transparent_pixel(ilContainer); - } - return NS_OK; //no mem allocated here. -} - -NS_IMETHODIMP -ImgDCallbk :: ImgDCBHaveRow(PRUint8 *rowbuf, PRUint8* rgbrow, - int x_offset, int len, - int row, int dup_rowcnt, - PRUint8 draw_mode, - int pass ) -{ - PRBool ret=PR_FALSE; - - if( ilContainer != NULL ) { - - ret = il_emit_row(ilContainer, rowbuf, rgbrow, x_offset, len, - row, dup_rowcnt, (il_draw_mode)draw_mode, pass ); - } - if(ret) - return NS_OK; - else - return NS_ERROR_FAILURE; - -} - -NS_IMETHODIMP -ImgDCallbk :: ImgDCBHaveImageFrame() -{ - if( ilContainer != NULL ) { - il_frame_complete_notify(ilContainer); - } - return NS_OK; //no mem allocated here. -} - -NS_IMETHODIMP -ImgDCallbk::ImgDCBFlushImage() -{ - if( ilContainer != NULL ) { - il_flush_image_data(ilContainer); - } - return NS_OK; -} - -NS_IMETHODIMP -ImgDCallbk:: ImgDCBImageSize() -{ - int ret = 0; - if( ilContainer != NULL ) { - ret = il_size(ilContainer); //still uses old imglib error msgs - // ret!=0 indicates error. - } - if(ret == 0) - return NS_OK; - else - return NS_ERROR_FAILURE; -} - -NS_IMETHODIMP -ImgDCallbk :: ImgDCBHaveImageAll() -{ - if( ilContainer != NULL ) { - il_image_complete(ilContainer); - } - return NS_OK; - -} - -NS_IMETHODIMP -ImgDCallbk :: ImgDCBError() -{ - if( ilContainer != NULL ) { - //implement me - } - return NS_OK; //no mem allocated here. - -} - -void* -ImgDCallbk :: ImgDCBSetTimeout(TimeoutCallbackFunction func, void* closure, PRUint32 msecs) -{ - return( IL_SetTimeout(func, closure, msecs )); - -} - -NS_IMETHODIMP -ImgDCallbk :: ImgDCBClearTimeout(void *timer_id) -{ - IL_ClearTimeout(timer_id); - return NS_OK; -} - -/*********************** Image Observer Notification. ************************* -* -* These functions are used to send messages to registered observers of an -* individual image client i.e. an IL_ImageReq. -* -******************************************************************************/ - -/* Fabricate a descriptive title for the image and notify observers. Used for - calls to the image viewer. */ -static void -il_description_notify(il_container *ic) -{ - char buf[36]; - IL_MessageData message_data; - IL_ImageReq *image_req; - NI_PixmapHeader *img_header = &ic->image->header; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - - PR_snprintf(buf, sizeof(buf), XP_GetString(XP_MSG_IMAGE_PIXELS), ic->type, - img_header->width, img_header->height); - - PR_ASSERT(ic->clients); - for (image_req = ic->clients; image_req; image_req = image_req->next) { - if (image_req->is_view_image) { - message_data.image_instance = image_req; - message_data.description = buf; /* Note scope limitation. Observer - must copy if necessary. */ - XP_NotifyObservers(image_req->obs_list, IL_DESCRIPTION, &message_data); - } - } -} - -/* Notify observers of the target dimensions of the image. */ -void -il_dimensions_notify(il_container *ic, int dest_width, int dest_height) -{ - IL_MessageData message_data; - IL_ImageReq *image_req; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - - PR_ASSERT(ic->clients); - for (image_req = ic->clients; image_req; image_req = image_req->next) { - message_data.image_instance = image_req; - message_data.width = dest_width; /* Note: these are stored as */ - message_data.height = dest_height; /* PRUint16s. */ - XP_NotifyObservers(image_req->obs_list, IL_DIMENSIONS, &message_data); - } -} - -/* Notify observers that the image is transparent and has a mask. */ -static void -il_transparent_notify(il_container *ic) -{ - IL_MessageData message_data; - IL_ImageReq *image_req; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - - PR_ASSERT(ic->clients); - for (image_req = ic->clients; image_req; image_req = image_req->next) { - message_data.image_instance = image_req; - XP_NotifyObservers(image_req->obs_list, IL_IS_TRANSPARENT, - &message_data); - } -} - -/* Notify observers that the image pixmap has been updated. */ -void -il_pixmap_update_notify(il_container *ic) -{ - IL_MessageData message_data; - IL_Rect *update_rect = &message_data.update_rect; - IL_ImageReq *image_req; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - - update_rect->x_origin = 0; - update_rect->y_origin = (PRUint16)ic->update_start_row; - update_rect->width = (PRUint16)ic->image->header.width; - update_rect->height = (PRUint16)(ic->update_end_row-ic->update_start_row+1); - - PR_ASSERT(ic->clients); - for(image_req = ic->clients; image_req; image_req = image_req->next) { - /* The user aborted the image loading. Don't display any more image - data */ - if (image_req->stopped) - continue; - - message_data.image_instance = image_req; - XP_NotifyObservers(image_req->obs_list, IL_PIXMAP_UPDATE, - &message_data); - } -} - -/* Notify observers that the image has finished decoding. */ -void -il_image_complete_notify(il_container *ic) -{ - IL_MessageData message_data; - IL_ImageReq *image_req; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - - for (image_req = ic->clients; image_req; image_req = image_req->next) { - message_data.image_instance = image_req; - XP_NotifyObservers(image_req->obs_list, IL_IMAGE_COMPLETE, - &message_data); - } -} - -/* Notify observers that a frame of an image animation has finished - decoding. */ -void -il_frame_complete_notify(il_container *ic) -{ - IL_MessageData message_data; - IL_ImageReq *image_req; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - - for (image_req = ic->clients; image_req; image_req = image_req->next) { - message_data.image_instance = image_req; - XP_NotifyObservers(image_req->obs_list, IL_FRAME_COMPLETE, - &message_data); - } -} - -int -il_compute_percentage_complete(int row, il_container *ic) -{ - PRUintn percent_height; - int percent_done = 0; - - percent_height = (PRUintn)(row * (PRUint32)100 / ic->image->header.height); - switch(ic->pass) { - case 0: percent_done = percent_height; /* non-interlaced GIF */ - break; - case 1: percent_done = percent_height / 8; - break; - case 2: percent_done = 12 + percent_height / 8; - break; - case 3: percent_done = 25 + percent_height / 4; - break; - case 4: percent_done = 50 + percent_height / 2; - break; - default: - ILTRACE(0,("Illegal interlace pass")); - break; - } - - return percent_done; -} - -/* Notify observers of image progress. */ -void -il_progress_notify(il_container *ic) -{ - PRUintn percent_done; - static PRUintn last_percent_done = 0; - int row = ic->update_end_row; - IL_MessageData message_data; - IL_ImageReq *image_req; - NI_PixmapHeader *img_header = &ic->image->header; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - - /* No more progress bars for GIF animations after initial load. */ - if (ic->is_looping) - return; - - /* Calculate the percentage of image decoded (not displayed) */ - if(ic->content_length) { - percent_done = - (PRUint32)100 * ic->bytes_consumed / ((PRUint32)ic->content_length); - - /* Some protocols, e.g. gopher, don't support content-length, so - * show the percentage of the image displayed instead - */ - } else { - /* Could be zero if before il_size() is called. */ - if (img_header->height == 0) - return; - int ret; - /* Interlaced GIFs are weird */ - if ((ret = nsCRT::strncasecmp(ic->type, "image/gif", 9)) == 0) { - percent_done = il_compute_percentage_complete(row, ic); - } - else - { - /* This isn't correct for progressive JPEGs, but there's - * really nothing we can do about that because the number - * of scans in a progressive JPEG isn't known until the - * whole file has been read. - */ - percent_done = (PRUintn)(row * (PRUint32)100 / img_header->height); - - } - } - - if (percent_done != last_percent_done) { - PR_ASSERT(ic->clients); - for (image_req = ic->clients; image_req; image_req = image_req->next) { - if (image_req->is_view_image) { /* XXXM12N Eliminate this test? */ - message_data.image_instance = image_req; - message_data.percent_progress = percent_done; - - XP_NotifyObservers(image_req->obs_list, IL_PROGRESS, - &message_data); - } - } - last_percent_done = percent_done; - } -} - - -/* Notify observers of information pertaining to a cached image. Note that - this notification is per image request and not per image container. */ -void -il_cache_return_notify(IL_ImageReq *image_req) -{ - IL_MessageData message_data; - il_container *ic = image_req->ic; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - message_data.image_instance = image_req; - - /* This function should only be called if the dimensions are known. */ - PR_ASSERT(ic->state >= IC_SIZED); - - /* First notify observers of the image dimensions. */ - message_data.width = (unsigned short) ic->dest_width; /* Note: these are stored as */ - message_data.height = (unsigned short) ic->dest_height; /* PRUint16s. */ - XP_NotifyObservers(image_req->obs_list, IL_DIMENSIONS, &message_data); - message_data.width = message_data.height = 0; - - /* Fabricate a title for the image and notify observers. Image Plugins - will need to supply information on the image type. */ - il_description_notify(ic); - - /* If the image is transparent and has a mask, notify observers - accordingly. */ - if (ic->mask) - XP_NotifyObservers(image_req->obs_list, IL_IS_TRANSPARENT, - &message_data); - - /* Now send observers a pixmap update notification for the displayable - area of the image. */ - nsCRT::memmove(&message_data.update_rect, &ic->displayable_rect, - sizeof(IL_Rect)); - XP_NotifyObservers(image_req->obs_list, IL_PIXMAP_UPDATE, &message_data); - nsCRT::zero(&message_data.update_rect, sizeof(IL_Rect)); - - if (ic->state == IC_COMPLETE) { - /* Finally send the observers a complete message. */ - XP_NotifyObservers(image_req->obs_list, IL_IMAGE_COMPLETE, - &message_data); - } -} - - -/* 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. */ -void -il_image_destroyed_notify(IL_ImageReq *image_req) -{ - IL_MessageData message_data; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - message_data.image_instance = image_req; - XP_NotifyObservers(image_req->obs_list, IL_IMAGE_DESTROYED, &message_data); - - /* Now destroy the observer list itself. */ - XP_DisposeObserverList(image_req->obs_list); -} - - -/* Notify observers that an error has occured. The observer should call - IL_DisplaySubImage in order to display the icon. Note that this function - is called per image request and not per image. */ -static void -il_icon_notify(IL_ImageReq *image_req, int icon_number, - XP_ObservableMsg message) -{ - IL_GroupContext *img_cx = image_req->img_cx; - int icon_width, icon_height; - IL_MessageData message_data; - - nsCRT::zero(&message_data, sizeof(IL_MessageData)); - - /* Obtain the dimensions of the icon. */ - img_cx->img_cb->GetIconDimensions(img_cx->dpy_cx, &icon_width, - &icon_height, icon_number); - - /* Fill in the message data and notify observers. */ - message_data.image_instance = image_req; - message_data.icon_number = icon_number; - message_data.icon_width = icon_width; - message_data.icon_height = icon_height; - XP_NotifyObservers(image_req->obs_list, message, &message_data); -} - -/********************* Image Group Observer Notification. ********************* -* -* This function is used to send messages to registered observers of an image -* group i.e. an IL_GroupContext. -* -******************************************************************************/ - -/* Notify observers that images have started/stopped loading in the context, - or started/stopped looping in the context. */ -void -il_group_notify(IL_GroupContext *img_cx, XP_ObservableMsg message) -{ - IL_GroupMessageData message_data; - - nsCRT::zero(&message_data, sizeof(IL_GroupMessageData)); - - /* Fill in the message data and notify observers. */ - message_data.display_context = img_cx->dpy_cx; - message_data.image_context = img_cx; - XP_NotifyObservers(img_cx->obs_list, message, &message_data); -} - - -static int -il_init_scaling(il_container *ic) -{ - int scaled_width = ic->image->header.width; - - /* Allocate temporary scale space */ - if (scaled_width != (int)ic->src_header->width) - { - PR_FREEIF(ic->scalerow); - - if (!(ic->scalerow = (unsigned char *)PR_MALLOC(scaled_width * 3))) - { - ILTRACE(0,("il: MEM scale row")); - return MK_OUT_OF_MEMORY; - } - } - return 0; -} - -/* 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. */ -PRBool -il_init_image_transparent_pixel(il_container *ic) -{ - IL_IRGB *img_trans_pixel = ic->image->header.transparent_pixel; - - if (!img_trans_pixel) { - img_trans_pixel = PR_NEWZAP(IL_IRGB); - if (!img_trans_pixel) - return PR_FALSE; - - if (ic->background_color) { - nsCRT::memcpy(img_trans_pixel, ic->background_color, sizeof(IL_IRGB)); - } - else { - /* A mask will always be used if no background color was - requested. */ - } - - ic->image->header.transparent_pixel = img_trans_pixel; - } - - return PR_TRUE; -} - -/* Destroy the destination image's transparent pixel. */ -void -il_destroy_image_transparent_pixel(il_container *ic) -{ - NI_PixmapHeader *img_header = &ic->image->header; - - PR_FREEIF(img_header->transparent_pixel); - img_header->transparent_pixel = NULL; -} - -/* 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. */ -int -il_size(il_container *ic) -{ - float aspect; - int status; - PRUint8 img_depth; - PRUint32 src_width, src_height; - int32 image_bytes, old_image_bytes; - IL_GroupContext *img_cx = ic->img_cx; - NI_PixmapHeader *src_header = ic->src_header; /* Source image header. */ - NI_PixmapHeader *img_header = &ic->image->header; /* Destination image - header. */ - PRUint32 req_w=0, req_h=0; /* store requested values for printing.*/ - - - /* Get the dimensions of the source image. */ - src_width = src_header->width; - src_height = src_header->height; - - /* Ensure that the source image has a sane area. */ - if (!src_width || !src_height || - (src_width > MAX_IMAGE_WIDTH) || - (src_height > MAX_IMAGE_HEIGHT)) { - ILTRACE(1,("il: bad image size: %dx%d", src_width, src_height)); - return MK_IMAGE_LOSSAGE; - } - - ic->state = IC_SIZED; - - if(ic->display_type == IL_Printer){ - req_w = ic->dest_width; - req_h = ic->dest_height; - ic->dest_width = 0; /*to decode natural size*/ - ic->dest_height = 0; - } - - /* For now, we don't allow an image to change output size on the - * fly, but we do allow the source image size to change, and thus - * we may need to change the scaling factor to fit it into the - * same size container on the display. - */ - if (ic->sized) { - status = il_init_scaling(ic); - return status; - } - - /* This must appear before il_init_img_header. */ - old_image_bytes = (int32)img_header->widthBytes * img_header->height; - - /* Initialize the dimensions of the destination image header structure - to be the dimensions of the source image. The Display Front End will - reset these dimensions to be the target dimensions of the image if - it does not handle scaling. */ - img_header->width = src_width; - img_header->height = src_height; - - /* Determine the target dimensions of the image. */ - aspect = (float)src_width/(float)src_height; - if (!ic->dest_width && !ic->dest_height) { - /* Both target dimensions were unspecified, so use the dimensions of - the source image. */ - ic->dest_width = src_width; - ic->dest_height = src_height; - } - else if (ic->dest_width && ic->dest_height) { - /* Both target dimensions were specified; determine if this causes - aspect ratio distortion. */ - if (ic->dest_width * src_height != ic->dest_height * src_width) - ic->aspect_distorted = PR_TRUE; - } - else if (ic->dest_width) { - /* Only the target width was specified. Determine the target height - which preserves aspect ratio. */ - ic->dest_height = (int)((float)ic->dest_width / aspect + 0.5); - } - else { - /* Only the target height was specified. Determine the target width - which preserves aspect ratio. */ - ic->dest_width = (int)(aspect * (float)ic->dest_height + 0.5); - } - if (ic->dest_width == 0) ic->dest_width = 1; - if (ic->dest_height == 0) ic->dest_height = 1; - - /* Determine if the image will be displayed at its natural size. */ - if (ic->dest_width == src_width && ic->dest_height == src_height) - ic->natural_size = PR_TRUE; - - /* Check that the target image dimensions are reasonable. */ - if ((ic->dest_width > MAX_IMAGE_WIDTH) || - (ic->dest_height > MAX_IMAGE_HEIGHT)) { - return MK_IMAGE_LOSSAGE; - } - - ILTRACE(2,("il: size %dx%d, scaled from %dx%d, ic = 0x%08x\n", - ic->dest_width, ic->dest_height, src_width, src_height, ic)); - - /* Determine the number of bytes per scan-line. Image data must be - quadlet aligned for optimizations. */ - img_depth = img_header->color_space->pixmap_depth; - img_header->widthBytes = (img_header->width * img_depth + 7) / 8; - img_header->widthBytes = ROUNDUP(img_header->widthBytes, 4); - - /* Create and initialize the mask pixmap structure, if required. A mask - is allocated only if the image is transparent and no background color - was specified for this image request. */ - if ((src_header->transparent_pixel && !ic->background_color) - ||(img_header->alpha_bits)) - { - if (!ic->mask) { - NI_PixmapHeader *mask_header; - - if (!(ic->mask = PR_NEWZAP(IL_Pixmap))) { - return MK_OUT_OF_MEMORY; - } - - mask_header = &ic->mask->header; - PRBool ret; - if(img_header->alpha_bits) - ret = IL_CreateGreyScaleColorSpace(1, img_header->alpha_bits, &mask_header->color_space); - else - ret = IL_CreateGreyScaleColorSpace(1, 1, &mask_header->color_space); - - if ((!ret)||(!mask_header->color_space)) - return MK_OUT_OF_MEMORY; - - mask_header->alpha_bits = img_header->alpha_bits; - mask_header->is_mask = PR_TRUE; - - mask_header->width = img_header->width; - mask_header->height = img_header->height; - if(img_header->alpha_bits == 1) - mask_header->widthBytes = (mask_header->width + 7) / 8; - if(img_header->alpha_bits == 8) - mask_header->widthBytes = mask_header->width; - - /* Mask data must be quadlet aligned for optimizations */ - mask_header->widthBytes = ROUNDUP(mask_header->widthBytes, 4); - } - - /* Notify observers that the image is transparent and has a mask. */ - il_transparent_notify(ic); - } - else if (ic->mask) /* for png alpha*/ { - il_transparent_notify(ic); - if(ic->background_color){ -/* - src_header->transparent_pixel = ic->background_color; - img_header->transparent_pixel = ic->background_color; - - nsCRT::memcpy(img_trans_pixel, ic->background_color, sizeof(IL_IRGB)); -*/ - }else{ -/* - il_destroy_pixmap(ic->img_cb, ic->mask); - ic->mask = NULL; -*/ - } - - } - - ic->sized = 1; - /* Notify observers of the target dimensions of the image. */ - ic->imgdcb->ImgDCBHaveHdr(ic->dest_width, ic->dest_height); - - /* Fabricate a title for the image and notify observers. Image Plugins - will need to supply information on the image type. */ - il_description_notify(ic); - - /* If the display front-end doesn't support scaling, IMGCBIF_NewPixmap will - set the image and mask dimensions to scaled_width and scaled_height. */ - nsresult rv; - rv = img_cx->img_cb->NewPixmap(img_cx->dpy_cx, ic->dest_width, - ic->dest_height, ic->image, ic->mask); - if (NS_FAILED(rv)) - return MK_OUT_OF_MEMORY; - - if (!ic->image->haveBits) - return MK_OUT_OF_MEMORY; - - if (ic->mask && !ic->mask->haveBits) - return MK_OUT_OF_MEMORY; - - rv = img_cx->img_cb->SetImageNaturalDimensions(ic->image, src_width, src_height); - - /* Adjust the total cache byte count to reflect any departure from the - original predicted byte count for this image. */ - image_bytes = (int32)img_header->widthBytes * img_header->height; - if (image_bytes - old_image_bytes) - il_adjust_cache_fullness(image_bytes - old_image_bytes); - - /* If we have a mask, initialize its bits. */ - if (ic->mask) { - NI_PixmapHeader *mask_header = &ic->mask->header; - PRUint32 mask_size = mask_header->widthBytes * mask_header->height; - - img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, ic->mask, - IL_LOCK_BITS); - - memset (ic->mask->bits, ~0, mask_size); - img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, ic->mask, - IL_UNLOCK_BITS); - } - - if ((status = il_init_scaling(ic)) < 0) - return status; - - - /* XXXM12N Clean this up */ - /* Get memory for quantizing. (required amount depends on image width) */ - if (img_header->color_space->type == NI_PseudoColor) { - if (!il_init_quantize(ic)) { - ILTRACE(0,("il: MEM il_init_quantize")); - return MK_OUT_OF_MEMORY; - } - } - - if((ic->display_type == IL_Printer)&& (req_w || req_h)){ - ic->dest_width = req_w; - ic->dest_height = req_h; - } - - return 0; -} - - -#define IL_SIZE_CHUNK 128 -#ifdef XP_MAC -# if TARGET_CPU_PPC -# define IL_PREFERRED_CHUNK 8192 -# define IL_OFFSCREEN_CHUNK 128 -# else /* normal mac */ -# define IL_PREFERRED_CHUNK 4096 -# define IL_OFFSCREEN_CHUNK 128 -# endif -#else /* !XP_MAC */ -# define IL_PREFERRED_CHUNK 2048 -# define IL_OFFSCREEN_CHUNK 128 -#endif - -int -IL_StreamWriteReady(il_container *ic) -{ - nsresult rv= NS_ERROR_FAILURE; - PRUint32 max_read = 0; - - if (ic->imgdec) - rv = ic->imgdec->ImgDWriteReady(&max_read); - - if(NS_FAILED(rv)) - return IL_OFFSCREEN_CHUNK; - - if(max_read == 0) - return 0; //send no more data please - - /* - * It could be that layout aborted image loading by calling IL_FreeImage - * before the netlib finished transferring data. Don't do anything. - */ - - if(ic->state == IC_ABORT_PENDING) - return IL_OFFSCREEN_CHUNK; - if (!ic->sized) - /* A (small) default initial chunk */ - return IL_SIZE_CHUNK; - - return IL_PREFERRED_CHUNK; - -} - -/* Given the first few bytes of a stream, identify the image format */ -PRBool -sniffout_mimetype(const char *buf, int32 len, char* aContentType) -{ - int i; - - if (len >= 4 && !nsCRT::strncmp(buf, "GIF8", 4)) - { - PR_snprintf(aContentType, 10,"%s", "image/gif"); - return PR_TRUE; - } - - /* for PNG */ - if (len >= 4 && ((unsigned char)buf[0]==0x89 && - (unsigned char)buf[1]==0x50 && - (unsigned char)buf[2]==0x4E && - (unsigned char)buf[3]==0x47)) - { - PR_snprintf(aContentType, 10,"%s","image/png"); - return PR_TRUE; - } - - - /* JFIF files start with SOI APP0 but older files can start with SOI DQT - * so we test for SOI followed by any marker, i.e. FF D8 FF - * this will also work for SPIFF JPEG files if they appear in the future. - * - * (JFIF is 0XFF 0XD8 0XFF 0XE0 0X4A 0X46 0X49 0X46 0X00) - */ - if (len >= 3 && - ((unsigned char)buf[0])==0xFF && - ((unsigned char)buf[1])==0xD8 && - ((unsigned char)buf[2])==0xFF) - { - PR_snprintf(aContentType, 11,"%s", "image/jpeg"); - return PR_TRUE; - } - - /* ART begins with JG (4A 47). Major version offset 2. - Minor version offset 3. Offset 4 must be NULL. - */ - if (len >= 5 && - ((unsigned char) buf[0])==0x4a && - ((unsigned char) buf[1])==0x47 && - ((unsigned char) buf[4])==0x00 ) - { - PR_snprintf(aContentType, 11,"%s", "image/x-jg"); - return PR_TRUE; - } - - - /* no simple test for XBM vs, say, XPM so punt for now */ - if (len >= 8 && !strncmp(buf, "#define ", 8) ) - { - /* Don't contradict the given type, since this ID isn't definitive */ - PR_snprintf(aContentType, 8,"%s", "unknown"); - return PR_TRUE; - } - - if (len < 12) - { - ILTRACE(1,("il: too few bytes to determine type")); - PR_snprintf(aContentType, 8,"%s", "unknown"); - return PR_FALSE; - } - - /* all the servers return different formats so root around */ - for (i=0; i<28; i++) - { - if (!strncmp(&buf[i], "Not Fou", 7)){ - PR_snprintf(aContentType, 8,"%s", "unknown"); - return PR_FALSE; - } - } - - //just in case - PR_snprintf(aContentType, 8,"%s", "unknown"); - return PR_FALSE; -} - -/* - * determine what kind of image data we are dealing with - */ - - -IL_IMPLEMENT(int) -IL_Type(const char *buf, int32 len) -{ - char aContent[200]; - return sniffout_mimetype(buf, len, aContent); -} - - -int -IL_StreamWrite(il_container *ic, const unsigned char *str, int32 len) -{ - nsresult rv; - - ILTRACE(4, ("il: write with %5d bytes for %s\n", len, ic->url_address)); - - /* - * Layout may have decided to abort this image in mid-stream, - * but netlib doesn't know about it yet and keeps sending - * us data. Force the netlib to abort. - */ - if (ic->state == IC_ABORT_PENDING) - return -1; - - /* Has user hit the stop button ? */ - if (il_image_stopped(ic)) - return -1; - - ic->bytes_consumed += len; - - if (len) - rv = ic->imgdec->ImgDWrite(str, len); - - /* Notify observers of image progress. */ - il_progress_notify(ic); - - if(NS_FAILED(rv)) - return -1; - else - return len; -} - - -int -IL_StreamFirstWrite(il_container *ic, const unsigned char *str, int32 len) -{ - nsresult rv = NS_OK; - - PR_ASSERT(ic); - PR_ASSERT(ic->image); - - /* If URL redirection occurs, the url stored in the - image container is the redirect url not the image file url. - If the image is animated, the imglib will never match the - file name in the cache unless you update ic->url_address. - ic->fetch_url keeps the actual url for you. - */ - - /* ic->fetch_url is being set in NetReaderImpl::FirstWrite(..). - This is just a backup code to set ic->fetch_url, in the case - we do not set ic->fetch_url in NetReaderImpl::FirstWrite(..).*/ - -// FREE_IF_NOT_NULL(ic->fetch_url); - - if (!ic->fetch_url) { - if (ic->url) { - ic->fetch_url = ic->url->GetAddress(); - } - else { - if(ic->url_address) // check needed because of mkicons.c - ic->fetch_url = PL_strdup(ic->url_address); - else - ic->fetch_url = NULL; - } - } - - /* if our mime sniffer can recognize what's in the - data stream and it is one of our std vanilla types. - Check to see if it matches the mimetype sent by creator. - */ - char contenttype[50]; - if(sniffout_mimetype((const char*) str, len, contenttype)){ - // data type understood by mime sniffer - if(nsCRT::strcmp(contenttype, ic->type) != 0){ - //what the sniff saw and what the mime header said is - //different. We'll believe the data from the sniffer - nsCRT::free(ic->type); - ic->type = nsCRT::strdup(contenttype); - } - } - - nsIImgDecoder *imgdec ; - char imgtypestr[200]; - - PR_snprintf(imgtypestr, sizeof(imgtypestr), "@mozilla.org/image/decoder;1?type=%s" - , ic->type ); - - static NS_DEFINE_IID(kIImgDecoderIID, NS_IIMGDECODER_IID); - rv = nsComponentManager::CreateInstance(imgtypestr, NULL, - kIImgDecoderIID, - (void **)&imgdec); - - /* we did our best. Gotta give up. */ - if (NS_FAILED(rv)){ - return MK_IMAGE_LOSSAGE; - } - - imgdec->SetContainer(ic); - // We will already have a decoder instance for this - // image container if the image is animated. For now, - // we release it before taking the new one. - // Later I'll see how animated image containers can - // reuse the decoder for subsequent frames. - if(ic->imgdec) - NS_RELEASE(ic->imgdec); - ic->imgdec = imgdec; - - rv = ic->imgdec->ImgDInit(); - - if(NS_FAILED(rv)){ - NS_RELEASE(ic->imgdec); - ic->imgdec = nsnull; - ILTRACE(0,("il: image init failed")); - return MK_OUT_OF_MEMORY; - } - - return 0; //ok -} - - -/* Called when a container is aborted by Netlib. */ -static void -il_container_aborted(il_container *ic) -{ - IL_ImageReq *image_req; - IL_GroupContext *img_cx; - il_context_list *current; - - /* Keep track of the fact that this container was aborted by Netlib, - and guard against multiple calls to this routine. */ - if (ic->is_aborted) - return; - ic->is_aborted = PR_TRUE; - - /* Notify image observers that the image was aborted. */ - for (image_req = ic->clients; image_req; image_req = image_req->next) { - il_icon_notify(image_req, IL_IMAGE_DELAYED, IL_ABORTED); - } - - /* Now handle image group observers. */ - for (current = ic->img_cx_list; current; current = current->next) { - /* Increment the count of images in this context which were aborted - by Netlib. Observer notification takes place if there were - previously no aborted images in this context. */ - img_cx = current->img_cx; - if (!img_cx->num_aborted) - il_group_notify(img_cx, IL_ABORTED_LOADING); - img_cx->num_aborted++; - -#ifdef DEBUG_GROUP_OBSERVER - ILTRACE(1,("1 img_cx=%x total=%d loading=%d looping=%d aborted=%d", - img_cx, img_cx->num_containers, img_cx->num_loading, - img_cx->num_looping, img_cx->num_aborted)); -#endif /* DEBUG_GROUP_OBSERVER */ - } -} - - -static void -il_bad_container(il_container *ic) -{ - IL_ImageReq *image_req; - - ILTRACE(4,("il: bad container, sending icon")); - if((ic->type)&& - ((nsCRT::strlen(ic->type) < 8) || - (nsCRT::strncmp(ic->type, "unknown", 7)==0))) { - ic->state = IC_MISSING; - for (image_req = ic->clients; image_req; image_req = image_req->next) - il_icon_notify(image_req, IL_IMAGE_NOT_FOUND, IL_ERROR_NO_DATA); - } - else { - if (ic->state == IC_INCOMPLETE) { - il_container_aborted(ic); - } - else { - for (image_req = ic->clients; image_req; - image_req = image_req->next) - il_icon_notify(image_req, IL_IMAGE_BAD_DATA, - IL_ERROR_IMAGE_DATA_TRUNCATED); - } - } - - /* Image container gets deleted later. */ -} - -/* IL_GetURL completion callback. */ -void -IL_NetRequestDone(il_container *ic, ilIURL *url, int status) -{ - IL_ImageReq *image_req; - PR_ASSERT(ic); - - /* Record the fact that NetLib is done loading. */ - if (ic->url == url) { - ic->is_url_loading = PR_FALSE; - } - /* The (ic->url == url) check is for a weird timer issue, see the comment at the - end of this function. */ - - /* - * It could be that layout aborted image loading by calling IL_DestroyImage - * before the netlib finished transferring data. If so, really do the - * freeing of the data that was deferred there. - */ - if (ic->state == IC_ABORT_PENDING) { - ic->is_url_loading = PR_FALSE; - il_delete_container(ic); - NS_RELEASE(url); - return; - } - - if (status < 0) { - ILTRACE(2,("il:net done ic=0x%08x, status=%d, ic->state=0x%02x\n", - ic, status, ic->state)); - - /* Netlib detected failure before a stream was even created. */ - if (ic->state < IC_BAD) { - if (status == MK_OBJECT_NOT_IN_CACHE) - ic->state = IC_NOCACHE; - else if (status == MK_UNABLE_TO_LOCATE_FILE) - ic->state = IC_MISSING; - else { - /* status is probably MK_INTERRUPTED */ - ic->state = IC_INCOMPLETE; /* try again on reload */ - } - - if (!ic->sized) { - if (status == MK_OBJECT_NOT_IN_CACHE) { - for (image_req = ic->clients; image_req; - image_req = image_req->next) - il_icon_notify(image_req, IL_IMAGE_DELAYED, - IL_NOT_IN_CACHE); - } - else if (status == MK_INTERRUPTED) { - il_container_aborted(ic); - } - else if (status == MK_UNABLE_TO_LOCATE_FILE) { - for (image_req = ic->clients; image_req; - image_req = image_req->next) - il_icon_notify(image_req, IL_IMAGE_NOT_FOUND, - IL_ERROR_NO_DATA); - } - else { - for (image_req = ic->clients; image_req; - image_req = image_req->next) - il_icon_notify(image_req, IL_IMAGE_BAD_DATA, - IL_ERROR_IMAGE_DATA_ILLEGAL); - } - } - } - } - else { - /* It is possible for NetLib to call the exit routine with a success status, - even though the stream was never created (this can happen when fetching - a mime image part which contains no image data.) Show a missing image - icon. */ - if (ic->state < IC_STREAM) { - ic->state = IC_MISSING; - for (image_req = ic->clients; image_req; image_req = image_req->next) - il_icon_notify(image_req, IL_IMAGE_NOT_FOUND, IL_ERROR_NO_DATA); - } - } - - if (ic->url == url) { - NS_RELEASE(url); - ic->url = NULL; - } - /* else there is actually another load going on from a looping gif. - * Weird timer issue. If ic->url does not equal url, then il_image_complete was - * already called for "url" and a new load started. ic->url is the url for - * the new load and will be released in its IL_NetRequestDone. "url" was already - * released by special code in il_image_complete. - */ -} - - -void -il_image_abort(il_container *ic) -{ - if (ic->imgdec) - ic->imgdec->ImgDAbort(); - - /* Clear any pending timeouts */ - if (ic->row_output_timeout) { - IL_ClearTimeout(ic->row_output_timeout); - ic->row_output_timeout = NULL; - } -} - -static void -IL_ChromeAlphaAbuseCheck(il_container *ic) -{ - IL_Pixmap *mask = ic->mask; - NI_PixmapHeader *header = &mask->header; - PRUint8 *alpha = (PRUint8 *)mask->bits; - - if (ic->image->header.alpha_bits == 8) { - unsigned num000 = 0, num255 = 0; - for (unsigned y=0; yheight; y++, alpha+=header->widthBytes) - for (unsigned x=0; xwidth; x++) { - if (alpha[x] == 0) - num000++; - else if (alpha[x] == 255) - num255++; - } -#ifdef DEBUG - if (num000+num255 == header->width*header->height) { - fprintf(stderr, "CHROME ALPHA ABUSE\n"); - fprintf(stderr, "\tusing an 8-bit alpha channel to represent binary alpha\n"); - fprintf(stderr, "\t%s\n", ic->url_address); - fprintf(stderr, "\tnum000=%d num255=%d sum=%d w*h=%d\n", - num000, num255, num000+num255, header->width*header->height); - } -#endif - } else if (ic->image->header.alpha_bits == 1) { - PRBool constAlpha=PR_TRUE; - - /* check full bytes */ - for (unsigned y=0; - yheight && constAlpha; - y++, alpha+=header->widthBytes) - for (unsigned x=0; xwidth/8; x++) - if (alpha[x] != 255) { - constAlpha = PR_FALSE; - break; - } - - /* check trailing bits */ - PRUint8 mask = 255; - mask <<= 8-(header->width&7); - if (mask && constAlpha) - for (unsigned y=0; - yheight; - y++, alpha+=header->widthBytes) - if ((alpha[header->width/8]&mask) != mask) { - constAlpha = PR_FALSE; - break; - } -#ifdef DEBUG - if (constAlpha) { - fprintf(stderr, "CHROME ALPHA ABUSE\n"); - fprintf(stderr, "\tfully opaque 1-bit alpha mask\n"); - fprintf(stderr, "\t%s\n", ic->url_address); - } -#endif - } -} - - -void -IL_StreamComplete(il_container *ic, PRBool is_multipart) -{ -#ifdef DEBUG - PRTime cur_time; - PRInt32 difference; -#endif /* DEBUG */ - - PR_ASSERT(ic); - if(ic->type){ - nsCRT::free(ic->type); - ic->type = NULL; - } -#ifdef DEBUG - cur_time = PR_Now(); - LL_SUB(cur_time, cur_time, ic->start_time); - difference = LL_L2I(difference, cur_time); - ILTRACE(1, ("il: complete: %d seconds for %s\n", - difference, ic->url_address)); -#endif /* DEBUG */ - - /* Check for abuse of alpha in chrome images */ - if ((ic->moz_type == TYPE_CHROME) && ic->image->header.alpha_bits) - IL_ChromeAlphaAbuseCheck(ic); - - ic->is_multipart = is_multipart; - - if (ic->imgdec) - ic->imgdec->ImgDComplete(); - else - il_image_complete(ic); -} - - -/* Called when the container has finished loading to update the number of - actively loading image containers in each of the client contexts. - Non-looping images are considered to have been loaded upon natural - completion of network activity for the image. Looping images, on the - other hand, are deemed to have been loaded once the first iteration of - the animation is complete. */ -static void -il_container_loaded(il_container *ic) -{ - il_context_list *current; - IL_GroupContext *img_cx; - - for (current = ic->img_cx_list; current; current = current->next) { - /* Decrement the number of actively loading image containers in the - client context. */ - img_cx = current->img_cx; - img_cx->num_loading--; - if (!img_cx->num_loading) { - /* If this is the last image to have loaded in the group, - notify observers that images stopped loading. */ - il_group_notify(img_cx, IL_FINISHED_LOADING); - } - -#ifdef DEBUG_GROUP_OBSERVER - ILTRACE(1,("2 img_cx=%x total=%d loading=%d looping=%d aborted=%d", - img_cx, img_cx->num_containers, img_cx->num_loading, - img_cx->num_looping, img_cx->num_aborted)); -#endif /* DEBUG_GROUP_OBSERVER */ - } -} - - -/* Called when a container starts/stops looping to update the number of - looping image containers in each of the client containers. An animated - image is considered to have started looping at the beginning of the - second iteration. */ -static void -il_container_looping(il_container *ic) -{ - PRBool is_looping = (PRBool)ic->is_looping; - il_context_list *current; - IL_GroupContext *img_cx; - - for (current = ic->img_cx_list; current; current = current->next) { - img_cx = current->img_cx; - if (is_looping) { /* Image has started looping. */ - /* Increment the number of looping image containers in the client - context. Observer notification takes place if the image group - previously had no looping images. */ - if (!img_cx->num_looping) - il_group_notify(img_cx, IL_STARTED_LOOPING); - img_cx->num_looping++; - -#ifdef DEBUG_GROUP_OBSERVER - ILTRACE(1,("3 img_cx=%x total=%d loading=%d looping=%d aborted=%d", - img_cx, img_cx->num_containers, img_cx->num_loading, - img_cx->num_looping, img_cx->num_aborted)); -#endif /* DEBUG_GROUP_OBSERVER */ - } - else { /* Image has stopped looping. */ - /* Decrement the number of looping image containers in the client - context. Observer notification takes place if this was - the last looping image in the group. */ - img_cx->num_looping--; - if (!img_cx->num_looping) - il_group_notify(img_cx, IL_FINISHED_LOOPING); - -#ifdef DEBUG_GROUP_OBSERVER - ILTRACE(1,("4 img_cx=%x total=%d loading=%d looping=%d aborted=%d", - img_cx, img_cx->num_containers, img_cx->num_loading, - img_cx->num_looping, img_cx->num_aborted)); -#endif /* DEBUG_GROUP_OBSERVER */ - } - } -} - - -/* Called when all activity within a container has successfully completed. */ -static void -il_container_complete(il_container *ic) -{ - IL_GroupContext *img_cx = ic->img_cx; - - /* Update the image (and mask) pixmaps for the final time. */ - il_flush_image_data(ic); - - /* Tell the Front Ends that we will not modify the bits any further. */ - img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, ic->image, - IL_RELEASE_BITS); - if (ic->mask) { - img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, ic->mask, - IL_RELEASE_BITS); - } - - if (!ic->is_looping) { - /* Tell the client contexts that the container has finished - loading. We don't do this for looping images which have just - finished looping, since we called il_container_loaded at the - time the first iteration completed. */ - il_container_loaded(ic); - } - else { - /* This is a looping image whose loop count has reached zero, so - set the container's state to indicate that it is no longer - looping. */ - ic->is_looping = PR_FALSE; - - /* Inform the client contexts that the container has stopped - looping. */ - il_container_looping(ic); - } - - /* Set the container's state to complete. This indicates that the - natural completion of network activity for the image. */ - ic->state = IC_COMPLETE; - -} - - -/* XXXM12N This routine needs to be broken up into smaller components. */ -void -il_image_complete(il_container *ic) -{ - NI_PixmapHeader *src_header = ic->src_header; - IL_DisplayType display_type = ic->display_type; - ilINetReader *reader; - - - switch( ic->state ){ - - case IC_ABORT_PENDING: - /* It could be that layout aborted image loading by calling - IL_DestroyImage() before the netlib finished transferring data. - Don't do anything. */ - il_scour_container(ic); - break; - - case IC_VIRGIN: - case IC_START: - case IC_STREAM: - /* If we didn't size the image, but the stream finished loading, the - image must be corrupt or truncated. */ - if(!(ic->is_multipart)){ - ic->state = IC_BAD; - il_bad_container(ic); - } - break; - - case IC_SIZED: - case IC_MULTI: - - PR_ASSERT(ic->image && ic->image->haveBits); - - ILTRACE(1,("il: complete %d image width %d (%d) height %d," - " depth %d, %d colors", - ic->multi, - ic->image->header.width, - ic->image->header.widthBytes, - ic->image->header.height, - ic->image->header.color_space->pixmap_depth, - ic->image->header.color_space->cmap.num_colors)); - - /* 3 cases: simple, multipart MIME, multi-image animation */ - if((ic->animate_request == eImageAnimation_LoopOnce) - ||(!ic->loop_count && !ic->is_multipart)) { - /* A single frame, single part image. */ - il_container_complete(ic); - } - else { - /* Display the rest of the last image before starting a new one */ - il_flush_image_data(ic); - - /* Force new colormap to be loaded in case its different from the - * LOSRC or previous images in the multipart message. - * XXX - fur - Shouldn't do this for COLORMAP case. - */ - /* PRBool ret= */ il_reset_palette(ic); - - FREE_IF_NOT_NULL(src_header->color_space->cmap.map); - FREE_IF_NOT_NULL(src_header->transparent_pixel); - il_destroy_image_transparent_pixel(ic); - FREE_IF_NOT_NULL(ic->comment); - ic->comment_length = 0; - - /* Handle looping, which can be used to replay an animation. */ - if (ic->loop_count) { - int is_infinite_loop = (ic->loop_count == -1); - ilIURL *netRequest = NULL; - if (!is_infinite_loop) - ic->loop_count--; - - ILTRACE(1,("il: loop %s", ic->url_address)); - - if(ic->net_cx){ - netRequest = ic->net_cx->CreateURL(ic->fetch_url, USE_IMG_CACHE); - if (!netRequest) { /* OOM */ - il_container_complete(ic); - break; - } - }else{ - il_container_complete(ic); - break; - } - - /* Only loop if the image stream is available locally. - Also, if the user hit the "stop" button, don't - allow the animation to loop. */ -#ifdef NU_CACHE - if ((ic->net_cx->IsLocalFileURL(ic->fetch_url) || - ic->net_cx->IsURLInCache(netRequest)) && - (!il_image_stopped(ic)) && - ic->net_cx && - (display_type == IL_Console)) -#else - if ((ic->net_cx->IsLocalFileURL(ic->fetch_url) || - ic->net_cx->IsURLInMemCache(netRequest) || - ic->net_cx->IsURLInDiskCache(netRequest)) && - (!il_image_stopped(ic)) && - ic->net_cx && - (display_type == IL_Console)) -#endif - { - if (!ic->is_looping) { - /* If this is the end of the first pass of the - animation, then set the state of the container - to indicate that we have started looping. */ - ic->is_looping = PR_TRUE; - - /* At this point the animation is considered to have - loaded, so we need to tell the client contexts that - the container has loaded. */ - il_container_loaded(ic); - - /* This is also the point at which the animation is - considered to have started looping, so inform the - client contexts accordingly. */ - il_container_looping(ic); - } - - ic->bytes_consumed = 0; - ic->state = IC_START; - - /* This is to deal with a weird timer bug, see the comment at the - end of IL_NetRequestDone. */ - NS_IF_RELEASE(ic->url); - - ic->url = netRequest; - /* Record the fact that we are calling NetLib to load a URL. */ - ic->is_url_loading = PR_TRUE; - - /* Suppress thermo & progress bar */ - /* Call to netlib for net cache data happens here. */ - netRequest->SetBackgroundLoad(PR_TRUE); - reader = IL_NewNetReader(ic); - - - /* using lclient insures we are using an active image request */ - (void) ic->lclient->net_cx->GetURL(ic->url, USE_IMG_CACHE, reader, PR_TRUE); - - /* Release reader, GetURL will keep a ref to it. */ - NS_RELEASE(reader); - } else { - ic->loop_count = 0; - NS_RELEASE(netRequest); - il_container_complete(ic); - } - } - else if (ic->is_multipart) { - ic->multi++; - ic->state = IC_MULTI; - } - } - break; - - case IC_MISSING: - case IC_NOCACHE: - - default: - break; - - }/*switch*/ - - - /* Clear any pending timeouts */ - if (ic->row_output_timeout) { - IL_ClearTimeout(ic->row_output_timeout); - ic->row_output_timeout = NULL; - } - - /* Notify observers that we are done decoding. */ - if (ic->state != IC_ABORT_PENDING && ic->state != IC_BAD) - il_image_complete_notify(ic); -} - - -void -IL_StreamAbort(il_container *ic, int status) -{ - int old_state; - IL_ImageReq *image_req; - - PR_ASSERT(ic); - - ILTRACE(4,("il: abort, status=%d ic->state=%d", status, ic->state)); - - /* Abort the image. */ - il_image_abort(ic); - if(ic->type){ - nsCRT::free(ic->type); - ic->type = NULL; - } - - - if(ic->state >= IC_SIZED || (ic->state == IC_ABORT_PENDING)){ - if (status == MK_INTERRUPTED){ - il_container_aborted(ic); - } - else{ - for (image_req = ic->clients; image_req; image_req = image_req->next) - il_icon_notify(image_req, IL_IMAGE_BAD_DATA, - IL_ERROR_IMAGE_DATA_ILLEGAL); - } - } - /* - * It could be that layout aborted image loading by calling IL_DestroyImage() - * before the netlib finished transferring data. Don't do anything. - */ - if (ic->state == IC_ABORT_PENDING) - return; - - old_state = ic->state; - - if (status == MK_INTERRUPTED) - ic->state = IC_INCOMPLETE; - else - ic->state = IC_BAD; - - if (old_state < IC_SIZED) - il_bad_container(ic); -} - -PRBool -IL_StreamCreated(il_container *ic, - ilIURL *url, - char* type) -{ - PR_ASSERT(ic); - - /* - * It could be that layout aborted image loading by calling IL_FreeImage() - * before the netlib finished transferring data. Don't do anything. - */ - if (ic->state == IC_ABORT_PENDING) - return PR_FALSE; - - if(ic->type != NULL) - nsCRT::free(ic->type); //can be !NULL in animated gifs. - ic->type = nsCRT::strdup(type); //mime string - ic->content_length = url->GetContentLength(); - char* addr = url->GetAddress(); - ILTRACE(4,("il: new stream, type %s, %s", ic->type, addr)); - nsCRT::free(addr); - ic->state = IC_STREAM; - -#ifndef M12N /* XXXM12N Fix me. */ -#ifdef XP_MAC - ic->image->hasUniqueColormap = PR_FALSE; -#endif -#endif /* M12N */ - - return PR_TRUE; -} - - -/* Phong's linear congruential hash */ -PRUint32 -il_hash(const char *ubuf) -{ - unsigned char * buf = (unsigned char*) ubuf; - PRUint32 h=1; - while(*buf) - { - h = 0x63c63cd9*h + 0x9c39c33d + (int32)*buf; - buf++; - } - return h; -} - -/* block certain hosts from loading images */ -PRBool il_PermitLoad(const char * image_url, nsIImageRequestObserver * aObserver) { - - /* convert image_url to an nsIURL so we can extract host and scheme */ - nsresult rv; - - nsCOMPtr uri; - rv = NS_NewURI(getter_AddRefs(uri), image_url); - if (NS_FAILED(rv)) { - return PR_TRUE; - } - - // remove this code once #73845 is fixed. - nsXPIDLCString scheme; - rv = uri->GetScheme(getter_Copies(scheme)); - if (NS_FAILED(rv) || (!scheme.get())) { - return PR_TRUE; - } - - /* extract scheme -- we block loading of only http and https images */ - PRBool isHTTP = PR_FALSE; - PRBool isHTTPS = PR_FALSE; - if (NS_FAILED(uri->SchemeIs("http", &isHTTP)) || - NS_FAILED(uri->SchemeIs("https", &isHTTPS)) || - (!isHTTP && !isHTTPS)) - return PR_TRUE; - - /* extract host */ - char * host; - rv = uri->GetHost(&host); - if (NS_FAILED(rv) || !host) { - return PR_TRUE; - } - - /* obtain first url from aObserver */ - if (!aObserver) { - Recycle(host); - return PR_TRUE; - } - char* firstHost = 0; - nsCOMPtr frameImageLoader = do_QueryInterface(aObserver); - if (frameImageLoader) { - nsCOMPtr presContext; - rv = frameImageLoader->GetPresContext(getter_AddRefs(presContext)); - if (presContext) { - nsCOMPtr firstURI; - - presContext->GetBaseURL(getter_AddRefs(firstURI)); - - /* Check to see if the image is the whole page, in which case accept it */ - PRBool eq; - - if(firstURI){ - firstURI->Equals(uri, &eq); - if (eq) { - Recycle(host); - return PR_TRUE; - } - rv = firstURI->GetHost(&firstHost); - } - } - } - if (!firstHost) { - firstHost = PL_strdup(host); - } - - /* check to see if we need to block image from loading */ - nsCOMPtr imgmanager(do_GetService(kImgManagerCID, &rv)); - if (NS_FAILED(rv)) { - Recycle(host); - Recycle(firstHost); - return PR_TRUE; - } - PRBool permission; - // commenting this out per pavlov's suggestion. he says this file is - // going away soon. CheckForPermission() no longer exists. - // nsIContentPolicy is used to block images now. - //rv = imgmanager->CheckForPermission(host, firstHost, &permission); - Recycle(host); - Recycle(firstHost); - if (NS_FAILED(rv)) { - return PR_TRUE; - } - return permission; -} - -/* Get requested animation policy from presContext - * normal = 0 - * one frame = 1 - * one loop = 2 - */ -nsImageAnimation -il_check_requested_animation(nsIImageRequestObserver * aObserver) { - - nsresult rv; - nsImageAnimation req_animate = eImageAnimation_Normal; //default value - - nsCOMPtr frameImageLoader = do_QueryInterface(aObserver); - if (frameImageLoader) { - nsCOMPtr presContext; - rv = frameImageLoader->GetPresContext(getter_AddRefs(presContext)); - if (presContext) { - rv = presContext->GetImageAnimationMode(&req_animate); - } - } - - return req_animate; -} - - -IL_IMPLEMENT(IL_ImageReq *) -IL_GetImage(const char* image_url, - IL_GroupContext *img_cx, - XP_ObserverList obs_list, - NI_IRGB *background_color, - PRUint32 req_width, PRUint32 req_height, - PRUint32 flags, - void *opaque_cx, - nsIImageRequestObserver * aObserver) -{ - /* block certain hosts from loading images */ - if (!il_PermitLoad(image_url, aObserver)) { - return NULL; - } - - ilINetContext *net_cx = (ilINetContext *)opaque_cx; - ImgCachePolicy cache_reload_policy = net_cx->GetReloadPolicy(); - - - ilIURL *url = NULL; - - IL_ImageReq *image_req; - ilINetReader *reader; - il_container *ic = NULL; - int req_depth = img_cx->color_space->pixmap_depth; - int err; - int is_view_image = PR_FALSE; - - if(flags == IL_STICKY) - is_view_image = PR_TRUE; - - /* Create a new instance for this image request. */ - image_req = PR_NEWZAP(IL_ImageReq); - if (!image_req) - return NULL; - image_req->img_cx = img_cx; - /* - * Remember the net context for this image request, It is possible that - * the lifetime of the image container's net context will not be as - * long as that of the image request itself (for example if the image - * request for which the container was originally created happens to - * be destroyed,) in which case we may need to give the container a - * handle on this backup net context. - */ - image_req->net_cx = net_cx->Clone(); - if (!image_req->net_cx) { - PR_FREEIF(image_req); - return NULL; - } - - image_req->obs_list = obs_list; - XP_SetObserverListObservable(obs_list, (void *)image_req); - - ILTRACE(1, ("il: IL_GetImage, url=%s\n", image_url)); - - if (!image_url) - { - ILTRACE(0,("il: no url, sending delayed icon")); - il_icon_notify(image_req, IL_IMAGE_DELAYED, IL_ERROR_NO_DATA); - return image_req; - } - - - if(is_view_image) - cache_reload_policy = SYNTH_IMGDOC_NEEDS_IMG_CACHE; - - ic = il_get_container(img_cx, cache_reload_policy, image_url, - background_color, img_cx->dither_mode, req_depth, - req_width, req_height); - if (!ic) - { - ILTRACE(0,("il: MEM il_container")); - il_icon_notify(image_req, IL_IMAGE_DELAYED, IL_ERROR_INTERNAL); - return image_req; - } - - - ic->animate_request = il_check_requested_animation(aObserver); - - /* Give the client a handle into the imagelib world. */ - image_req->ic = ic; - - - - - if (!il_add_client(img_cx, ic, image_req, is_view_image)) - { - il_icon_notify(image_req, IL_IMAGE_DELAYED, IL_ERROR_INTERNAL); - return image_req; - } - - /* If the image is already in memory ... */ - if (ic->state != IC_VIRGIN) { - switch (ic->state) { - case IC_BAD: - il_icon_notify(image_req, IL_IMAGE_BAD_DATA, - IL_ERROR_IMAGE_DATA_ILLEGAL); - break; - - case IC_MISSING: - il_icon_notify(image_req, IL_IMAGE_NOT_FOUND, IL_ERROR_NO_DATA); - break; - - case IC_INCOMPLETE: - il_icon_notify(image_req, IL_IMAGE_DELAYED, - IL_ERROR_IMAGE_DATA_TRUNCATED); - break; - - case IC_SIZED: - case IC_MULTI: - /* This is a cached image that hasn't completed decoding. */ - il_cache_return_notify(image_req); - break; - - case IC_COMPLETE: -#ifndef M12N - /* M12N Fix custom colormaps. */ - il_set_color_palette(cx, ic); -#else -#endif /* M12N */ - /* This is a cached image that has already completed decoding. */ - il_cache_return_notify(image_req); - - break; - - case IC_START: - case IC_STREAM: - case IC_ABORT_PENDING: - case IC_NOCACHE: - break; - - default: - PR_ASSERT(0); - //NS_RELEASE(image_req->net_cx); - //PR_FREEIF(image_req); - /* This takes the image_req out of the ic client list, - frees image_req->new_cx, frees image_req.*/ - il_delete_client(ic, image_req); - return NULL; - } - - /* NOCACHE falls through to be tried again */ - if (ic->state != IC_NOCACHE) - return image_req; - } - - /* This is a virgin (never-used) image container. */ - else - { - ic->forced = FORCE_RELOAD(cache_reload_policy); - } - - ic->state = IC_START; - -#ifdef DEBUG - ic->start_time = PR_Now(); -#endif - - /* Record the context that actually initiates and controls the transfer. */ - ic->net_cx = net_cx->Clone(); - - /* need to make a net request */ - ILTRACE(1,("il: net request for %s, %s", image_url, - ic->forced ? "force" : "")); - - url = ic->net_cx->CreateURL(image_url, cache_reload_policy); - - if (!url) - { - // NS_IF_RELEASE(image_req->net_cx); - // PR_FREEIF(image_req); - /* This takes the image_req out of the ic client list, - frees image_req->new_cx, frees image_req. - */ - il_delete_client(ic, image_req); - - return NULL; - } - -#if 0 - /* Add the referer to the URL. */ - ic->net_cx->AddReferer(url); -#endif - - ic->is_looping = PR_FALSE; - ic->url = url; - /* Record the fact that we are calling NetLib to load a URL. */ - ic->is_url_loading = PR_TRUE; - - /* save away the container */ - reader = IL_NewNetReader(ic); - if (!reader) { - //NS_RELEASE(image_req->net_cx); - //PR_FREEIF(image_req); - /* This takes the image_req out of the ic client list, - frees image_req->new_cx, frees image_req. - */ - il_delete_client(ic, image_req); - return NULL; - } - err = ic->net_cx->GetURL(url, cache_reload_policy, reader, PR_FALSE); - - /* Release reader, GetURL will keep a ref to it. */ - NS_RELEASE(reader); - return image_req; -} - - -IL_IMPLEMENT(void) -IL_ReloadImages(IL_GroupContext *img_cx, void *net_cx) -{ - /* XXXM12N - Implement me. */ - -} - - -IL_IMPLEMENT(void) -IL_SetDisplayMode(IL_GroupContext *img_cx, PRUint32 display_flags, - IL_DisplayData *display_data) -{ - if (display_flags & IL_DISPLAY_CONTEXT) - img_cx->dpy_cx = display_data->display_context; - - if (display_flags & IL_DISPLAY_TYPE) - img_cx->display_type = display_data->display_type; - - if (display_flags & IL_COLOR_SPACE) { - if (img_cx->color_space) - IL_ReleaseColorSpace(img_cx->color_space); - img_cx->color_space = display_data->color_space; - IL_AddRefToColorSpace(img_cx->color_space); - } - - if (display_flags & IL_PROGRESSIVE_DISPLAY) - img_cx->progressive_display = display_data->progressive_display; - - if (display_flags & IL_DITHER_MODE) - if (img_cx->color_space && img_cx->color_space->pixmap_depth == 1) { - /* Dithering always on in monochrome mode. */ - img_cx->dither_mode = IL_Dither; - } - else { - img_cx->dither_mode = display_data->dither_mode; - } -} - - - -/* Interrupts all images loading in a context. Specifically, stops all - looping image animations. */ -IL_IMPLEMENT(void) -IL_InterruptContext(IL_GroupContext *img_cx) -{ - il_container *ic; - IL_ImageReq *image_req; - il_container_list *ic_list; - - if (!img_cx) - return; - - /* Mark all clients in this context as interrupted. */ - for (ic_list = img_cx->container_list; ic_list; ic_list = ic_list->next) { - ic = ic_list->ic; - for (image_req = ic->clients; image_req; image_req = image_req->next) { - if (image_req->img_cx == img_cx) { - image_req->stopped = PR_TRUE; - } - } - } -} - -/* Interrupts just a specific image request */ -IL_IMPLEMENT(void) -IL_InterruptRequest(IL_ImageReq *image_req) -{ - if (image_req != NULL) { - image_req->stopped = PR_TRUE; - } -} - -/* Has the user aborted the image load ? */ -PRBool -il_image_stopped(il_container *ic) -{ - IL_ImageReq *image_req; - for (image_req = ic->clients; image_req; image_req = image_req->next) { - if (!image_req->stopped) - return PR_FALSE; - } - - /* All clients must be stopped for image container to become dormant. */ - return PR_TRUE; -} - - -/* 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 dpy_cx argument is opaque to the image library and is passed back to - all of the callbacks in the IMGCBIF interface. */ -IL_IMPLEMENT(IL_GroupContext*) -IL_NewGroupContext(void *dpy_cx, - ilIImageRenderer *img_cb) -{ - IL_GroupContext *img_cx; - - if (!img_cb) - return NULL; - - img_cx = (IL_GroupContext*)PR_NEWZAP(IL_GroupContext); - if (!img_cx) - return NULL; - - img_cx->dpy_cx = dpy_cx; - img_cx->img_cb = img_cb; - - img_cx->progressive_display = PR_TRUE; - - /* Create an observer list for the image context. */ - if (XP_NewObserverList((void *)img_cx, &img_cx->obs_list) - == MK_OUT_OF_MEMORY) { - PR_FREEIF(img_cx); - return NULL; - } - - /* Add the context to the global image context list. */ - img_cx->next = il_global_img_cx_list; - il_global_img_cx_list = img_cx; - - return img_cx; -} - - -/* 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_IMPLEMENT(void) -IL_DestroyGroupContext(IL_GroupContext *img_cx) -{ - if (img_cx) { - /* Remove ourself from the global image context list. */ - if (img_cx == il_global_img_cx_list) { - il_global_img_cx_list = NULL; - } - else { - IL_GroupContext *current, *next; - - for (current = il_global_img_cx_list; current; current = next) { - next = current->next; - if (next == img_cx) { - current->next = next->next; - break; - } - } - } - - /* Destroy any images remaining in the context. */ - if (img_cx->num_containers) { - PR_ASSERT(img_cx->container_list != NULL); - IL_DestroyImageGroup(img_cx); - } - - /* Destroy the observer list. */ - XP_DisposeObserverList(img_cx->obs_list); - - /* Release the image context's reference to the colorspace. */ - if (img_cx->color_space) { - IL_ReleaseColorSpace(img_cx->color_space); - img_cx->color_space = NULL; - } - - /* Release the img context callback interface. */ - NS_RELEASE(img_cx->img_cb); - PR_FREEIF(img_cx); - } -} - - -/* Add an observer/closure pair to an image group context's observer list. - Returns PR_TRUE if the observer is successfully registered. */ -IL_IMPLEMENT(PRBool) -IL_AddGroupObserver(IL_GroupContext *img_cx, XP_ObserverProc observer, - void *closure) -{ - return (PRBool)(!XP_AddObserver(img_cx->obs_list, observer, closure)); -} - - -/* Remove an observer/closure pair from an image group context's observer - list. Returns PR_TRUE if successful. */ -IL_IMPLEMENT(PRBool) -IL_RemoveGroupObserver(IL_GroupContext *img_cx, XP_ObserverProc observer, - void *closure) -{ - return XP_RemoveObserver(img_cx->obs_list, observer, closure); -} - - -/* Return the dimensions of an icon. */ -IL_IMPLEMENT(void) -IL_GetIconDimensions(IL_GroupContext *img_cx, int icon_number, int *width, - int *height) -{ - /* Check for a NULL image context. */ - if (!img_cx) - return; - - /* Obtain the dimensions of the icon. */ - img_cx->img_cb->GetIconDimensions(img_cx->dpy_cx, width, height, - icon_number); -} - - -/* Return the image IL_Pixmap associated with an image request. */ -IL_IMPLEMENT(IL_Pixmap *) -IL_GetImagePixmap(IL_ImageReq *image_req) -{ - if ((image_req && image_req->ic)&& - (image_req->ic->state == IC_COMPLETE)||(image_req->ic->state == IC_SIZED)) - return image_req->ic->image; - else - return NULL; -} - - -/* Return the mask IL_Pixmap associated with an image request. */ -IL_IMPLEMENT(IL_Pixmap *) -IL_GetMaskPixmap(IL_ImageReq *image_req) -{ - if (image_req && image_req->ic) - return image_req->ic->mask; - else - return NULL; -} - - -/* Return the natural dimensions of the image. Returns 0,0 if the dimensions - are unknown. */ -IL_IMPLEMENT(void) -IL_GetNaturalDimensions(IL_ImageReq *image_req, int *width, int *height) -{ - NI_PixmapHeader *src_header; - - if (width) - *width = 0; - if (height) - *height = 0; - - if (!image_req || !image_req->ic) - return; - - src_header = image_req->ic->src_header; - - if (src_header) { - if (width) - *width = src_header->width; - if (height) - *height = src_header->height; - } -} - diff --git a/mozilla/modules/libimg/src/if.h b/mozilla/modules/libimg/src/if.h deleted file mode 100644 index 667779cbc10..00000000000 --- a/mozilla/modules/libimg/src/if.h +++ /dev/null @@ -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 */ - diff --git a/mozilla/modules/libimg/src/ilNetReader.cpp b/mozilla/modules/libimg/src/ilNetReader.cpp deleted file mode 100644 index c10de11786e..00000000000 --- a/mozilla/modules/libimg/src/ilNetReader.cpp +++ /dev/null @@ -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; - } -} diff --git a/mozilla/modules/libimg/src/il_util.cpp b/mozilla/modules/libimg/src/il_util.cpp deleted file mode 100644 index 13288a70d0e..00000000000 --- a/mozilla/modules/libimg/src/il_util.cpp +++ /dev/null @@ -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++; -} diff --git a/mozilla/modules/libimg/src/ilclient.cpp b/mozilla/modules/libimg/src/ilclient.cpp deleted file mode 100644 index 132c8a15898..00000000000 --- a/mozilla/modules/libimg/src/ilclient.cpp +++ /dev/null @@ -1,1222 +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 -*- - * ilclient.c --- Management of imagelib client data structures, - * including image cache. - * - */ - - -#include "if.h" -#include "nsIImgDecoder.h" -#include "nsImgDCallbk.h" -#include "ilISystemServices.h" -#include "nsIFactory.h" -#include "nsCRT.h" -#include "xpcompat.h" //temporary, for timers - -#undef PIN_CHROME -/* Note that default cache size is set in - src/gfx/nsImageManager.cpp, ~line 62. -*/ -static PRUint32 image_cache_size; -static PRUint32 max_cache_items = 192; - -ilISystemServices *il_ss = NULL; - -/* simple list, in use order */ -struct il_cache_struct { - il_container *head; - il_container *tail; - int32 bytes; - int32 max_bytes; - int items; -}; - -struct il_cache_struct il_cache; -/*---------------------------------------------*/ -/*-------------------------------*/ -NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID); -NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID); - -ImgDCallbk::~ImgDCallbk() -{ - if(ilContainer) - il_delete_container(ilContainer); -} - -NS_IMPL_ISUPPORTS1(ImgDCallbk, nsIImgDCallbk) - -NS_IMETHODIMP -ImgDCallbk::CreateInstance(const nsCID &aClass, - il_container *ic, - const nsIID &aIID, - void **ppv) -{ - ImgDCallbk *imgdcb = NULL; - *ppv = NULL; - - if (&aClass && !aIID.Equals(kISupportsIID)) - return NS_NOINTERFACE; - - imgdcb = new ImgDCallbk(ic); - /* make sure interface = nsISupports, ImgDCallbk */ - nsresult res = imgdcb->QueryInterface(aIID,(void**)ppv); - - if (NS_FAILED(res)) { - *ppv = NULL; - delete imgdcb; - ic->imgdcb = NULL; - } - return res; -} - -/*-------------------------*/ - -/* Add an image container to a context's container list. */ -static PRBool -il_add_container_to_context(IL_GroupContext *img_cx, il_container *ic) -{ - il_container_list *ic_list; - - ic_list = PR_NEWZAP(il_container_list); - if (!ic_list) - return PR_FALSE; - - ic_list->ic = ic; - ic_list->next = img_cx->container_list; - img_cx->container_list = ic_list; - return PR_TRUE; -} - -/* Remove an image container from a context's container list. */ -static PRBool -il_remove_container_from_context(IL_GroupContext *img_cx, il_container *ic) -{ - il_container_list *current, *next; - - current = img_cx->container_list; - if (!current) - return PR_FALSE; - - if (current->ic == ic) { - img_cx->container_list = current->next; - PR_FREEIF(current); - return PR_TRUE; - } - else { - for (; current; current = next) { - next = current->next; - if (next && (next->ic == ic)) { - current->next = next->next; - PR_FREEIF(next); - return PR_TRUE; - } - } - } - return PR_FALSE; -} - -/* Returns PR_TRUE if the context didn't belong to the container's client - context list, and was successfully added to that list. */ -static PRBool -il_add_client_context(IL_GroupContext *img_cx, il_container *ic) -{ - il_context_list *current = ic->img_cx_list; - - /* Check whether the context is already in the client context list. */ - if (current) - for (; current; current = current->next) { - if (current->img_cx == img_cx) - return PR_FALSE; - } - - if (il_add_container_to_context(img_cx, ic)) { - /* If the client image context doesn't already belong to the - container's client context list, then add it to the beginning - of the list. */ - current = PR_NEWZAP(il_context_list); - if (!current) - return PR_FALSE; - current->img_cx = img_cx; - current->next = ic->img_cx_list; - ic->img_cx_list = current; - - /* Increment the number of containers in this context. */ - img_cx->num_containers++; - - /* If the image is still loading, increment the number of loading - containers in the context. Observer notification takes place - if the image group previously had no actively loading images. */ - if (IMAGE_CONTAINER_ACTIVE(ic) && !ic->is_looping) { - PR_ASSERT(!ic->is_aborted); - if (!img_cx->num_loading) - il_group_notify(img_cx, IL_STARTED_LOADING); - img_cx->num_loading++; - } - - /* If the image is looping, increment the number of looping containers - in the context. Observer notification takes place if the image - group previously had no looping images. */ - if (ic->is_looping) { - if (!img_cx->num_looping) - il_group_notify(img_cx, IL_STARTED_LOOPING); - img_cx->num_looping++; - } - -#ifdef DEBUG_GROUP_OBSERVER - ILTRACE(1,("5 img_cx=%x total=%d loading=%d looping=%d aborted=%d", - img_cx, img_cx->num_containers, img_cx->num_loading, - img_cx->num_looping, img_cx->num_aborted)); -#endif /* DEBUG_GROUP_OBSERVER */ - - return PR_TRUE; - } - else { - return PR_FALSE; - } -} - -/* Returns PR_TRUE if the client context belonged to the container's client - context list, and was successfully deleted from that list. */ -static PRBool -il_remove_client_context(IL_GroupContext *img_cx, il_container *ic) -{ - PRBool deleted_element = PR_FALSE; - il_context_list *current, *next; - - current = ic->img_cx_list; - if (!current) - return PR_FALSE; - - if (current->img_cx == img_cx) { - ic->img_cx_list = current->next; - PR_FREEIF(current); - deleted_element = PR_TRUE; - } - else { - for (; current; current = next) { - next = current->next; - if (next && (next->img_cx == img_cx)) { - current->next = next->next; - PR_FREEIF(next); - deleted_element = PR_TRUE; - break; - } - } - } - - if (deleted_element && il_remove_container_from_context(img_cx, ic)) { - /* Decrement the number of containers in this context. */ - img_cx->num_containers--; - - /* If the image didn't load successfully, then decrement the number - of loading containers in the context. (If the image did load - successfully, the number of loading containers in the context was - previously decremented at the time the container loaded, so don't - do it again.) Observer notification takes place if this was - the last image loading in the group. */ - if (!(ic->state == IC_COMPLETE || ic->is_looping)) { - img_cx->num_loading--; - if (!img_cx->num_loading) - il_group_notify(img_cx, IL_FINISHED_LOADING); - - if (ic->is_aborted) - img_cx->num_aborted--; - } - - /* If the image was looping, then decrement the number of looping - containers in the context. Observer notification takes place if - this was the last looping image in the group. */ - if (ic->is_looping) { - img_cx->num_looping--; - if (!img_cx->num_looping) - il_group_notify(img_cx, IL_FINISHED_LOOPING); - } - -#ifdef DEBUG_GROUP_OBSERVER - ILTRACE(1,("6 img_cx=%x total=%d loading=%d looping=%d aborted=%d", - img_cx, img_cx->num_containers, img_cx->num_loading, - img_cx->num_looping, img_cx->num_aborted)); -#endif /* DEBUG_GROUP_OBSERVER */ - - return PR_TRUE; - } - else { - return PR_FALSE; - } -} - -/* Returns TRUE if image container appears to match search parameters */ -static int -il_image_match(il_container *ic, /* Candidate for match. */ - IL_DisplayType display_type, - const char *image_url, - IL_IRGB *background_color, - int req_depth, /* Colorspace depth. */ - int req_width, /* Target image width. */ - int req_height) /* Target image height. */ -{ - PRBool ic_sized = (PRBool)(ic->state >= IC_SIZED); - NI_PixmapHeader *img_header = &ic->image->header; - IL_IRGB *img_trans_pixel = img_header->transparent_pixel; - - /* Allowable conditions for there to be a size match. req_width and - req_height both zero indicate usage of the image's natural size. - If only one is zero, it indicates scaling maintaining the image's - aspect ratio. If ic_size has been called for the image cache entry, - then ic->dest_width and ic->dest_height represent the size of the - image as it will be displayed. If ic_size has not been called for - the cache entry, then ic->dest_width and ic->dest_height represent the - requested size. */ - if (!( - /* Both dimensions match (either zero is a match.) */ - (((PRUint32)req_width == ic->dest_width) && - ((PRUint32)req_height == ic->dest_height)) || - /* Width matches, request height zero, aspect ratio same. */ - (ic_sized && ((PRUint32)req_width == ic->dest_width) && !req_height && - !ic->aspect_distorted) || - /* Height matches, request width zero, aspect ratio same. */ - (ic_sized && ((PRUint32)req_height == ic->dest_height) && !req_width && - !ic->aspect_distorted) || - /* Request dimensions zero, cache entry has natural dimensions. */ - (!req_width && !req_height && ic->natural_size) - )) - return PR_FALSE; - - /* We allow any depth image through as the FE may have asked us to - decode to a colorspace other than the display colorspace. */ - - /* Now check the background color. This only applies to transparent - images, so skip this test if the candidate for the match is known - to be opaque. */ - if (!ic_sized || img_trans_pixel) { - if (background_color) { - if (ic->background_color) { - /* Both request and candidate have a background color; check - whether they match. */ - if (background_color->red != ic->background_color->red) - return PR_FALSE; - if (background_color->green != ic->background_color->green) - return PR_FALSE; - if (background_color->blue != ic->background_color->blue) - return PR_FALSE; - } - else { - /* A background color was requested, but the candidate does - not have one. */ - return PR_FALSE; - } - } - else { /* No background color was requested. */ - if (ic->background_color) { - /* A background color was not requested, but the candidate - has one. This means that while the current request may - need a mask, the candidate definitely does not have one. */ - return PR_FALSE; - } - else { - /* Neither the request nor the candidate have a background - color, so don't disqualify the candidate. */ - } - } - } - - /* Check the url (we have already checked the hash value which is based - on the url.) */ - if (nsCRT::strcmp(image_url, ic->url_address)) - return PR_FALSE; - - /* Printer contexts and window contexts may have different - native image formats, so don't reuse an image cache entry - created for an onscreen context in a printer context or - vice-versa. */ - if (display_type != ic->display_type) - return PR_FALSE; - - - if((ic->display_type==IL_Printer) && - (ic->dest_width != ic->image->header.width) && - (ic->dest_height != ic->image->header.height )) - return PR_FALSE; - - /* XXX - temporary */ - if (ic->rendered_with_custom_palette) - return PR_FALSE; - - return PR_TRUE; -} - -static int -il_images_match(il_container *ic1, il_container *ic2) -{ - return il_image_match(ic1, - ic2->display_type, - ic2->url_address, - ic2->background_color, - ic2->image->header.color_space->pixmap_depth, - ic2->dest_width, ic2->dest_height); -} - -static il_container * -il_find_in_cache(IL_DisplayType display_type, - PRUint32 hash, - const char *image_url, - IL_IRGB* background_color, - int req_depth, - int req_width, - int req_height) -{ - il_container *ic=0; - PR_ASSERT(hash); - for (ic=il_cache.head; ic; ic=ic->next) - { - if (ic->hash != hash) - continue; - if (il_image_match(ic, display_type, image_url, background_color, req_depth, - req_width, req_height)) - break; - } - if (ic) - { - ILTRACE(2,("il: found ic=0x%08x in cache\n", ic)); - return ic; - } - return NULL; -} - -static void -il_addtocache(il_container *ic); - -il_container * -il_get_container(IL_GroupContext *img_cx, - ImgCachePolicy cache_reload_policy, - const char *image_url, - IL_IRGB *background_color, - IL_DitherMode dither_mode, - int req_depth, - int req_width, /* Target width requested by client. */ - int req_height) /* Target height requested by client. */ -{ - PRUint32 urlhash, hash; - il_container *ic=NULL; - PRBool isChromeAlready = PR_FALSE; - - urlhash = hash = il_hash(image_url); - - /* - * Take into account whether color rendering preferences have - * changed since the image was cached. - */ - hash += 21117 * (int)dither_mode; - - /* Check the cache */ - ic = il_find_in_cache(img_cx->display_type, hash, image_url, - background_color, req_depth, req_width, req_height); - - if (ic) { - - ILTRACE(2,("il: il_get_container: found ic=0x%08x in cache for url %s\n", ic, image_url)); - - /* This ic is being destroyed. Need a new one */ - if ((ic->state == IC_ABORT_PENDING)) - ic = NULL; - - /* Check if we have to reload or if there's an expiration date */ - /* and we've expired or if this is a JavaScript generated image. */ - /* We don't want to cache JavaScript generated images because: */ - /* 1) The assumption is that they are generated and might change */ - /* if the page is reloaded. */ - /* 2) Their namespace crosses document boundaries, so caching */ - /* could result in incorrect behavior. */ - - // if it is chrome, record that fact, and ensure it is not purged - - if(cache_reload_policy == DONT_USE_IMG_CACHE && ic && ic->moz_type != TYPE_CHROME){ - ILTRACE(2,("il: il_get_container: DONT_USE_IMG_CACHE ic=0x%08x discarding\n", ic)); - /* Don't use old copy and purge it from cache.*/ - if (!ic->is_in_use) { - il_removefromcache(ic); - il_delete_container(ic); - } - ic = NULL; - } - } - -#ifdef PIN_CHROME - /* Reorder the cache list so it remains in LRU order*/ - if (ic && ic->moz_type != TYPE_CHROME) - il_removefromcache(ic); - else if (ic && ic->moz_type == TYPE_CHROME) - isChromeAlready = PR_TRUE; -#else - if(ic) - il_removefromcache(ic); -#endif - - /* There's no existing matching container. Make a new one. */ - if (!ic) { - ic = PR_NEWZAP(il_container); - if (!ic) - return NULL; - - /* Allocate the source image header. */ - if (!(ic->src_header = PR_NEWZAP(NI_PixmapHeader))) { - PR_FREEIF(ic); - return NULL; - } - - /* Allocate the source image's colorspace. The fields will be - filled in by the image decoder. */ - if (!(ic->src_header->color_space = PR_NEWZAP(IL_ColorSpace))) { - PR_FREEIF(ic->src_header); - PR_FREEIF(ic); - return NULL; - } - IL_AddRefToColorSpace(ic->src_header->color_space); - - /* Allocate the destination image structure. A destination mask - structure will be allocated later if the image is determined to - be transparent and no background_color has been provided. */ - if (!(ic->image = PR_NEWZAP(IL_Pixmap))) { - IL_ReleaseColorSpace(ic->src_header->color_space); - PR_FREEIF(ic->src_header); - PR_FREEIF(ic); - return NULL; - } - - /* Set the destination image colorspace to be the source image's - colorspace. The Front Ends can override this with the display - colorspace. */ - ic->image->header.color_space = ic->src_header->color_space; - IL_AddRefToColorSpace(ic->image->header.color_space); - - /* Clear the flag to indicate that this is not a mask */ - ic->image->header.is_mask = PR_FALSE; - - /* Save the requested background color in the container. */ - if (background_color) { - if (!(ic->background_color = PR_NEWZAP(IL_IRGB))) { - PR_FREEIF(ic->image); - IL_ReleaseColorSpace(ic->src_header->color_space); - IL_ReleaseColorSpace(ic->image->header.color_space); - PR_FREEIF(ic->src_header); - PR_FREEIF(ic); - return NULL; - } - nsCRT::memcpy(ic->background_color, background_color, sizeof(IL_IRGB)); - } - else { - ic->background_color = NULL; - } - - ILTRACE(2, ("il: create ic=0x%08x\n", ic)); - -#ifdef PIN_CHROME - if((nsCRT::strncmp(image_url,"chrome", 6) == 0)&& - (nsCRT::strncmp(image_url+(nsCRT::strlen(image_url) - 9), "throb", 4) != 0)&& - (nsCRT::strncmp(image_url+(nsCRT::strlen(image_url) - 9), "busy", 4) != 0)) - ic->moz_type = TYPE_CHROME; - else -#endif - ic->moz_type = TYPE_DEFAULT; - - ic->hash = hash; - ic->urlhash = urlhash; - ic->url_address = nsCRT::strdup(image_url); - ic->is_url_loading = PR_FALSE; - ic->dest_width = req_width; - ic->dest_height = req_height; - - /* The image context is saved for use during decoding only. */ - ic->img_cx = img_cx; - - /* The type of display for which this image is being decoded e.g. - screen, printer, postscript. */ - ic->display_type = img_cx->display_type; - - /* Certain callbacks, like DestroyPixmap, can be invoked after the - image context has been destroyed, so we hold on to the callback - interface and increment its reference count. The reference count - is decremented when the container is destroyed. */ - ic->img_cb = img_cx->img_cb; - NS_ADDREF(ic->img_cb); - - /* callbacks for the image decoders */ - ImgDCallbk* imgdcb = new ImgDCallbk(ic); - if (!imgdcb) { - - PR_FREEIF(ic->image); - IL_ReleaseColorSpace(ic->src_header->color_space); - IL_ReleaseColorSpace(ic->image->header.color_space); - PR_FREEIF(ic->src_header); - nsCRT::free(ic->url_address); - PR_FREEIF(ic); - return NULL; - } - nsresult res = imgdcb->QueryInterface(NS_GET_IID(nsIImgDCallbk), (void**)&imgdcb); - if (NS_FAILED(res)) { - delete imgdcb; - - PR_FREEIF(ic->image); - IL_ReleaseColorSpace(ic->src_header->color_space); - IL_ReleaseColorSpace(ic->image->header.color_space); - PR_FREEIF(ic->src_header); - nsCRT::free(ic->url_address); - PR_FREEIF(ic); - return NULL; - } - imgdcb->SetContainer(ic); - ic->imgdcb = imgdcb; - } -#ifdef PIN_CHROME - if ( isChromeAlready == PR_FALSE ) // image is new, or existing and type is - // not TYPE_CHROME -#endif - il_addtocache(ic); - - ic->is_in_use = PR_TRUE; - - return ic; -} - -void -il_scour_container(il_container *ic) -{ - /* scour quantize, ds, scalerow etc */ - if (ic->image->header.color_space->type == NI_PseudoColor) - il_free_quantize(ic); - FREE_IF_NOT_NULL(ic->scalerow); - - /* reset a bunch of stuff */ - ic->url = NULL; - if (ic->net_cx) - NS_RELEASE(ic->net_cx); - ic->net_cx = NULL; - - ic->forced = PR_FALSE; - - ic->is_alone = PR_FALSE; -} - -/* - * destroy an il_container, freeing it and the image - */ -void -il_delete_container(il_container *ic) -{ - PR_ASSERT(ic); - if (ic) { - ILTRACE(2,("il: delete ic=0x%08x", ic)); - - /* - * We can't throw away this container until the netlib - * stops sending us stuff. We defer the actual deletion - * of the container until then. - */ - if (ic->state == IC_ABORT_PENDING) return; - if (ic->is_url_loading) { -#ifdef DEBUG_kipp - printf("il_delete_container: bad: can't delete ic=%p '%s'\n", - ic, ic->url_address ? ic->url_address : "(null)"); -#endif - ic->state = IC_ABORT_PENDING; - return; - } - - PR_ASSERT(ic->clients == NULL); - il_scour_container(ic); - - - PR_FREEIF(ic->background_color); - - PR_FREEIF(ic->src_header->transparent_pixel); - IL_ReleaseColorSpace(ic->src_header->color_space); - PR_FREEIF(ic->src_header); - - /* delete the image */ - if (!(ic->image || ic->mask)) { -#ifdef DEBUG_kipp - printf("il_delete_container: bad: ic=%p '%s' image=%p mask=%p\n", - ic, ic->url_address ? ic->url_address : "(null)", - ic->image, ic->mask); -#endif - return; - } - il_destroy_pixmap(ic->img_cb, ic->image); - if (ic->mask) - il_destroy_pixmap(ic->img_cb, ic->mask); - NS_RELEASE(ic->img_cb); - if (ic->imgdcb) { - ic->imgdcb->SetContainer(nsnull); - NS_RELEASE(ic->imgdcb); - } - - if (ic->imgdec) { - ic->imgdec->SetContainer(nsnull); - NS_RELEASE(ic->imgdec); - } - - FREE_IF_NOT_NULL(ic->comment); - nsCRT::free(ic->url_address); - nsCRT::free(ic->type); - FREE_IF_NOT_NULL(ic->fetch_url); - - PR_FREEIF(ic); - } -} - - -/* Destroy an IL_Pixmap. */ -void -il_destroy_pixmap(ilIImageRenderer *img_cb, IL_Pixmap *pixmap) -{ - NI_PixmapHeader *header = &pixmap->header; - - /* Free the pixmap's bits, as well as the client_data. */ - img_cb->DestroyPixmap(NULL, pixmap); - - /* Release memory used by the header. */ - IL_ReleaseColorSpace(header->color_space); - PR_FREEIF(header->transparent_pixel); - - /* Release the IL_Pixmap. */ - PR_FREEIF(pixmap); -} - - - -il_container * -il_removefromcache(il_container *ic) -{ - int32 image_bytes; - NI_PixmapHeader *img_header = &ic->image->header; - - PR_ASSERT(ic); - if (ic) - { - - if ( ic->moz_type == TYPE_CHROME ) - ILTRACE(2,("\nRemoving a chrome image from the image cache")); - - ILTRACE(2,("il: remove ic=0x%08x from cache\n", ic)); - PR_ASSERT(ic->next || ic->prev || (il_cache.head == il_cache.tail)); - - /* Remove entry from doubly-linked list. */ - if (il_cache.head == ic) - il_cache.head = ic->next; - - if (il_cache.tail == ic) - il_cache.tail = ic->prev; - - if (ic->next) - ic->next->prev = ic->prev; - if (ic->prev) - ic->prev->next = ic->next; - - ic->next = ic->prev = NULL; - - image_bytes = ((int32) img_header->widthBytes) * img_header->height; - -/* this assert gets triggered all the time. Take it out or fix it */ -/* PR_ASSERT (il_cache.bytes >= (int32)image_bytes); */ - - if (il_cache.bytes < (int32)image_bytes) - il_cache.bytes = 0; - else - il_cache.bytes -= image_bytes; - il_cache.items--; - PR_ASSERT(il_cache.items >= 0); - } - - return ic; - -} - -void -il_adjust_cache_fullness(int32 bytes) -{ - il_cache.bytes += bytes; - PR_ASSERT(il_cache.bytes >= 0); - - /* Safety net - This should never happen. */ - if (il_cache.bytes < 0) - il_cache.bytes = 0; - - /* We get all of the memory cache. (Only images are cached in memory.) */ - il_reduce_image_cache_size_to(image_cache_size); - - /* Collect some debugging info. */ - if (il_cache.bytes > il_cache.max_bytes) - il_cache.max_bytes = il_cache.bytes; -} - -static void -il_addtocache(il_container *ic) -{ - NI_PixmapHeader *img_header = &ic->image->header; - - ILTRACE(2,("il: add ic=0x%08x to cache\n", ic)); - PR_ASSERT(!ic->prev && !ic->next); - - /* Thread onto doubly-linked list, kept in LRU order */ - ic->prev = NULL; - ic->next = il_cache.head; - if (il_cache.head) - il_cache.head->prev = ic; - else { - PR_ASSERT(il_cache.tail == NULL); - il_cache.tail = ic; - } - il_cache.head = ic; - - /* Image storage is added in when image is sized */ - if (ic->sized) - il_cache.bytes += (PRUint32)img_header->widthBytes * img_header->height; - il_cache.items++; -} - - -/* Set limit on approximate size, in bytes, of all pixmap storage used - by the imagelib. */ -IL_IMPLEMENT(void) -IL_SetCacheSize(PRUint32 new_size) -{ - image_cache_size = new_size; - il_reduce_image_cache_size_to(new_size); -} - - -void -il_reduce_image_cache_size_to(PRUint32 new_size) -{ - int32 last_size = 0; -#ifdef XP_PC -/* -We are limiting he number of items(containers) in the -imagelib cache to 192 for windows only.We need to limit -the number of containers in the image cache for win95/98, -because each container contains an nsIImage instance, and -each nsIImage instance on window (nsImageWin) holds onto -a HBITMAP which is a GDI resource. The number of GDI resources -is limited on windows. Hence by limiting the number -of items in the cache, we ensure that we do not run - out of resources. Note that even if we limit the number of -items in the cache to 192, the actual number of items may be more -than this, depending on the actual number of nsIImage instances in use. -Currently, we are making this restriction only on platforms where -there is a known problem. -*/ - int32 last_num_items = 0; - - while ((il_cache.items > (int32)max_cache_items) && (il_cache.items != last_num_items)) { - last_num_items = il_cache.items; - IL_ShrinkCache(); - } -#endif - - while ((il_cache.bytes > (int32)new_size) && (il_cache.bytes != last_size)) { - last_size = il_cache.bytes; - IL_ShrinkCache(); - } -} - -IL_IMPLEMENT(PRUint32) -IL_ShrinkCache(void) -{ - il_container *ic; - ILTRACE(3,("shrink")); - - for (ic = il_cache.tail; ic; ic = ic->prev) - { - if (ic->is_in_use || ic->moz_type == TYPE_CHROME) { - continue; - } - - il_removefromcache(ic); - il_delete_container(ic); - break; - } - - return il_cache.bytes; -} - -IL_IMPLEMENT(void) -IL_FlushCache(PRUint8 img_catagory) -{ - ILTRACE(3,("flush")); - - il_container *ic = il_cache.head; - while (ic) - { - if (ic->is_in_use ||((img_catagory == 0 )&&(ic->moz_type == TYPE_CHROME))){ -#ifdef DEBUG_kipp - printf("IL_FlushCache: il_container %p in use '%s'\n", - ic, ic->url_address ? ic->url_address : "(null)"); -#endif - ic = ic->next; - continue; - } - - il_removefromcache(ic); - il_delete_container(ic); - ic = il_cache.head; - } -} - -IL_IMPLEMENT(PRUint32) -IL_GetCacheSize() -{ - return il_cache.bytes; -} - - -/* 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_IMPLEMENT(void) -IL_UnCache(IL_Pixmap *pixmap) -{ - il_container *ic; - if (pixmap) - { - for (ic=il_cache.head; ic; ic=ic->next) - { - /* Check the pixmap argument against both the image and mask - pixmaps of the container. */ - if (((ic->image == pixmap) || (ic->mask == pixmap)) && - !ic->is_in_use || ic->moz_type != TYPE_CHROME) - { - il_removefromcache(ic); - il_delete_container(ic); - return; - } - } - } -} - - -/* Free num_bytes of memory by flushing the Least Recently Used (LRU) images - from the image cache. */ -IL_IMPLEMENT(void) -IL_FreeMemory(IL_GroupContext *image_context, PRUint32 num_bytes) -{ - /* XXXM12N Implement me. */ -} - -PRBool -il_add_client(IL_GroupContext *img_cx, il_container *ic, - IL_ImageReq* image_req, int is_view_image) -{ - PRBool added_context; - - ILTRACE(3, ("il: add_client ic=0x%08x, image_req =0x%08x\n", ic, - image_req)); - - image_req->is_view_image = is_view_image; - - /* Add the client to the end of the container's client list. */ - if (!ic->lclient) //this is the first - ic->clients = image_req; - else - ic->lclient->next = image_req; - ic->lclient = image_req; - - /* Now add the client context to the container's client context list, - (if necessary,) and also add the container to the context's list of - containers. Note: a PR_FALSE return value could mean that the context - did not need to be added. */ - added_context = il_add_client_context(img_cx, ic); - - /* Always return PR_TRUE. */ - return PR_TRUE; -} - -/* Delete an IL_ImageReq from the list of clients for an image container. - Return PR_TRUE if successful, PR_FALSE otherwise. */ -PRBool -il_delete_client(il_container *ic, IL_ImageReq *image_req) -{ - IL_GroupContext *img_cx; - ilINetContext *net_cx; - IL_ImageReq *current_req; - IL_ImageReq *prev_req = NULL; - - /* Search for the given image request in the container's client list. */ - current_req = ic->clients; - while (current_req) { - if (current_req == image_req) - break; - prev_req = current_req; - current_req = current_req->next; - } - - /* If the image request wasn't found in the client list, return PR_FALSE. */ - if (!current_req) - return PR_FALSE; - - /* Image request was found in the client list i.e. current_req is the - same as image_req. */ - if (current_req == ic->clients) - ic->clients = current_req->next; - else - prev_req->next = current_req->next; - - if (current_req == ic->lclient) - ic->lclient = prev_req; - - img_cx = current_req->img_cx; - net_cx = current_req->net_cx; /* This is destroyed below. */ - - PR_FREEIF(current_req); /* Delete the image request. */ - - /* Decrement the number of unique images for the given image request's - image context, but be careful to do this only when there are no other - clients of this image with the same context. */ - current_req = ic->clients; - while (current_req) { - if (current_req->img_cx == img_cx) - break; - current_req = current_req->next; - } - if (!current_req) { /* The given image request's context had no - other requests associated with the image. */ - PRBool removed_context; - - /* Remove the context from the container's list of client contexts. - Also remove the container from the context's list of containers. */ - removed_context = il_remove_client_context(img_cx, ic); - - if (ic->clients) { - /* If the deleted image request's image context happened to be the - image context used by the container, then we (arbitrarily) set the - container's image context to be that of the first client in the - list. We only have to do this if the client list isn't empty. */ - if (ic->img_cx == img_cx) - ic->img_cx = ic->clients->img_cx; - /* The container's net context may be about to become invalid, so - give the container a different one which is known to be valid. */ - if ((ic->net_cx )&&(ic->net_cx == net_cx)) - { - NS_RELEASE(ic->net_cx); - ic->net_cx = ic->clients->net_cx->Clone(); - } - } - } - - /* Destroy the net context for the client we just destroyed. */ - NS_IF_RELEASE(net_cx); - - ILTRACE(3, ("il: delete_client ic=0x%08x, image_req =0x%08x\n", ic, - image_req)); - - return PR_TRUE; -} - -static void -il_delete_all_clients(il_container *ic) -{ - IL_ImageReq *image_req; - IL_ImageReq *next_req = NULL; - - for (image_req = ic->clients; image_req; image_req = next_req) { - next_req = image_req->next; - il_delete_client(ic, image_req); - } -} - -#if 1 -/* One-time image library initialization. - = Initialize internal state - = Scan image plug-in directory - = Register individual image decoders with the netlib */ -IL_IMPLEMENT(int) -IL_Init(ilISystemServices *ss) -{ - if (il_log_module == NULL) { - il_log_module = PR_NewLogModule("IMGLIB"); - } - il_ss = ss; - - /* XXXM12N - finish me. */ - return PR_TRUE; -} -#endif - -/* Used when exiting the client, this code frees all imagelib data structures. - This is done for two reasons: - 1) It makes leakage analysis of the heap easier, and - 2) It causes resources to be freed on Windows that would otherwise persist - beyond the browser's lifetime. - - XXX - Actually, right now it just frees the cached images. There are still - a couple of other places that leaks need to be fixed. */ -IL_IMPLEMENT(void) -IL_Shutdown() -{ - il_container *ic, *ic_next; - for (ic = il_cache.head; ic; ic = ic_next) - { - ic_next = ic->next; - il_delete_all_clients(ic); - ic->moz_type = TYPE_DEFAULT; // avoid assert - il_removefromcache(ic); - il_delete_container(ic); - } - - PR_ASSERT(il_cache.bytes == 0); -} - -/* 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. Also, - if the last client is removed, the container can be reclaimed, - either by storing it in the cache or throwing it away. -*/ -IL_IMPLEMENT(void) -IL_DestroyImage(IL_ImageReq *image_req) -{ - IL_GroupContext *img_cx; - PRBool client_deleted; - il_container *ic, *ic2 = NULL, *ic2_next = NULL; - il_container_list *ic_list; - - /* Check for a NULL request. */ - if (!image_req) - return; - - ic = image_req->ic; - - /* Get the container and context for this image request. */ - img_cx = image_req->img_cx; - - /* Certain requests, such as requests for internal image icons, do not - have an image container. For these cases, there is nothing else to - be done, so return early. - XXXM12N This will not be necessary once icons are completely separated - from the Image Library. */ - if (!ic){ - /* editing icons don't have ic's but need to be freed */ - if( image_req->net_cx ) - NS_RELEASE( image_req->net_cx ); - PR_FREEIF( image_req ); - return; - } - - ic_list = img_cx->container_list; - ILTRACE(1, ("il: IL_DestoyImage: ic = 0x%08x\n", ic)); - PR_ASSERT(ic_list); - if (!ic_list) - return; - - /* 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. */ - il_image_destroyed_notify(image_req); - - /* Delete the image request from the container's list of clients. */ - client_deleted = il_delete_client(ic, image_req); - PR_ASSERT(client_deleted); - - /* The image container can't be deleted until all clients are done. */ - if (ic->clients) - return; - - /* Don't allow any new streams to be created in - il_image_complete() as a result of a looping animation. (It's - possible that this image is being freed before the stream - completes/aborts. This can happen in autoscroll mode and the - editor apparently allows this to occur also.) */ - ic->loop_count = 0; - - il_image_abort(ic); - - PR_ASSERT(img_cx->num_containers >= 0); - if (!img_cx->num_containers) { - PR_ASSERT(!img_cx->container_list); - img_cx->container_list = 0; - img_cx->num_loading = 0; - img_cx->num_aborted = 0; - } - - if (ic->moz_type != TYPE_CHROME && - ((ic->state != IC_COMPLETE) || ic->multi || ic->rendered_with_custom_palette)) - { - il_removefromcache(ic); - il_delete_container(ic); - return; - } - - /* Don't allow duplicate entries in cache */ - for (ic2 = il_cache.head; ic2; ic2 = ic2_next) { - ic2_next = ic2->next; - if ((!ic2->is_in_use) && il_images_match(ic, ic2)) { - il_removefromcache(ic2); - il_delete_container(ic2); - } - } - - ic->is_in_use = PR_FALSE; -} - - -/* This routine is a "safety net", in case layout didn't free up all the - * images on a page. It assumes layout made a mistake and frees them anyway. - */ -IL_IMPLEMENT(void) -IL_DestroyImageGroup(IL_GroupContext *img_cx) -{ - IL_ImageReq *image_req, *next_req; - il_container *ic; - il_container_list *ic_list, *ic_list_next; - - if (img_cx == NULL) - return; - - if (img_cx->num_containers > 0) { - PR_ASSERT(img_cx->container_list); - - for (ic_list = img_cx->container_list; ic_list; - ic_list = ic_list_next) { - ic_list_next = ic_list->next; - ic = ic_list->ic; - ic->forced = 0; - - - for (image_req = ic->clients; image_req; image_req = next_req) { - next_req = image_req->next; - if (image_req->img_cx == img_cx){ - IL_DestroyImage(image_req); - } - } - - } -#if 0 // XXX now that we don't delete chrome images, this will fire - PR_ASSERT(img_cx->num_containers == 0); - PR_ASSERT(img_cx->container_list == NULL); -#endif - } - - ILTRACE(1, ("il: IL_DestroyImageGroup\n")); -} diff --git a/mozilla/modules/libimg/src/makefile.win b/mozilla/modules/libimg/src/makefile.win deleted file mode 100644 index 422cfbed3f2..00000000000 --- a/mozilla/modules/libimg/src/makefile.win +++ /dev/null @@ -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> diff --git a/mozilla/modules/libimg/src/nsIImgDecoder.cpp b/mozilla/modules/libimg/src/nsIImgDecoder.cpp deleted file mode 100644 index 1efee70c7e0..00000000000 --- a/mozilla/modules/libimg/src/nsIImgDecoder.cpp +++ /dev/null @@ -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; -} diff --git a/mozilla/modules/libimg/src/scale.cpp b/mozilla/modules/libimg/src/scale.cpp deleted file mode 100644 index 280f9c339ef..00000000000 --- a/mozilla/modules/libimg/src/scale.cpp +++ /dev/null @@ -1,1294 +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 -*- - scale.c --- Controls rendering of scan lines to screen, including scaling - and transparency -*/ - - -#include "if.h" /* Image library internal declarations */ -#include "il.h" /* Image library external API */ - -#include "nsCRT.h" -#include "xpcompat.h" //temporary, for timers - -#include "nsVoidArray.h" -#include "nsITimer.h" -#include "nsITimerCallback.h" - - - -/* Approximate size of pixel data chunks sent to the FE for display */ -#define OUTPUT_CHUNK_SIZE 150000 - -/* Delay from decode to display of first scanline, in milliseconds. */ -#define ROW_OUTPUT_INITIAL_DELAY 32 - -/* Delays between subsequent sets of scanlines */ -#define ROW_OUTPUT_DELAY 300 - -/* for png */ -typedef struct _IL_IRGBGA { - PRUint8 index; - PRUint8 red, green, blue, gray, alpha; -} IL_IRGBGA; - -static void -il_timeout_callback(void *closure) -{ - int delay; - il_container *ic = (il_container *)closure; - NI_PixmapHeader *img_header = &ic->image->header; - - ic->row_output_timeout = NULL; - if (ic->state == IC_ABORT_PENDING) - return; - - /* - * Don't schedule any more timeouts once we start decoding the - * second image in a multipart image sequence. Instead display - * will take place when the entire image is decoded. - */ - if (ic->multi && - ((PRUint32)img_header->height * img_header->width < 100000)) { - return; - } - - il_flush_image_data(ic); - - delay = (ic->pass > 1) ? 2 * ROW_OUTPUT_DELAY : ROW_OUTPUT_DELAY; - - ic->row_output_timeout = IL_SetTimeout(il_timeout_callback, ic, delay); -} - -/*----------------------------------------------------------------------------- - * Display a specified number of rows of pixels for the purpose of - * progressive image display. The data is accumulated without forwarding - * it to the front-end for display until either the row-output timeout - * fires or the image is fully decoded. - *---------------------------------------------------------------------------*/ -void -il_partial( - il_container *ic, /* The image container */ - int row, /* Starting row; zero is top row of image */ - int row_count, /* Number of rows to output, including starting row */ - int pass) /* Zero, unless interlaced GIF, - in which case ranges 1-4, or progressive JPEG, - in which case ranges from 1-n. */ -{ - NI_PixmapHeader *img_header = &ic->image->header; - - if (!ic->new_data_for_fe) { - ic->update_start_row = row; - ic->update_end_row = row + row_count - 1; - ic->new_data_for_fe = PR_TRUE; - } else { - if (row < ic->update_start_row) - ic->update_start_row = row; - - if ((row + row_count - 1) > ic->update_end_row) - ic->update_end_row = row + row_count - 1; - } - - ic->pass = pass; - - if (ic->img_cx->progressive_display) - { -#ifdef XP_WIN - /* The last pass of an image is displayed with less delay. */ - if (!ic->multi && (pass == IL_FINAL_PASS)) -#else - /* The first and last pass of an image are displayed with less - delay. */ - if (!ic->multi && ((pass <= 1) || (pass == IL_FINAL_PASS))) -#endif - { - int num_rows = ic->update_end_row - ic->update_start_row + 1; - if (num_rows * img_header->widthBytes > OUTPUT_CHUNK_SIZE) - il_flush_image_data(ic); - } - - - /* - * Don't schedule any more timeouts once we start decoding the - * second image in a multipart image sequence. Instead display - * will take place when the entire image is decoded. - */ - if (ic->multi && - ((PRUint32)img_header->height * img_header->width < 100000)) { - return; - } - - if (!ic->row_output_timeout){ - /* Set a timer that will actually display the image data. */ - ic->row_output_timeout = IL_SetTimeout(il_timeout_callback, ic, - ROW_OUTPUT_INITIAL_DELAY); - } - } -} - - -/*----------------------------------------------------------------------------- - * Force the front-end to to display any lines in the image bitmap - * that have been decoded, but haven't yet been sent to the screen. - * (Progressively displayed images are normally displayed several - * lines at a time for efficiency. This routine flushes out the last - * few undisplayed lines in the image.) - *---------------------------------------------------------------------------*/ -void -il_flush_image_data(il_container *ic) -{ - IL_GroupContext *img_cx = ic->img_cx; - IL_Pixmap *image = ic->image; - IL_Pixmap *mask = ic->mask; - NI_PixmapHeader *img_header = &image->header; - NI_PixmapHeader *mask_header = mask ? &mask->header : NULL; - int row, start_row, end_row, row_interval; - - /* If we never called il_size(), we have no data for the FE. There - may also be no new data if a previous flush has occurred. */ - if (!image->haveBits || !ic->new_data_for_fe) - return; - - start_row = ic->update_start_row; - end_row = ic->update_end_row; - row_interval = (2 * OUTPUT_CHUNK_SIZE) / img_header->widthBytes; - row = start_row; - -#ifdef XP_UNIX - /* If the amount of image data becomes really large, break it - * up into chunks to BLT out to the screen. Otherwise, there - * can be a noticeable delay as the FE processes a large image. - * (In the case of the XFE, it can take a long time to send - * it to the server.) - */ - for (;row < (end_row - row_interval); row += row_interval) { - img_cx->img_cb->UpdatePixmap(img_cx->dpy_cx, image, 0, row, - img_header->width, row_interval); - if (mask) { - img_cx->img_cb->UpdatePixmap(img_cx->dpy_cx, mask, 0, row, - mask_header->width, row_interval); - } - } -#endif /* XP_UNIX */ - - /* Draw whatever is leftover after sending the chunks */ - img_cx->img_cb->UpdatePixmap(img_cx->dpy_cx, image, - 0, row, img_header->width, end_row - row + 1); - - if (mask) { - img_cx->img_cb->UpdatePixmap(img_cx->dpy_cx, mask, 0, row, - mask_header->width, end_row - row + 1); - } - /* Update the displayable area of the pixmap. */ - ic->displayable_rect.x_origin = 0; - ic->displayable_rect.y_origin = 0; - ic->displayable_rect.width = (PRUint16)img_header->width; - ic->displayable_rect.height = MAX(ic->displayable_rect.height, - end_row + 1); - - img_cx->img_cb->SetDecodedRect(image, 0, 0, - ic->displayable_rect.width, ic->displayable_rect.height); - - /* Notify observers that the image pixmap has been updated. */ - il_pixmap_update_notify(ic); - - /* Notify observers of image progress. */ - il_progress_notify(ic); - - ic->new_data_for_fe = PR_FALSE; - ic->update_end_row = ic->update_start_row = 0; -} - - -/* Copy a packed RGB triple */ -#define COPY_RGB(src, dest) \ - {dest[0] = src[0]; dest[1] = src[1]; dest[2] = src[2];} - -/*----------------------------------------------------------------------------- - * Scale a row of packed RGB pixels using the Bresenham algorithm. - * Output is also packed RGB pixels. - *---------------------------------------------------------------------------*/ -static void -il_scale_RGB_row( - PRUint8 XP_HUGE *src, /* Source row of packed RGB pixels */ - int src_len, /* Number of pixels in source row */ - PRUint8 *dest, /* Destination, packed RGB pixels */ - int dest_len) /* Length of target row, in pixels */ -{ - PRUint8 *dest_end = dest + (3 * dest_len); - int n = 0; - - PR_ASSERT(dest); - PR_ASSERT(src_len != dest_len); - - /* Two cases */ - - /* Scaling down ? ... */ - if (src_len > dest_len) - { - while (dest < dest_end) { - COPY_RGB(src, dest); - dest += 3; - n += src_len; - while (n >= dest_len) { - src += 3; - n -= dest_len; - } - } - } - else - /* Scaling up. */ - { - while (dest < dest_end) { - n += dest_len; - while (n >= src_len) { - COPY_RGB(src, dest); - dest += 3; - n -= src_len; - } - src += 3; - } - } -} - -#ifdef M12N -/*----------------------------------------------------------------------------- - * Scale a row of single-byte pixels using the Bresenham algorithm. - * Output is also single-byte pixels. - *---------------------------------------------------------------------------*/ -static void -il_scale_CI_row( - PRUint8 XP_HUGE *src, /* Source row of packed RGB pixels */ - int src_len, /* Number of pixels in source row */ - PRUint8 *dest, /* Destination, packed RGB pixels */ - int dest_len, /* Length of target row, in pixels */ - PRUint8* indirect_map,/* image-to-FE color mapping */ - int transparent_pixel_color) -{ - int src_pixel, mapped_src_pixel; - PRUint8 *dest_end = dest + dest_len; - int n = 0; - - PR_ASSERT(dest); - PR_ASSERT(src_len != dest_len); - - /* Two cases */ - - /* Scaling down ? ... */ - if (src_len > dest_len) - { - while (dest < dest_end) { - if (*src != transparent_pixel_color) - *dest = indirect_map[*src]; - dest ++; - n += src_len; - while (n >= dest_len) { - src ++; - n -= dest_len; - } - } - } - else - /* Scaling up. */ - { - while (dest < dest_end) { - n += dest_len; - src_pixel = *src; - mapped_src_pixel = indirect_map[src_pixel]; - while (n >= src_len) { - if (src_pixel != transparent_pixel_color) - *dest = mapped_src_pixel; - dest ++; - n -= src_len; - } - src++; - } - } -} -#endif /* M12N */ - -/* Convert row coordinate from image space to display space. */ -#define SCALE_YCOORD(ih, sh, y) \ - ((int)((PRUint32)(y) * (ih)->height / (sh)->height)) - -#define SCALE_XCOORD(ih, sh, x) \ - ((int)((PRUint32)(x) * (ih)->width / (sh)->width)) - -/* Add a bit to the row of mask bits. Flush accumulator to memory if full. */ -#define SHIFT_IMAGE_MASK(not_transparent_flag) \ - { \ - fgmask32 |= ((PRUint32)not_transparent_flag ) << M32(mask_bit); \ - bgmask32 |= ((PRUint32)not_transparent_flag ^ 1) << M32(mask_bit); \ - \ - /* Filled up 32-bit mask word. Write it to memory. */ \ - if (mask_bit-- == 0) { \ - PRUint32 mtmp = *m; \ - mtmp |= fgmask32; \ - if (draw_mode == ilErase) \ - mtmp &= ~bgmask32; \ - *m++ = mtmp; \ - mask_bit = 31; \ - bgmask32 = 0; \ - fgmask32 = 0; \ - } \ - output_bits_remaining--; \ - } - -/*----------------------------------------------------------------------------- - * - * Create a 1 bit mask bitmap from alpha channel. - * Accumulate the mask in 32-bit chunks for efficiency. - ******* - - A Special thanks to Glenn Randers-Pehrson for - contributing a nice, fast dithering function, the - "GlennRP_random_dither_alpha" function, to convert - 8 bit alpha masks to 1bit dithered masks for use where 8 bit - masks are not supported. - - 04-11-2000. pnunn. - ******** - *---------------------------------------------------------------------------*/ -static void -il_alpha_mask( - PRUint8 *src, /* RGBa, input data */ - int src_len, /* Number of pixels in source row */ - int x_offset, /* Destination offset from left edge */ - PRUint8 XP_HUGE *maskp, /* Output pointer, left-justified bitmask */ - int mask_len, /* Number of pixels in output row */ - il_draw_mode draw_mode) /* ilOverlay or ilErase */ -{ - int not_transparent,n =0; - int output_bits_remaining = mask_len; - - PRUint32 bgmask32 = 0; /* 32-bit temporary mask accumulators */ - PRUint32 fgmask32 = 0; - - int mask_bit; /* next bit to write in setmask32 */ - - PRUint32 *m = ((PRUint32*)maskp) + (x_offset >> 5); - mask_bit = ~x_offset & 0x1f; - - PR_ASSERT(mask_len); - // mask_len = (int)mask_len; - - /* Handle case in which we have a mask for a non-transparent - image. This can happen when we have a LOSRC that is a transparent - GIF and a SRC that is a JPEG. For now, we avoid crashing. Later - we should fix that case so it does the right thing and gets rid - of the mask. */ - if (!src) - return; - - /* Scaling down (or source and dest same size) ... */ - if (src_len >= mask_len) - { - while (output_bits_remaining ) { - int tmprand=0; - tmprand = 1+(int)(200.0*rand()/(RAND_MAX+1.0)); - not_transparent = (*(src+3) > tmprand); - if(!not_transparent) { *src = 0; src[1] = 0; src[2] = 0; } - - SHIFT_IMAGE_MASK(not_transparent); - n += src_len; - - while ( n >= mask_len){ - src += 4; - n -= mask_len; - } - } - } - else - /* Scaling up */ - { - while (output_bits_remaining) { - int tmprand=0; - n += mask_len; - - while (n >= src_len) { - tmprand = 1+(int)(200.0*rand()/(RAND_MAX+1.0)); - not_transparent = (*(src+3) > tmprand); - if(!not_transparent) { *src = 0; src[1] = 0; src[2] = 0; } - SHIFT_IMAGE_MASK(not_transparent); - n -= src_len; - } - src +=4; - } - } - - /* End of scan line. Write out any remaining mask bits. */ - if (mask_bit < 31) { - PRUint32 mtmp = *m; - mtmp |= fgmask32; - if (draw_mode == ilErase) - mtmp &= ~bgmask32; - *m = mtmp; - } - -} -/*----------------------------------------------------------------------------- - * Create a transparency mask bitmap. Perform horizontal scaling if - * requested using a Bresenham algorithm. Accumulate the mask in - * 32-bit chunks for efficiency. - *---------------------------------------------------------------------------*/ -static void -il_generate_scaled_transparency_mask( - IL_IRGB *transparent_pixel, /* The transparent pixel */ - PRUint8 *src, /* Row of pixels, 8-bit pseudocolor data */ - int src_len, /* Number of pixels in source row */ - int x_offset, /* Destination offset from left edge */ - PRUint8 XP_HUGE *maskp, /* Output pointer, left-justified bitmask */ - int mask_len, /* Number of pixels in output row */ - il_draw_mode draw_mode) /* ilOverlay or ilErase */ -{ - int not_transparent, n = 0; - int src_trans_pixel_index = - transparent_pixel ? transparent_pixel->index : -1; - int output_bits_remaining = mask_len; - - PRUint32 bgmask32 = 0; /* 32-bit temporary mask accumulators */ - PRUint32 fgmask32 = 0; - - int mask_bit; /* next bit to write in setmask32 */ - - PRUint32 *m = ((PRUint32*)maskp) + (x_offset >> 5); - mask_bit = ~x_offset & 0x1f; - - PR_ASSERT(maskp); - - /* Handle case in which we have a mask for a non-transparent - image. This can happen when we have a LOSRC that is a transparent - GIF and a SRC that is a JPEG. For now, we avoid crashing. Later - we should fix that case so it does the right thing and gets rid - of the mask. */ - if (!src) - return; - - /* Two cases */ - /* Scaling down ? (or source and dest same size) ... */ - if (src_len >= mask_len) - { - while (output_bits_remaining) { - not_transparent = (*src != src_trans_pixel_index); - - SHIFT_IMAGE_MASK(not_transparent); - n += src_len; - - while (n >= mask_len) { - src++; - n -= mask_len; - } - } - } - else - /* Scaling up */ - { - while (output_bits_remaining) { - n += mask_len; - not_transparent = (*src != src_trans_pixel_index); - - while (n >= src_len) { - SHIFT_IMAGE_MASK(not_transparent); - n -= src_len; - } - src++; - } - } - - /* End of scan line. Write out any remaining mask bits. */ - if (mask_bit < 31) { - PRUint32 mtmp = *m; - mtmp |= fgmask32; - if (draw_mode == ilErase) - mtmp &= ~bgmask32; - *m = mtmp; - } - - -} - - /*----------------------------------------------------------------------------- - * Scale 1-bit transparency mask: - * Perform horizontal scaling if requested using a Bresenham algorithm. - * Accumulate the mask in 32-bit chunks for efficiency. - *---------------------------------------------------------------------------*/ - static void - il_scale_mask( - PRUint8 *src, /* input mask data */ - int src_len, /* Number of pixels in source row */ - int x_offset, /* Destination offset from left edge */ - PRUint8 XP_HUGE *maskp, /* Output pointer, left-justified bitmask */ - int mask_len, /* Number of pixels in output row */ - il_draw_mode draw_mode) /* ilOverlay or ilErase */ - { - - int not_transparent,n = 0; - int output_bits_remaining = mask_len; - - PRUint32 bgmask32 = 0; /* 32-bit temporary mask accumulators */ - PRUint32 fgmask32 = 0; - - PRUint8 src_bit; /* next bit to read in setmask32 */ - int mask_bit; /* next bit to write in setmask32 */ - - PRUint32 *m = ((PRUint32*)maskp) + (x_offset >> 5); - mask_bit = ~x_offset & 0x1f; - - src_bit = 0x07; - - PR_ASSERT(mask_len); - /* Handle case in which we have a mask for a non-transparent - image. This can happen when we have a LOSRC that is a transparent - GIF and a SRC that is a JPEG. For now, we avoid crashing. Later - we should fix that case so it does the right thing and gets rid - of the mask. */ - if (!src) - return; - - - - if (src_len >= mask_len) /* Scaling down */ - { - while (output_bits_remaining ) { - not_transparent = ((*src & ((PRUint8)1 << src_bit)) != 0); - - SHIFT_IMAGE_MASK(not_transparent); - n += src_len; - - while ( n >= mask_len){ - if (src_bit-- == 0){ - src ++; - src_bit = 7; - } - n -= mask_len; - } - } - } else /* Scaling up */ - { - while (output_bits_remaining){ - n += mask_len; - not_transparent = ((*src & ((PRUint8)1 << src_bit)) != 0); - - while (n >= src_len){ - SHIFT_IMAGE_MASK(not_transparent); - n -= src_len; - } - - if (src_bit-- == 0){ - src ++; - src_bit = 7; - } - } - } - /* End of scan line. Write out any remaining mask bits. */ - if (mask_bit < 31){ - PRUint32 mtmp = *m; - mtmp |= fgmask32; - if (draw_mode == ilErase) - mtmp &= ~bgmask32; - *m = mtmp; - } -} -#undef SHIFT_IMAGE_MASK -/*----------------------------------------------------------------------------- - * When color quantization (possibly accompanied by dithering) takes - * place, the background pixels in a transparent image that overlays a - * solid-color background, e.g. , will get - * mapped to a color in the color-cube. The real background color, - * however, may not be one of these colors reserved for images. This - * routine serves to return transparent pixels to their background - * color. This routine must performing scaling because the source - * pixels are in the image space and the target pixels are in the - * display space. - *---------------------------------------------------------------------------*/ -static void -il_reset_background_pixels( - il_container *ic, /* The image container */ - PRUint8 *src, /* Row of pixels, 8-bit pseudocolor data */ - int src_len, /* Number of pixels in row */ - PRUint8 XP_HUGE *dest, /* Output pointer, 8-bit pseudocolor data */ - int dest_len) /* Width of output pixel row */ -{ - int is_transparent, n = 0; - PRUint8 XP_HUGE *dest_end = dest + dest_len; - NI_PixmapHeader *img_header = &ic->image->header; - int src_trans_pixel_index = ic->src_header->transparent_pixel->index; - int img_trans_pixel_index = img_header->transparent_pixel->index; - int dpy_trans_pixel_index = img_header->color_space->cmap.index ? - img_header->color_space->cmap.index[img_trans_pixel_index] : - il_identity_index_map[img_trans_pixel_index]; - - /* Two cases */ - - /* Scaling down ? (or not scaling ?) ... */ - if (src_len >= dest_len) { - while (dest < dest_end) { - is_transparent = (*src == src_trans_pixel_index); - if (is_transparent) - *dest = dpy_trans_pixel_index; - dest++; - n += src_len; - - while (n >= dest_len) { - src++; - n -= dest_len; - } - } - } else { - /* Scaling up */ - while (dest < dest_end) { - n += dest_len; - is_transparent = (*src++ == src_trans_pixel_index); - - if (is_transparent) - while (n >= src_len) { - *dest++ = dpy_trans_pixel_index; - n -= src_len; - } - else - while (n >= src_len) { - dest++; - n -= src_len; - } - } - } -} - - - -static void -il_generate_byte_mask( - il_container *ic, /* The image container */ - PRUint8 *src, /* Row of pixels, 8-bit pseudocolor data */ - int src_len, /* Number of pixels in row */ - PRUint8 *dest, /* Output pointer, 8-bit pseudocolor data */ - int dest_len) /* Width of output pixel row */ -{ - int is_transparent, n = 0; - PRUint8 XP_HUGE *dest_end = dest + dest_len; - int src_trans_pixel_index = ic->src_header->transparent_pixel->index; - - /* Two cases */ - - /* Scaling down ? (or not scaling ?) ... */ - if (src_len >= dest_len) { - while (dest < dest_end) { - is_transparent = (*src == src_trans_pixel_index); - *dest = is_transparent - 1; - dest++; - n += src_len; - - while (n >= dest_len) { - src++; - n -= dest_len; - } - } - } else { - /* Scaling up */ - while (dest < dest_end) { - n += dest_len; - is_transparent = (*src++ == src_trans_pixel_index); - - if (is_transparent) - while (n >= src_len) { - *dest++ = 0; - n -= src_len; - } - else - while (n >= src_len) { - *dest++ = (PRUint8)-1; - n -= src_len; - } - } - } -} - -static void -il_overlay(PRUint8 *src, PRUint8 *dest, PRUint8 *byte_mask, int num_cols, - int bytes_per_pixel) -{ - int i, col; -#if 0 - PRUint8 *s = src; - PRUint8 *s_end = src + (num_cols * bytes_per_pixel); -#endif - for (col = num_cols; col > 0; col--) { - if (*byte_mask++) { - for (i = bytes_per_pixel-1; i >= 0; i--) { - dest[i] = src[i]; - } - } - dest += bytes_per_pixel; - src += bytes_per_pixel; - } -} - -/*----------------------------------------------------------------------------- - * Scale a row of packed RGB pixels using the Bresenham algorithm. - * Output is also packed RGB pixels. - *---------------------------------------------------------------------------*/ - -static void -il_scale_alpha8( - PRUint8 XP_HUGE *src, /* Source row of packed RGB pixels */ - int src_len, /* Number of pixels in source row */ - PRUint8 *dest, /* Destination, packed RGB pixels */ - int dest_len) /* Length of target row, in pixels */ -{ - PRUint8 *dest_end = dest + dest_len; - int n = 0; - - PR_ASSERT(dest); - PR_ASSERT(src_len != dest_len); - - /* Two cases */ - - /* Scaling down ? ... */ - if (src_len > dest_len) - { - while (dest < dest_end) { - *dest= *src; - dest ++; - n += src_len; - while (n >= dest_len) { - src++; - n -= dest_len; - } - } - } - else - /* Scaling up. */ - { - while (dest < dest_end) { - n += dest_len; - while (n >= src_len) { - *dest = *src; - dest ++; - n -= src_len; - } - src ++; - } - } -} - -static PRUint8 il_tmpbuf[MAX_IMAGE_WIDTH]; - -/*----------------------------------------------------------------------------- - * Emit a complete row of pixel data into the image. This routine - * provides any necessary conversion to the display depth, optional dithering - * for pseudocolor displays, scaling and transparency, including mask - * generation, if necessary. If sufficient data is accumulated, the screen - * image is updated, as well. - * - * PN note: Function too long. Needs to be split. Return true on success. - *---------------------------------------------------------------------------*/ -PRBool -il_emit_row( - il_container *ic, /* The image container */ - PRUint8 *cbuf, /* Color index data source, or NULL if source - is RGB data */ - PRUint8 *rgbbuf, /* Packed RGBa data or RGBa workspace if != NULL */ - int x_offset, /* First column to write data into */ - int len, /* Width of source image, in pixels */ - int row, /* Starting row of image */ - int dup_row_count, /* Number of times to duplicate row */ - il_draw_mode draw_mode, /* ilOverlay or ilErase */ - int pass) /* Zero, unless interlaced GIF, - in which case ranges 1-4, or progressive JPEG, - in which case ranges from 1-n. */ -{ - IL_GroupContext *img_cx = ic->img_cx; - IL_Pixmap *image = ic->image; - IL_Pixmap *mask = ic->mask; - NI_PixmapHeader *src_header = ic->src_header; - NI_PixmapHeader *img_header = &image->header; - NI_PixmapHeader *mask_header = NULL; - NI_ColorSpace *src_color_space = src_header->color_space; - NI_ColorSpace *img_color_space = img_header->color_space; - PRUint8 XP_HUGE *out; - PRUint8 XP_HUGE *dp; - PRUint8 XP_HUGE *mp; - PRUint8 XP_HUGE *maskp = NULL; - PRUint8 XP_HUGE *alphabitstart = NULL; - PRUint8 *byte_mask = NULL; - PRUint8 XP_HUGE *srcbuf = rgbbuf; - PRUint8 *p = cbuf; - PRUint8 *pl = cbuf+len; - int drow_start, drow_end, row_count, color_index, dup, do_dither; - int dcolumn_start, dcolumn_end, column_count, offset, src_len, dest_len; - - PR_ASSERT(row >= 0); - PR_ASSERT(image->haveBits); /* we'd better have some bits... */ - - if(row >= (int) src_header->height) { - ILTRACE(2,("il: ignoring extra row (%d)", row)); - return PR_TRUE; - } - - /* Set first and last destination row in the image. Assume no scaling. */ - drow_start = row; - drow_end = row + dup_row_count - 1; - dcolumn_start = x_offset; - dcolumn_end = x_offset + len - 1; - - /* If scaling, convert vertical image coordinates to display space. */ - if (img_header->height != src_header->height) { - int d = drow_start; - int next_drow_start = SCALE_YCOORD(img_header, src_header, drow_end+1); - drow_start = SCALE_YCOORD(img_header, src_header, drow_start); - - /* - * Don't emit a row of pixels that will be overwritten later. - * (as may happen during when images are being reduced vertically). - */ - if (drow_start == next_drow_start) { - /* - * Except that the bottom line of pixels can never be - * overwritten by a subsequent line. - */ - if (d != (int) (src_header->height - 1)) - return PR_TRUE; - else - drow_end = drow_start; - } else { - drow_end = next_drow_start - 1; - if (drow_end >= (int)img_header->height) - drow_end = img_header->height - 1; - } - } - - /* If scaling, convert horizontal image coordinates to display space. */ - if (img_header->width != src_header->width) { - int d = dcolumn_start; - int next_dcolumn_start = SCALE_XCOORD(img_header, src_header, - dcolumn_end+1); - dcolumn_start = SCALE_XCOORD(img_header, src_header, dcolumn_start); - - /* - * Don't emit a column of pixels that will be overwritten later. - * (as may happen during when images are being reduced vertically). - */ - if (dcolumn_start == next_dcolumn_start) { - /* - * Except that the right column of pixels can never be - * overwritten by a subsequent column. - */ - if (d != (int)(src_header->width - 1)) - return PR_TRUE; - else - dcolumn_end = dcolumn_start; - } else { - dcolumn_end = next_dcolumn_start - 1; - if (dcolumn_end >= (int)img_header->width) - dcolumn_end = img_header->width - 1; - } - } - /* Before we do anything else, lock down the pixels of the image, and - mask (if we have one). We need to be carefull not to return - between here and the end - */ - nsresult rv; - rv = img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, image, IL_LOCK_BITS); - if (NS_FAILED(rv)) return PR_FALSE; - - if (mask) - { - rv = img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, mask, IL_LOCK_BITS); - if (NS_FAILED(rv)) return PR_FALSE; - } - - /* Number of pixel rows and columns to emit into framebuffer */ - row_count = drow_end - drow_start + 1; - column_count = dcolumn_end - dcolumn_start + 1; - - /* If an alphamask (8 or 1 bit) exists......*/ - if(img_header->alpha_bits) { - mask_header = &mask->header; - // img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, mask, - // IL_LOCK_BITS); - -#ifdef _USD - alphabitstart = maskp = (PRUint8 XP_HUGE *)mask->bits + - (mask_header->height - drow_start - 1) * mask_header->widthBytes; -#else - alphabitstart = maskp = (PRUint8 XP_HUGE *)mask->bits + - drow_start * mask_header->widthBytes; -#endif - if(img_header->alpha_bits == 1) - { - // picks off alphachannel, packs it for 1bit mask and scales if necessary - il_alpha_mask(rgbbuf, (int)len, dcolumn_start, - alphabitstart, column_count, draw_mode); - - PRUint8 *tmpbuf, *rgbbuf_p; - int i; - - rgbbuf_p = tmpbuf = rgbbuf; - for(i=0; i < len; i++){ - *rgbbuf_p++ = *tmpbuf++; - *rgbbuf_p++ = *tmpbuf++; - *rgbbuf_p++ = *tmpbuf++; - tmpbuf++; /* strip off alpha channel */ - } - } - else{ /* alpha_bits=8*/ - - PRUint8 *tmpbuf, *rgbbuf_p; - int i; - unsigned char *scalemask; - - - unsigned char *alphabits_1= (unsigned char *)PR_MALLOC(len); - unsigned char *alphabits; - alphabits = alphabits_1; - - rgbbuf_p = tmpbuf = rgbbuf; - - for(i=0; i < len; i++){ - *rgbbuf_p++ = *tmpbuf++; - *rgbbuf_p++ = *tmpbuf++; - *rgbbuf_p++ = *tmpbuf++; - *alphabits++ = *tmpbuf++; /* put alpha channel in separate buffer */ - } - - alphabits = alphabits_1; - - if(len != column_count ){ - if ((scalemask= (unsigned char *)PR_MALLOC(mask_header->widthBytes)) != NULL) - { - il_scale_alpha8( alphabits, len, scalemask, mask_header->widthBytes); - nsCRT::memcpy(alphabitstart, scalemask, mask_header->widthBytes); - PR_DELETE(scalemask); - } - } - else - nsCRT::memcpy(alphabitstart, alphabits_1, mask_header->widthBytes); - - PR_DELETE(alphabits_1); - - } /* else */ - // img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, mask, - // IL_UNLOCK_BITS); - } else if(mask){/* If a mask not attributed to an alpha channel exists..ie: - a transparent image appears over a background image ... */ - - PR_ASSERT(mask->haveBits); /* we'd better have some bits... */ - mask_header = &mask->header; - - /* Bug, we retain the mask from a transparent - LOSRC GIF when the SRC is a JPEG. */ - /* PR_ASSERT(cbuf); */ - - // img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, mask, - // IL_LOCK_BITS); -#ifdef _USD - maskp = (PRUint8 XP_HUGE *)mask->bits + - (mask_header->height - drow_start - 1) * mask_header->widthBytes; -#else - maskp = (PRUint8 XP_HUGE *)mask->bits + - drow_start * mask_header->widthBytes; -#endif - - PR_ASSERT(maskp); - /* We know this mask is prescaled: */ - if (nsCRT::strncasecmp(ic->type, "image/x-jg", 9)==0){ - /* No scaling needed*/ - if (len == column_count) - nsCRT::memcpy(maskp, cbuf, mask_header->widthBytes); - else /* Scale */ - il_scale_mask(cbuf, (int)len, - dcolumn_start, - maskp, column_count, - draw_mode); - - /* Set to NULL, don't let anyone use it by mistake. */ - cbuf = NULL; - - }else{ - - il_generate_scaled_transparency_mask(src_header->transparent_pixel, - cbuf, (int)len, - dcolumn_start, - maskp, column_count, - draw_mode); - - } - // img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, mask, - // IL_UNLOCK_BITS); - } - - if (!ic->converter) { - -#ifdef M12N - int i; - int src_trans_pixel_index; - PRUint8 XP_HUGE * dest; - PRUint8 *indirect_map = src_color_space->cmap.index; - - PR_ASSERT(image->haveBits); - - if (indirect_map == NULL) { - indirect_map = il_identity_index_map; - } - - if ((draw_mode == ilErase) || !src_header->transparent_pixel) - src_trans_pixel_index = -1; /* no transparency */ - else - src_trans_pixel_index = src_header->transparent_pixel->index; - - // img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, image, - // IL_LOCK_BITS); - - /* No converter, image is already rendered in pseudocolor. */ -#ifdef _USD - out = (PRUint8 XP_HUGE *)image->bits + - (img_header->height - drow_start - 1) * img_header->widthBytes; -#else - out = (PRUint8 XP_HUGE *)image->bits + - drow_start * img_header->widthBytes; -#endif - - dest = out + dcolumn_start; - - /* If horizontal scaling ... */ - if (len != column_count) { - il_scale_CI_row(cbuf, len, dest, column_count, - indirect_map, src_trans_pixel_index); - } else { - - /* Convert to FE's palette indices */ - for (i = 0; i < len; i++) - if (cbuf[i] != src_trans_pixel_index) - dest[i] = indirect_map[cbuf[i]]; - } - // img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, image, - // IL_UNLOCK_BITS); -#endif /* M12N */ - - } else { - - /* Generate the output row in RGB space, regardless of screen depth. */ - if (cbuf) { - PRUint8 *r = rgbbuf; - IL_RGB *map = src_color_space->cmap.map, *entry; - - if (!src_header->transparent_pixel) { - /* Simple case: no transparency */ - while (p < pl) { - color_index = *p++; - entry = map + color_index; - r[0] = entry->red; - r[1] = entry->green; - r[2] = entry->blue; - r += 3 ; - } - } else { - /* - * There are two kinds of transparency, depending on whether - * the image is overlaying: - * 1. a solid color background, or - * 2. another image - * - * The first case is easy. We just substitute the background - * color for all the transparent pixels in the image. No mask - * is necessary. The second case requires that we generate a - * bit mask (see the code above). It also seems to require that - * all the transparent pixels in the image be set to black. - * XXX - Why ? Is this some platform-specific thing ? - fur - */ - int background_r, background_g, background_b; - IL_IRGB *src_trans_pixel = src_header->transparent_pixel; - int src_trans_pixel_index = src_trans_pixel->index; - - background_r = background_g = background_b = 0; - if (!ic->mask) { - /* Solid background color */ - background_r = src_trans_pixel->red; - background_g = src_trans_pixel->green; - background_b = src_trans_pixel->blue; - } - - /* Remap transparent pixels */ - while (p < pl) { - color_index = *p++; - if (color_index == src_trans_pixel_index) { - r[0] = background_r; - r[1] = background_g; - r[2] = background_b; - r += 3; - } else { - entry = map + color_index; - r[0] = entry->red; - r[1] = entry->green; - r[2] = entry->blue; - r += 3; - } - } - } - } - - - /* Now we are in RGB space. */ - - /* Simple anamorphic scaling (in RGB space for now) */ - src_len = len; - dest_len = column_count; - if (src_len != dest_len) { - PRUint8 XP_HUGE *src = rgbbuf; - PRUint8 *dest = ic->scalerow; - srcbuf = dest; - - /* Scale the pixel data (mask data already scaled) */ - il_scale_RGB_row(src, src_len, dest, dest_len); - - } - - img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, image, - IL_LOCK_BITS); - -#ifdef _USD - out = (PRUint8 XP_HUGE *)image->bits + - (img_header->height-drow_start-1) * (PRUint32)img_header->widthBytes; -#else - out = (PRUint8 XP_HUGE *)image->bits + - drow_start * img_header->widthBytes; -#endif - - if (src_header->transparent_pixel && (draw_mode == ilOverlay)) - { - if( cbuf ){ - il_generate_byte_mask(ic, cbuf, len, il_tmpbuf, column_count); - byte_mask = il_tmpbuf; - } - } - - - - /* - * Convert RGB to display depth. If display is pseudocolor, this may - * also color-quantize and dither. - */ - (*ic->converter)(ic, byte_mask, srcbuf, dcolumn_start, - column_count, out); - - // img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, image, - // IL_UNLOCK_BITS); - - /* - * Have to reset transparent pixels to background color - * because color quantization may have mutated them. - */ - if (src_header->transparent_pixel && - (img_color_space->type == NI_PseudoColor) && - !mask && (draw_mode == ilErase)) - il_reset_background_pixels(ic, cbuf, len, - out + dcolumn_start, column_count); - } - - /* - * We now have one row of pixels and, if required for transparency, a row - * of mask data. If the pixels in this row of the image cover span more - * than one pixel vertically when displayed, the row needs to be - * replicated in the framebuffer. (This replication is necessary when - * displaying interlaced GIFs and/or vertical scaling of any image type.) - * Actually, pixel rows are not simply copied: Dithering may need to be - * applied on a line-by-line basis. - */ - dp = out; - mp = maskp; - dup = row_count - 1; - offset = dcolumn_start * (img_color_space->pixmap_depth / 8); - - -#ifndef M12N /* Clean this up */ - if (ic->image->pixmap_depth == 1) - do_dither = PR_TRUE; - else - do_dither = ic->converter && (row_count <= 4) && - ((ic->dither_mode == IL_Dither) || - (nsCRT::strncasecmp(ic->type, "image/jpeg",10)==0); -#else - do_dither = (ic->dither_mode == IL_Dither); - if ((nsCRT::strncasecmp(ic->type, "image/gif",9)==0)|| - (nsCRT::strncasecmp(ic->type, "image/png",9)==0) && - (!ic->converter || (row_count > 4))) - do_dither = PR_FALSE; - -#endif /* M12N */ - - while (dup--) { -#ifdef _USD - dp -= img_header->widthBytes; - if (mask) - mp -= mask_header->widthBytes; -#else - dp += img_header->widthBytes; - if (mask) - mp += mask_header->widthBytes; -#endif - /* Is dithering being done (either mono or pseudocolor) ... ? */ - if (do_dither) { - - /* Dither / color-quantize */ - (*ic->converter)(ic, byte_mask, srcbuf, dcolumn_start, - column_count, dp); - - /* - * Have to reset transparent pixels to background color - * because color quantization may have mutated them. - */ - if (img_header->transparent_pixel && - (img_color_space->type == NI_PseudoColor) && - !mask && (draw_mode == ilErase)) - il_reset_background_pixels(ic, cbuf, len, dp + dcolumn_start, - column_count); - } else { - /* If no dithering, each row of pixels is exactly the same. */ - if (byte_mask) - il_overlay(out + offset, dp + offset, byte_mask, column_count, - (img_color_space->pixmap_depth/8)); - else - nsCRT::memcpy(dp + offset, out + offset, - (img_color_space->pixmap_depth/8) * column_count); - } - - /* Duplicate the mask also. */ - if (maskp) { - nsCRT::memcpy(mp, maskp, mask_header->widthBytes); - } - } - /* Now we can unlock the bits */ - img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, image, IL_UNLOCK_BITS); - - if (mask) - img_cx->img_cb->ControlPixmapBits(img_cx->dpy_cx, mask, IL_UNLOCK_BITS); - - - /* If enough rows accumulated, send to the front-end for display. */ - il_partial(ic, drow_start, row_count, pass); - - return PR_TRUE; -} - - diff --git a/mozilla/modules/libimg/src/win32.order b/mozilla/modules/libimg/src/win32.order deleted file mode 100644 index 2c80bee72e5..00000000000 --- a/mozilla/modules/libimg/src/win32.order +++ /dev/null @@ -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 diff --git a/mozilla/modules/libimg/src/xpcompat.cpp b/mozilla/modules/libimg/src/xpcompat.cpp deleted file mode 100644 index 07444320fc1..00000000000 --- a/mozilla/modules/libimg/src/xpcompat.cpp +++ /dev/null @@ -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 -#endif -#include -#include -#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 - -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); -} - -