Compare commits

..

69 Commits

Author SHA1 Message Date
pnunn%netscape.com
0a34e58966 removed old stuff. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@28105 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-19 22:06:26 +00:00
pnunn%netscape.com
a4cc8ac4d3 removing crud. pn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@28047 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-19 18:56:43 +00:00
pnunn%netscape.com
7bde1477d8 Basic doc for building branch. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27964 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-17 00:41:43 +00:00
pnunn%netscape.com
b612a148ba added npl. pn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27950 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-16 23:39:45 +00:00
pnunn%netscape.com
d5bfa71c4b a patch from Bruce Mitchener. pn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27949 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-16 23:30:19 +00:00
pnunn%netscape.com
e71cf2a529 added. Need to add NPL header. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27759 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-16 00:08:23 +00:00
pnunn%netscape.com
4f5fd16734 moved from libimg/src to decoder directory. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27756 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-16 00:07:12 +00:00
pnunn%netscape.com
a5176702e2 created.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27755 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-16 00:05:54 +00:00
pnunn%netscape.com
8979a3fad0 make xbm decoder later and put into extensions.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27754 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-16 00:01:39 +00:00
pnunn%netscape.com
c49a9b4709 not needed. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27753 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-16 00:00:30 +00:00
pnunn%netscape.com
13d03e28ac removed java include exports.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27751 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 23:58:13 +00:00
pnunn%netscape.com
c866554da3 moved from libimg/src to public_com for decoders. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27750 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 23:56:49 +00:00
pnunn%netscape.com
642da9707b fixed exports line.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27748 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 23:55:30 +00:00
pnunn%netscape.com
0acfa61263 not needed. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27742 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:57:09 +00:00
pnunn%netscape.com
89c0781d24 not needed
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27740 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:55:40 +00:00
pnunn%netscape.com
780260e884 Remove java references. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27738 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:54:58 +00:00
pnunn%netscape.com
70dd4159e6 created. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27737 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:52:32 +00:00
pnunn%netscape.com
5058e2b221 Removed java export references. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27736 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:51:46 +00:00
pnunn%netscape.com
127e421780 removed java include references. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27733 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:49:33 +00:00
pnunn%netscape.com
ca1405a4cc created.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27732 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:48:09 +00:00
pnunn%netscape.com
95468f0d5e removed references to old java dirs. pnunn
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27723 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:44:20 +00:00
pnunn%netscape.com
37ab104512 not needed. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27721 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:23:58 +00:00
pnunn%netscape.com
d10d4ce551 not needed
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27720 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:21:31 +00:00
pnunn%netscape.com
8506d5cbe2 not needed.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27719 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:20:58 +00:00
pnunn%netscape.com
ea50ea51f6 not needed. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27717 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 22:18:06 +00:00
pnunn%netscape.com
9871d36b60 not needed. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27688 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:57:25 +00:00
pnunn%netscape.com
33d7fe9053 not needed. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27684 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:42:36 +00:00
pnunn%netscape.com
e0abf2fdfe moved to decoder directory. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27682 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:41:11 +00:00
pnunn%netscape.com
267df0934c mods for new interfaces to decoders. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27681 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:40:00 +00:00
pnunn%netscape.com
c300f85316 move to decoder directory. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27680 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:38:55 +00:00
pnunn%netscape.com
64498b66a3 now in decoder directory. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27679 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:38:16 +00:00
pnunn%netscape.com
c413a524fc took out old functions. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27678 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:37:00 +00:00
pnunn%netscape.com
5e6a26c6e0 update timer stuff. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27677 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:36:24 +00:00
pnunn%netscape.com
ca143f104f created. ImgLib interface to decoders. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27676 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:35:28 +00:00
pnunn%netscape.com
7c0ff00adc upd. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27674 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:34:08 +00:00
pnunn%netscape.com
fd11e1167c moved to decoder directory. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27673 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:33:04 +00:00
pnunn%netscape.com
7287682f57 pn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27672 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:31:46 +00:00
pnunn%netscape.com
2a7e0e803b no longer needed. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27668 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:25:05 +00:00
pnunn%netscape.com
8a8dc37cf3 now in public_com. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27666 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:22:02 +00:00
pnunn%netscape.com
9e39e494bd created. for win dll. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27663 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:20:30 +00:00
pnunn%netscape.com
3dddf4ff1e created. interface from imglib to decoder. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27661 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:19:51 +00:00
pnunn%netscape.com
0520c455ea created.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27655 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:18:50 +00:00
pnunn%netscape.com
6564d8b635 created. Callback interface to imglib. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27652 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:18:31 +00:00
pnunn%netscape.com
123f687572 moved from libimg/src to decoder directory. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27647 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:17:21 +00:00
pnunn%netscape.com
10c490edd7 moved from libimg/src to decoder directory. COM interface mods. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27644 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:16:50 +00:00
pnunn%netscape.com
8511417ea8 created. subset of xpcompat.cpp in libimg/src. needed for decoder. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27639 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:16:09 +00:00
pnunn%netscape.com
6de4f2a9a4 now in public_com.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27632 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:13:44 +00:00
pnunn%netscape.com
0da98ddc6d created. for win dll. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27626 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:12:21 +00:00
pnunn%netscape.com
64a8e25432 Moved from libimg/src to decoder directory. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27622 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:10:50 +00:00
pnunn%netscape.com
4d7b7c3901 created.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27621 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:10:16 +00:00
pnunn%netscape.com
da0ab53025 created. Imglib to decoder interface. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27618 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:09:37 +00:00
pnunn%netscape.com
3add707b7b created. Callback interface to imglib. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27616 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:08:19 +00:00
pnunn%netscape.com
172b6a088a created. for win. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27613 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:07:33 +00:00
pnunn%netscape.com
4f8b2af049 created. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27610 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:06:46 +00:00
pnunn%netscape.com
3d5b140734 moved from libimg/src to decoder directory. modified for COM interface. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27609 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:06:15 +00:00
pnunn%netscape.com
4550e62995 created. subset of xpcompat.cpp in libimg/src needed for image decoders. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27608 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:04:59 +00:00
pnunn%netscape.com
9b3493120c created. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27603 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 20:00:39 +00:00
pnunn%netscape.com
29171154ea created. Moved from libimg/src to here, since needed for image decoders. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27601 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:58:51 +00:00
pnunn%netscape.com
44ef3c4e5c created. Is subset of if.h needed for image decoders. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27600 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:58:04 +00:00
pnunn%netscape.com
edbdc50469 created. is subset of xpcompat.h needed for image decoders. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27599 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:57:18 +00:00
pnunn%netscape.com
459552dbf3 created. makefile for gif decoder dll. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27598 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:54:34 +00:00
pnunn%netscape.com
9fd339206a created. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27596 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:53:46 +00:00
pnunn%netscape.com
930534ac84 created. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27594 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:53:25 +00:00
pnunn%netscape.com
06a6974b4d created.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27593 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:52:35 +00:00
pnunn%netscape.com
30c51b12af created. callback interface for gif decoder. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27592 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:52:16 +00:00
pnunn%netscape.com
8719f156ab created. Moved from libimg/src/gif.h to gif decoder directory. pnunn
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27591 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:51:08 +00:00
pnunn%netscape.com
1f849bb18c created. Modified from libimg/src/gif.cpp for gif decoder. pnunn.
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27589 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:49:43 +00:00
pnunn%netscape.com
1fc7936585 created. subset of xpcompat needed for image decoder. pnunn
git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27588 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 19:47:31 +00:00
(no author)
3d4ab640f7 This commit was manufactured by cvs2svn to create branch
'IMGLIB_DECODERS_BRANCH'.

git-svn-id: svn://10.0.0.236/branches/IMGLIB_DECODERS_BRANCH@27531 18797224-902f-48f8-a5cc-f745e15eee43
1999-04-15 03:10:34 +00:00
369 changed files with 35709 additions and 104276 deletions

View File

@@ -0,0 +1,33 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public src
ifndef MOZ_NATIVE_PNG
DIRS += png
endif
EXTRA_LIBS = $(PNG_LIBS) $(ZLIB_LIBS)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,99 @@
Branch for imglib components:
Basic description:
I have 3 new subdirectories to make below mozilla/modules/libimg.
Some of the files in mozilla/modules/libimg/src and libimg/public
should be moved to one of the new directories or retired into the
attic, and created as new in one of the new directories.
I have new exports in libimg/public and libimg/public_com.
I have a few new files that should go into the new directories.
------------------------------
The old structure:
libimg/
/src
/public
/png
------------------------------
The new structure:
libimg/
/src
/public
/public_com
/gifcom
/jpgcom
/pngcom
------------------------------
******************************************************
mozilla/modules/libimg/doc.
-----------------------------------------------------------------
To get a buildable tree with the branch:
1> pull a fresh tree and build as usual
2> delete the mozilla/modules/libimg directory.
(Pulling the branch over the existing libimg directory
will not work.)
3> pull the branch
cvs co -r IMGLIB_DECODERS_BRANCH mozilla/modules/libimg
4> You can now build just the imglib:
cd modules/libimg
clobber the libimg build
rebuild.
You should be ready to run.
The new decoder components will be installed
in bin/components.
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
If you want to do a clean top level build, you will need to modify
the build files that specify the tree structure. The top level build
files don't know about new directories and the directories that
have been removed.
for linux: add these files to allmakefiles.sh:
modules/libimg/public_com
modules/libimg/gifcom
modules/libimg/jpgcom
modules/libimg/pngcom
remove these files from allmakefiles.sh:
modules/libimg/classes/makefile
modules/libimg/classes/netscape/Makefile
modules/libimg/classes/netscape/libimg/Makefile
--------------------------------------------------------------------------------
for mac: add to the mozilla::build::mac::BuildList.pm:
under BUILD THE DIST at #LIBIMAGE add the following exports:
InstallFromManifest(":mozilla:modules:libimg:public_com:MANIFEST", ":mozilla:dist:libimg:");
and under BUILD COMMON PROJECTS:
BuildOneProject(":mozilla:modules:libimg:macbuild:gifcom.mcp", "gifdecoder$D.shlb", "gifdecoder.toc",1,$main::ALIAS_SYM_FILES, 0);
BuildOneProject(":mozilla:modules:libimg:macbuild:pngcom.mcp", "pngdecoder$D.shlb", "pngdecoder.toc",1,$main::ALIAS_SYM_FILES, 0);
BuildOneProject(":mozilla:modules:libimg:macbuild:jpgcom.mcp", "jpgdecoder$D.shlb", "jpgdecoder.toc",1,$main::ALIAS_SYM_FILES, 0);
--------------------------------------------------------------------------------
for win/NT: mozilla/modules/libimg/makefile.win specifies the
new directories. It will be pulled when the module
is pulled with the branch tag IMGLIB_DECODERS_BRANCH.
--------------------------------------------------------------------------------

View File

@@ -0,0 +1,50 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = nsgif
IS_COMPONENT = 1
LOCAL_INCLUDES = -I$(srcdir)
EXTRA_LIBS =
CPPSRCS = \
gif.cpp \
nsGIFDecoder.cpp \
nsGIFCallback.cpp \
dllcompat.cpp \
$(NULL)
REQUIRES += util img gif xpcom img
EXTRA_LIBS += $(NSPR_LIBS)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,442 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* 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.
*/
/* This file has func's from
xpcompat that are needed by
the local dll. So far,
1> Mac stuff.
2> NET_BACat
*/
#include "prtypes.h"
#include "prlog.h"
#include "prmem.h"
#include "xp_mcom.h"
PR_BEGIN_EXTERN_C
int MK_UNABLE_TO_LOCATE_FILE = -1;
int MK_OUT_OF_MEMORY = -2;
int XP_MSG_IMAGE_PIXELS = -7;
int XP_MSG_IMAGE_NOT_FOUND = -8;
int XP_MSG_XBIT_COLOR = -9;
int XP_MSG_1BIT_MONO = -10;
int XP_MSG_XBIT_GREYSCALE = -11;
int XP_MSG_XBIT_RGB = -12;
int XP_MSG_DECODED_SIZE = -13;
int XP_MSG_WIDTH_HEIGHT = -14;
int XP_MSG_SCALED_FROM = -15;
int XP_MSG_IMAGE_DIM = -16;
int XP_MSG_COLOR = -17;
int XP_MSG_NB_COLORS = -18;
int XP_MSG_NONE = -19;
int XP_MSG_COLORMAP = -20;
int XP_MSG_BCKDRP_VISIBLE = -21;
int XP_MSG_SOLID_BKGND = -22;
int XP_MSG_JUST_NO = -23;
int XP_MSG_TRANSPARENCY = -24;
int XP_MSG_COMMENT = -25;
int XP_MSG_UNKNOWN = -26;
int XP_MSG_COMPRESS_REMOVE = -27;
PR_END_EXTERN_C
/* binary block Allocate and Concatenate
*
* destination_length is the length of the existing block
* source_length is the length of the block being added to the
* destination block
*/
char *
NET_BACat (char **destination,
size_t destination_length,
const char *source,
size_t source_length)
{
if (source)
{
if (*destination)
{
*destination = (char *) PR_REALLOC (*destination, destination_length + source_length);
if (*destination == NULL)
return(NULL);
XP_MEMMOVE (*destination + destination_length, source, source_length);
}
else
{
*destination = (char *) PR_MALLOC (source_length);
if (*destination == NULL)
return(NULL);
XP_MEMCPY(*destination, source, source_length);
}
}
return *destination;
}
#if defined(XP_MAC)
/* prototypes for local routines */
static void shortsort(char *lo, char *hi, unsigned width,
int ( *comp)(const void *, const void *));
static void swap(char *p, char *q, unsigned int width);
/* this parameter defines the cutoff between using quick sort and
insertion sort for arrays; arrays with lengths shorter or equal to the
below value use insertion sort */
#define CUTOFF 8 /* testing shows that this is good value */
/***
*XP_QSORT(base, num, wid, comp) - quicksort function for sorting arrays
*
*Purpose:
* quicksort the array of elements
* side effects: sorts in place
*
*Entry:
* char *base = pointer to base of array
* unsigned num = number of elements in the array
* unsigned width = width in bytes of each array element
* int (*comp)() = pointer to function returning analog of strcmp for
* strings, but supplied by user for comparing the array elements.
* it accepts 2 pointers to elements and returns neg if 1<2, 0 if
* 1=2, pos if 1>2.
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
/* sort the array between lo and hi (inclusive) */
void XP_QSORT (
void *base,
size_t num,
size_t width,
int ( *comp)(const void *, const void *)
)
{
char *lo, *hi; /* ends of sub-array currently sorting */
char *mid; /* points to middle of subarray */
char *loguy, *higuy; /* traveling pointers for partition step */
unsigned size; /* size of the sub-array */
char *lostk[30], *histk[30];
int stkptr; /* stack for saving sub-array to be processed */
/* Note: the number of stack entries required is no more than
1 + log2(size), so 30 is sufficient for any array */
if (num < 2 || width == 0)
return; /* nothing to do */
stkptr = 0; /* initialize stack */
lo = (char*)base;
hi = (char *)base + width * (num-1); /* initialize limits */
/* this entry point is for pseudo-recursion calling: setting
lo and hi and jumping to here is like recursion, but stkptr is
prserved, locals aren't, so we preserve stuff on the stack */
recurse:
size = (hi - lo) / width + 1; /* number of el's to sort */
/* below a certain size, it is faster to use a O(n^2) sorting method */
if (size <= CUTOFF) {
shortsort(lo, hi, width, comp);
}
else {
/* First we pick a partititioning element. The efficiency of the
algorithm demands that we find one that is approximately the
median of the values, but also that we select one fast. Using
the first one produces bad performace if the array is already
sorted, so we use the middle one, which would require a very
wierdly arranged array for worst case performance. Testing shows
that a median-of-three algorithm does not, in general, increase
performance. */
mid = lo + (size / 2) * width; /* find middle element */
swap(mid, lo, width); /* swap it to beginning of array */
/* We now wish to partition the array into three pieces, one
consisiting of elements <= partition element, one of elements
equal to the parition element, and one of element >= to it. This
is done below; comments indicate conditions established at every
step. */
loguy = lo;
higuy = hi + width;
/* Note that higuy decreases and loguy increases on every iteration,
so loop must terminate. */
for (;;) {
/* lo <= loguy < hi, lo < higuy <= hi + 1,
A[i] <= A[lo] for lo <= i <= loguy,
A[i] >= A[lo] for higuy <= i <= hi */
do {
loguy += width;
} while (loguy <= hi && comp(loguy, lo) <= 0);
/* lo < loguy <= hi+1, A[i] <= A[lo] for lo <= i < loguy,
either loguy > hi or A[loguy] > A[lo] */
do {
higuy -= width;
} while (higuy > lo && comp(higuy, lo) >= 0);
/* lo-1 <= higuy <= hi, A[i] >= A[lo] for higuy < i <= hi,
either higuy <= lo or A[higuy] < A[lo] */
if (higuy < loguy)
break;
/* if loguy > hi or higuy <= lo, then we would have exited, so
A[loguy] > A[lo], A[higuy] < A[lo],
loguy < hi, highy > lo */
swap(loguy, higuy, width);
/* A[loguy] < A[lo], A[higuy] > A[lo]; so condition at top
of loop is re-established */
}
/* A[i] >= A[lo] for higuy < i <= hi,
A[i] <= A[lo] for lo <= i < loguy,
higuy < loguy, lo <= higuy <= hi
implying:
A[i] >= A[lo] for loguy <= i <= hi,
A[i] <= A[lo] for lo <= i <= higuy,
A[i] = A[lo] for higuy < i < loguy */
swap(lo, higuy, width); /* put partition element in place */
/* OK, now we have the following:
A[i] >= A[higuy] for loguy <= i <= hi,
A[i] <= A[higuy] for lo <= i < higuy
A[i] = A[lo] for higuy <= i < loguy */
/* We've finished the partition, now we want to sort the subarrays
[lo, higuy-1] and [loguy, hi].
We do the smaller one first to minimize stack usage.
We only sort arrays of length 2 or more.*/
if ( higuy - 1 - lo >= hi - loguy ) {
if (lo + width < higuy) {
lostk[stkptr] = lo;
histk[stkptr] = higuy - width;
++stkptr;
} /* save big recursion for later */
if (loguy < hi) {
lo = loguy;
goto recurse; /* do small recursion */
}
}
else {
if (loguy < hi) {
lostk[stkptr] = loguy;
histk[stkptr] = hi;
++stkptr; /* save big recursion for later */
}
if (lo + width < higuy) {
hi = higuy - width;
goto recurse; /* do small recursion */
}
}
}
/* We have sorted the array, except for any pending sorts on the stack.
Check if there are any, and do them. */
--stkptr;
if (stkptr >= 0) {
lo = lostk[stkptr];
hi = histk[stkptr];
goto recurse; /* pop subarray from stack */
}
else
return; /* all subarrays done */
}
/***
*shortsort(hi, lo, width, comp) - insertion sort for sorting short arrays
*
*Purpose:
* sorts the sub-array of elements between lo and hi (inclusive)
* side effects: sorts in place
* assumes that lo < hi
*
*Entry:
* char *lo = pointer to low element to sort
* char *hi = pointer to high element to sort
* unsigned width = width in bytes of each array element
* int (*comp)() = pointer to function returning analog of strcmp for
* strings, but supplied by user for comparing the array elements.
* it accepts 2 pointers to elements and returns neg if 1<2, 0 if
* 1=2, pos if 1>2.
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
static void shortsort (
char *lo,
char *hi,
unsigned width,
int ( *comp)(const void *, const void *)
)
{
char *p, *max;
/* Note: in assertions below, i and j are alway inside original bound of
array to sort. */
while (hi > lo) {
/* A[i] <= A[j] for i <= j, j > hi */
max = lo;
for (p = lo+width; p <= hi; p += width) {
/* A[i] <= A[max] for lo <= i < p */
if (comp(p, max) > 0) {
max = p;
}
/* A[i] <= A[max] for lo <= i <= p */
}
/* A[i] <= A[max] for lo <= i <= hi */
swap(max, hi, width);
/* A[i] <= A[hi] for i <= hi, so A[i] <= A[j] for i <= j, j >= hi */
hi -= width;
/* A[i] <= A[j] for i <= j, j > hi, loop top condition established */
}
/* A[i] <= A[j] for i <= j, j > lo, which implies A[i] <= A[j] for i < j,
so array is sorted */
}
/***
*swap(a, b, width) - swap two elements
*
*Purpose:
* swaps the two array elements of size width
*
*Entry:
* char *a, *b = pointer to two elements to swap
* unsigned width = width in bytes of each array element
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
static void swap (
char *a,
char *b,
unsigned width
)
{
char tmp;
if ( a != b )
/* Do the swap one character at a time to avoid potential alignment
problems. */
while ( width-- ) {
tmp = *a;
*a++ = *b;
*b++ = tmp;
}
}
#endif /* XP_MAC */
#ifdef XP_MAC
#include <OSUtils.h>
static void MyReadLocation(MachineLocation * loc)
{
static MachineLocation storedLoc; // InsideMac, OSUtilities, page 4-20
static Boolean didReadLocation = FALSE;
if (!didReadLocation)
{
ReadLocation(&storedLoc);
didReadLocation = TRUE;
}
*loc = storedLoc;
}
// current local time = GMTDelta() + GMT
// GMT = local time - GMTDelta()
static long GMTDelta()
{
MachineLocation loc;
long gmtDelta;
MyReadLocation(&loc);
gmtDelta = loc.u.gmtDelta & 0x00FFFFFF;
if ((gmtDelta & 0x00800000) != 0)
gmtDelta |= 0xFF000000;
return gmtDelta;
}
// This routine simulates stdclib time(), time in seconds since 1.1.1970
// The time is in GMT
time_t GetTimeMac()
{
unsigned long maclocal;
// Get Mac local time
GetDateTime(&maclocal);
// Get Mac GMT
maclocal -= GMTDelta();
// return unix GMT
return (maclocal - UNIXMINUSMACTIME);
}
// Returns the GMT times
time_t Mactime(time_t *timer)
{
time_t t = GetTimeMac();
if (timer != NULL)
*timer = t;
return t;
}
#endif /* XP_MAC */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,28 @@
/* -*- 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.0 (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.
*/
/* gif.h */
extern int il_gif_init(il_container *ic);
extern int il_gif_write(il_container *, const uint8 *, int32);
extern void il_gif_complete(il_container *ic);
extern unsigned int il_gif_write_ready(il_container *ic);
extern void il_gif_abort(il_container *ic);
extern void gif_delay_time_callback(void *closure);

View File

@@ -0,0 +1,99 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
#
#------------------------------------------------------------------------
#
# Makefile to build the IMGLIB LIB
#
#------------------------------------------------------------------------
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
LIBRARY_NAME = nsgif
#
# 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\plc3.lib \
$(DIST)\lib\util.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
!ifdef NU_CACHE
$(DIST)\lib\cache.lib \
!endif
$(NULL)
MISCDEP=$(LLIBS)
LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
LIBRARY_SUFFIX = $(MOZ_BITS)$(VERSION_NUMBER)
MAKE_OBJ_TYPE=DLL
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
DLLNAME=nsgif$(MOZ_BITS)$(VERSION_NUMBER)
DLL1NAME=nsgif$(MOZ_BITS)$(VERSION_NUMBER)
PDBFILE=$(DLLNAME).pdb
MAPFILE=$(DLLNAME).map
DEFFILE=nsgif.def
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
DLL=.\$(OBJDIR)\$(DLLNAME).dll
MAPFILE= $(DLLNAME).map
MODULE=img
DEPTH=..\..\..
LINCS=-I$(DEPTH)/dist/public/xpcom -I. -I$(DEPTH)/dist/public/raptor
REQUIRES=nspr xpcom util raptor
CPPSRCS=nsGIFCallback.cpp nsGIFDecoder.cpp dllcompat.cpp gif.cpp
CPP_OBJS= .\$(OBJDIR)\nsGIFDecoder.obj .\$(OBJDIR)\nsGIFCallback.obj \
.\$(OBJDIR)\dllcompat.obj .\$(OBJDIR)\gif.obj
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib

View File

@@ -0,0 +1,63 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsGIFDecoder.cpp --- interface to gif decoder
*/
#include "nsGIFCallback.h"
NS_DEFINE_IID(kGIFCallbkIID, NS_GIFCALLBK_IID);
NS_DEFINE_CID(kGIFCallbkCID, NS_GIFCALLBK_CID);
/* callbks: */
/*-------------class----------*/
NS_IMETHODIMP GIFCallbk::AddRef()
{
NS_INIT_REFCNT();
return NS_OK;
}
NS_IMETHODIMP GIFCallbk::Release()
{
return NS_OK;
}
NS_IMETHODIMP GIFCallbk::QueryInterface(const nsIID& aIID, void** aResult)
{
if (NULL == aResult) {
return NS_ERROR_NULL_POINTER;
}
if ( aIID.Equals(kGIFCallbkIID) ||
aIID.Equals(kImgDCallbkIID)||
aIID.Equals(kISupportsIID)) {
*aResult = (void*) this;
NS_INIT_REFCNT();
return NS_OK;
}
return NS_NOINTERFACE;
}
/*-----------------------------*/

View File

@@ -0,0 +1,56 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsGIFDecoder.cpp --- interface to gif decoder
*/
#ifndef _nsGIFCallbk_h
#define _nsGIFCallbk_h
#include "nsIImgDecoder.h"
#include "nsGIFDecoder.h"
/* new gif call back stuff: */
/* 0b1eab40-cdc6-11d2-802c-0060088f91a3 */
#define NS_GIFCALLBK_CID \
{ 0x0b1eab40, 0xcdc6, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/* 1cab3680-cdc6-11d2-802c-0060088f91a3 */
#define NS_GIFCALLBK_IID \
{ 0x1cab3680, 0xcdc6, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
class GIFCallbk : public nsIImgDCallbk {
public:
NS_DECL_ISUPPORTS
il_container *GetContainer() {return mContainer;};
il_container *SetContainer(il_container *ic) {mContainer=ic; return ic;};
GIFCallbk(il_container *aContainer){mContainer=aContainer;};
~GIFCallbk();
private:
il_container* mContainer;
};
#endif

View File

@@ -0,0 +1,305 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsGIFDecoder.cpp --- interface to gif decoder
*/
#include "if_struct.h"
#include "prmem.h"
#include "merrors.h"
#include "dllcompat.h"
#include "gif.h"
#include "nsGIFDecoder.h"
#include "nsImgDecCID.h"
#include "nsIImgDecoder.h" /* interface class */
#include "nsImgDecoder.h" /* factory */
#include "nscore.h"
/*--- needed for autoregistry ---*/
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
PR_BEGIN_EXTERN_C
extern int MK_OUT_OF_MEMORY;
PR_END_EXTERN_C
/*-----------class----------------*/
class GIFDecoder : public nsIImgDecoder
{
public:
GIFDecoder(il_container* aContainer);
~GIFDecoder();
NS_DECL_ISUPPORTS
/* stream */
NS_IMETHOD ImgDInit();
NS_IMETHOD ImgDWriteReady();
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len);
NS_IMETHOD ImgDComplete();
NS_IMETHOD ImgDAbort();
il_container *SetContainer(il_container *ic){mContainer = ic; return ic;}
il_container *GetContainer() {return mContainer;}
private:
il_container* mContainer;
};
/*-------------------------------------------------*/
GIFDecoder::GIFDecoder(il_container* aContainer)
{
NS_INIT_REFCNT();
mContainer = aContainer;
};
GIFDecoder::~GIFDecoder(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
};
NS_IMETHODIMP
GIFDecoder::QueryInterface(const nsIID& aIID, void** aInstPtr)
{
if (NULL == aInstPtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kGIFDecoderIID) ||
aIID.Equals(kImgDecoderIID) ||
aIID.Equals(kISupportsIID)) {
*aInstPtr = (void*) this;
NS_INIT_REFCNT();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
GIFDecoder::AddRef()
{
NS_INIT_REFCNT();
return NS_OK;
}
NS_IMETHODIMP
GIFDecoder::Release()
{
return NS_OK;
}
/*-----------class----------------*/
class nsGIFDecFactory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
nsGIFDecFactory(const nsCID &aClass);
~nsGIFDecFactory();
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
private:
nsCID mClassID;
il_container *mContainer;
};
/*-----------------------------------------*/
nsGIFDecFactory* gFactory = NULL;
NS_IMPL_ISUPPORTS(nsGIFDecFactory, kIFactoryIID);
nsGIFDecFactory::nsGIFDecFactory(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
}
nsGIFDecFactory::~nsGIFDecFactory(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
/*----------------------------------for autoregistration ----*/
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
extern "C" NS_EXPORT nsresult
NSRegisterSelf(nsISupports* aServMgr, const char *path)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
if ((rv = nsRepository::RegisterComponent(kGIFDecoderCID,
"Netscape GIFDec",
"component://netscape/image/decoder&type=image/gif", path, PR_TRUE, PR_TRUE)
) != NS_OK) {
return rv;
}
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *path)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterFactory(kGIFDecoderCID, path);
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
/*--------------------*/
NS_IMETHODIMP
nsGIFDecFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **ppv)
{
GIFDecoder *gifdec = NULL;
*ppv = NULL;
il_container* ic = NULL;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE;
ic = new il_container();
gifdec = new GIFDecoder(ic);
nsresult res = gifdec->QueryInterface(aIID,(void**)ppv);
//interface is other than nsISupports and gifdecoder
if (NS_FAILED(res)) {
*ppv = NULL;
delete gifdec;
}
return res;
}
NS_METHOD
nsGIFDecFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}
extern "C" NS_EXPORT nsresult
NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if( !aClass.Equals(kGIFDecoderCID))
return NS_ERROR_FACTORY_NOT_REGISTERED;
if( gFactory == NULL){
gFactory = new nsGIFDecFactory(aClass);
if( gFactory == NULL)
return NS_ERROR_OUT_OF_MEMORY;
gFactory->AddRef(); //for global
}
gFactory->AddRef(); //for client
*aFactory = gFactory;
return NS_OK;
}
/*----------------------------------------------------*/
// api functions
/*------------------------------------------------------*/
NS_IMETHODIMP
GIFDecoder::ImgDInit()
{
if(mContainer != NULL) {
return(il_gif_init(mContainer));
}
else {
return nsnull;
}
}
NS_IMETHODIMP
GIFDecoder::ImgDWriteReady()
{
if(mContainer != NULL) {
return(il_gif_write_ready(mContainer));
}
return 0;
}
NS_IMETHODIMP
GIFDecoder::ImgDWrite(const unsigned char *buf, int32 len)
{
if( mContainer != NULL ) {
return(il_gif_write(mContainer, buf,len));
}
return 0;
}
NS_IMETHODIMP
GIFDecoder::ImgDComplete()
{
if( mContainer != NULL ) {
il_gif_complete(mContainer);
}
return 0;
}
NS_IMETHODIMP
GIFDecoder::ImgDAbort()
{
if( mContainer != NULL ) {
il_gif_abort(mContainer);
}
return 0;
}

View File

@@ -0,0 +1,40 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsGIFDecoder.cpp --- interface to gif decoder
*/
#ifndef _nsGIFDec_h
#define _nsGIFDec_h
#define NS_GIFDECODER_CID \
{ 0x0d471b70, 0xbaf5, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/* 402fb190-bbd0-11d2-802c-0060088f91a3 */
#define NS_GIFDECODER_IID \
{ 0x402b190, 0xbbd0, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
static NS_DEFINE_IID(kGIFDecoderIID, NS_GIFDECODER_IID);
static NS_DEFINE_CID(kGIFDecoderCID, NS_GIFDECODER_CID);
#endif

View File

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

View File

@@ -0,0 +1,53 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = nsjpg
IS_COMPONENT = 1
LOCAL_INCLUDES = -I$(srcdir)
EXTRA_LIBS =
CPPSRCS = \
jpeg.cpp \
nsJPGDecoder.cpp \
nsJPGCallback.cpp \
dllcompat.cpp \
$(NULL)
CPPSRCS += \
$(NULL)
REQUIRES += util jpeg xpcom img
EXTRA_LIBS += $(NSPR_LIBS)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,442 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* 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.
*/
/* This file has func's from
xpcompat that are needed by
the local dll. So far,
1> Mac stuff.
2> NET_BACat
*/
#include "prtypes.h"
#include "prlog.h"
#include "prmem.h"
#include "xp_mcom.h"
PR_BEGIN_EXTERN_C
int MK_UNABLE_TO_LOCATE_FILE = -1;
int MK_OUT_OF_MEMORY = -2;
int XP_MSG_IMAGE_PIXELS = -7;
int XP_MSG_IMAGE_NOT_FOUND = -8;
int XP_MSG_XBIT_COLOR = -9;
int XP_MSG_1BIT_MONO = -10;
int XP_MSG_XBIT_GREYSCALE = -11;
int XP_MSG_XBIT_RGB = -12;
int XP_MSG_DECODED_SIZE = -13;
int XP_MSG_WIDTH_HEIGHT = -14;
int XP_MSG_SCALED_FROM = -15;
int XP_MSG_IMAGE_DIM = -16;
int XP_MSG_COLOR = -17;
int XP_MSG_NB_COLORS = -18;
int XP_MSG_NONE = -19;
int XP_MSG_COLORMAP = -20;
int XP_MSG_BCKDRP_VISIBLE = -21;
int XP_MSG_SOLID_BKGND = -22;
int XP_MSG_JUST_NO = -23;
int XP_MSG_TRANSPARENCY = -24;
int XP_MSG_COMMENT = -25;
int XP_MSG_UNKNOWN = -26;
int XP_MSG_COMPRESS_REMOVE = -27;
PR_END_EXTERN_C
/* binary block Allocate and Concatenate
*
* destination_length is the length of the existing block
* source_length is the length of the block being added to the
* destination block
*/
char *
NET_BACat (char **destination,
size_t destination_length,
const char *source,
size_t source_length)
{
if (source)
{
if (*destination)
{
*destination = (char *) PR_REALLOC (*destination, destination_length + source_length);
if (*destination == NULL)
return(NULL);
XP_MEMMOVE (*destination + destination_length, source, source_length);
}
else
{
*destination = (char *) PR_MALLOC (source_length);
if (*destination == NULL)
return(NULL);
XP_MEMCPY(*destination, source, source_length);
}
}
return *destination;
}
#if defined(XP_MAC)
/* prototypes for local routines */
static void shortsort(char *lo, char *hi, unsigned width,
int ( *comp)(const void *, const void *));
static void swap(char *p, char *q, unsigned int width);
/* this parameter defines the cutoff between using quick sort and
insertion sort for arrays; arrays with lengths shorter or equal to the
below value use insertion sort */
#define CUTOFF 8 /* testing shows that this is good value */
/***
*XP_QSORT(base, num, wid, comp) - quicksort function for sorting arrays
*
*Purpose:
* quicksort the array of elements
* side effects: sorts in place
*
*Entry:
* char *base = pointer to base of array
* unsigned num = number of elements in the array
* unsigned width = width in bytes of each array element
* int (*comp)() = pointer to function returning analog of strcmp for
* strings, but supplied by user for comparing the array elements.
* it accepts 2 pointers to elements and returns neg if 1<2, 0 if
* 1=2, pos if 1>2.
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
/* sort the array between lo and hi (inclusive) */
void XP_QSORT (
void *base,
size_t num,
size_t width,
int ( *comp)(const void *, const void *)
)
{
char *lo, *hi; /* ends of sub-array currently sorting */
char *mid; /* points to middle of subarray */
char *loguy, *higuy; /* traveling pointers for partition step */
unsigned size; /* size of the sub-array */
char *lostk[30], *histk[30];
int stkptr; /* stack for saving sub-array to be processed */
/* Note: the number of stack entries required is no more than
1 + log2(size), so 30 is sufficient for any array */
if (num < 2 || width == 0)
return; /* nothing to do */
stkptr = 0; /* initialize stack */
lo = (char*)base;
hi = (char *)base + width * (num-1); /* initialize limits */
/* this entry point is for pseudo-recursion calling: setting
lo and hi and jumping to here is like recursion, but stkptr is
prserved, locals aren't, so we preserve stuff on the stack */
recurse:
size = (hi - lo) / width + 1; /* number of el's to sort */
/* below a certain size, it is faster to use a O(n^2) sorting method */
if (size <= CUTOFF) {
shortsort(lo, hi, width, comp);
}
else {
/* First we pick a partititioning element. The efficiency of the
algorithm demands that we find one that is approximately the
median of the values, but also that we select one fast. Using
the first one produces bad performace if the array is already
sorted, so we use the middle one, which would require a very
wierdly arranged array for worst case performance. Testing shows
that a median-of-three algorithm does not, in general, increase
performance. */
mid = lo + (size / 2) * width; /* find middle element */
swap(mid, lo, width); /* swap it to beginning of array */
/* We now wish to partition the array into three pieces, one
consisiting of elements <= partition element, one of elements
equal to the parition element, and one of element >= to it. This
is done below; comments indicate conditions established at every
step. */
loguy = lo;
higuy = hi + width;
/* Note that higuy decreases and loguy increases on every iteration,
so loop must terminate. */
for (;;) {
/* lo <= loguy < hi, lo < higuy <= hi + 1,
A[i] <= A[lo] for lo <= i <= loguy,
A[i] >= A[lo] for higuy <= i <= hi */
do {
loguy += width;
} while (loguy <= hi && comp(loguy, lo) <= 0);
/* lo < loguy <= hi+1, A[i] <= A[lo] for lo <= i < loguy,
either loguy > hi or A[loguy] > A[lo] */
do {
higuy -= width;
} while (higuy > lo && comp(higuy, lo) >= 0);
/* lo-1 <= higuy <= hi, A[i] >= A[lo] for higuy < i <= hi,
either higuy <= lo or A[higuy] < A[lo] */
if (higuy < loguy)
break;
/* if loguy > hi or higuy <= lo, then we would have exited, so
A[loguy] > A[lo], A[higuy] < A[lo],
loguy < hi, highy > lo */
swap(loguy, higuy, width);
/* A[loguy] < A[lo], A[higuy] > A[lo]; so condition at top
of loop is re-established */
}
/* A[i] >= A[lo] for higuy < i <= hi,
A[i] <= A[lo] for lo <= i < loguy,
higuy < loguy, lo <= higuy <= hi
implying:
A[i] >= A[lo] for loguy <= i <= hi,
A[i] <= A[lo] for lo <= i <= higuy,
A[i] = A[lo] for higuy < i < loguy */
swap(lo, higuy, width); /* put partition element in place */
/* OK, now we have the following:
A[i] >= A[higuy] for loguy <= i <= hi,
A[i] <= A[higuy] for lo <= i < higuy
A[i] = A[lo] for higuy <= i < loguy */
/* We've finished the partition, now we want to sort the subarrays
[lo, higuy-1] and [loguy, hi].
We do the smaller one first to minimize stack usage.
We only sort arrays of length 2 or more.*/
if ( higuy - 1 - lo >= hi - loguy ) {
if (lo + width < higuy) {
lostk[stkptr] = lo;
histk[stkptr] = higuy - width;
++stkptr;
} /* save big recursion for later */
if (loguy < hi) {
lo = loguy;
goto recurse; /* do small recursion */
}
}
else {
if (loguy < hi) {
lostk[stkptr] = loguy;
histk[stkptr] = hi;
++stkptr; /* save big recursion for later */
}
if (lo + width < higuy) {
hi = higuy - width;
goto recurse; /* do small recursion */
}
}
}
/* We have sorted the array, except for any pending sorts on the stack.
Check if there are any, and do them. */
--stkptr;
if (stkptr >= 0) {
lo = lostk[stkptr];
hi = histk[stkptr];
goto recurse; /* pop subarray from stack */
}
else
return; /* all subarrays done */
}
/***
*shortsort(hi, lo, width, comp) - insertion sort for sorting short arrays
*
*Purpose:
* sorts the sub-array of elements between lo and hi (inclusive)
* side effects: sorts in place
* assumes that lo < hi
*
*Entry:
* char *lo = pointer to low element to sort
* char *hi = pointer to high element to sort
* unsigned width = width in bytes of each array element
* int (*comp)() = pointer to function returning analog of strcmp for
* strings, but supplied by user for comparing the array elements.
* it accepts 2 pointers to elements and returns neg if 1<2, 0 if
* 1=2, pos if 1>2.
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
static void shortsort (
char *lo,
char *hi,
unsigned width,
int ( *comp)(const void *, const void *)
)
{
char *p, *max;
/* Note: in assertions below, i and j are alway inside original bound of
array to sort. */
while (hi > lo) {
/* A[i] <= A[j] for i <= j, j > hi */
max = lo;
for (p = lo+width; p <= hi; p += width) {
/* A[i] <= A[max] for lo <= i < p */
if (comp(p, max) > 0) {
max = p;
}
/* A[i] <= A[max] for lo <= i <= p */
}
/* A[i] <= A[max] for lo <= i <= hi */
swap(max, hi, width);
/* A[i] <= A[hi] for i <= hi, so A[i] <= A[j] for i <= j, j >= hi */
hi -= width;
/* A[i] <= A[j] for i <= j, j > hi, loop top condition established */
}
/* A[i] <= A[j] for i <= j, j > lo, which implies A[i] <= A[j] for i < j,
so array is sorted */
}
/***
*swap(a, b, width) - swap two elements
*
*Purpose:
* swaps the two array elements of size width
*
*Entry:
* char *a, *b = pointer to two elements to swap
* unsigned width = width in bytes of each array element
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
static void swap (
char *a,
char *b,
unsigned width
)
{
char tmp;
if ( a != b )
/* Do the swap one character at a time to avoid potential alignment
problems. */
while ( width-- ) {
tmp = *a;
*a++ = *b;
*b++ = tmp;
}
}
#endif /* XP_MAC */
#ifdef XP_MAC
#include <OSUtils.h>
static void MyReadLocation(MachineLocation * loc)
{
static MachineLocation storedLoc; // InsideMac, OSUtilities, page 4-20
static Boolean didReadLocation = FALSE;
if (!didReadLocation)
{
ReadLocation(&storedLoc);
didReadLocation = TRUE;
}
*loc = storedLoc;
}
// current local time = GMTDelta() + GMT
// GMT = local time - GMTDelta()
static long GMTDelta()
{
MachineLocation loc;
long gmtDelta;
MyReadLocation(&loc);
gmtDelta = loc.u.gmtDelta & 0x00FFFFFF;
if ((gmtDelta & 0x00800000) != 0)
gmtDelta |= 0xFF000000;
return gmtDelta;
}
// This routine simulates stdclib time(), time in seconds since 1.1.1970
// The time is in GMT
time_t GetTimeMac()
{
unsigned long maclocal;
// Get Mac local time
GetDateTime(&maclocal);
// Get Mac GMT
maclocal -= GMTDelta();
// return unix GMT
return (maclocal - UNIXMINUSMACTIME);
}
// Returns the GMT times
time_t Mactime(time_t *timer)
{
time_t t = GetTimeMac();
if (timer != NULL)
*timer = t;
return t;
}
#endif /* XP_MAC */

View File

@@ -0,0 +1,993 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* jpeg.c --- Glue code to Independent JPEG Group decoder library
* $Id: jpeg.cpp,v 1.1.2.1 1999-04-15 20:16:50 pnunn%netscape.com Exp $
*/
#include "if_struct.h"
#include "dllcompat.h"
#include "nsIImgDecoder.h"
#include "nsImgDecCID.h"
#include "nsJPGDecoder.h"
#include "nsJPGCallback.h"
#include "jpeg.h"
#include "merrors.h"
#include "il.h"
#include <ctype.h> /* to declare isprint() */
#ifndef XP_MAC
# include <sys/types.h>
#endif
PR_BEGIN_EXTERN_C
#include "jpeglib.h"
#include "jerror.h"
extern int MK_OUT_OF_MEMORY;
PR_END_EXTERN_C
#ifdef XP_OS2_HACK
/* 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 <setjmp.h>
#endif
#ifdef PROFILE
# pragma profile on
#endif
/* Normal JFIF markers can't have more bytes than this. */
#define MAX_JPEG_MARKER_LENGTH (((uint32)1 << 16) - 1)
/*
* 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 */
} 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 */
uint32 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);
}
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
*---------------------------------------------------------------------------*/
boolean PR_CALLBACK
fill_input_buffer (j_decompress_ptr jd)
{
il_source_mgr *src = (il_source_mgr *)jd->src;
enum data_source_state data_source_state = src->state;
uint32 bytesToSkip, new_backtrack_buflen, new_buflen, roundup_buflen;
unsigned char *new_buffer;
ILTRACE(5,("il:jpeg: fill, state=%d, nib=0x%x, bib=%d", data_source_state,
src->pub.next_input_byte, src->pub.bytes_in_buffer));
switch (data_source_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. */
XP_BCOPY (src->pub.next_input_byte,
src->backtrack_buffer + src->backtrack_buflen,
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;
}
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.
*/
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.
*---------------------------------------------------------------------------*/
static int
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 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 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)
{
uint 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);
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;
}
int 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 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 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 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 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
uint 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 50000
/* Timeout durations, in milliseconds */
/* Delay between displaying chunks of pixels for the first scan. */
#define JPEG_TIMEOUT_INITIAL_DELAY 100
/* Delay between displaying chunks of pixels for subsequent scans */
#define JPEG_TIMEOUT_DELAY 200
static void
jpeg_timeout_callback(void *closure)
{
uint32 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 = (uint32)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. */
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) {
uint32 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();
ic->imgdcb->ImgDCBHaveImageFrame();
}
#ifdef PROFILE
# pragma profile off
#endif

View File

@@ -0,0 +1,31 @@
/* -*- 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.0 (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.
*/
/* jpeg.h */
extern int il_jpeg_init(il_container *ic);
extern int il_jpeg_write(il_container *, const uint8 *, int32);
extern void il_jpeg_complete(il_container *ic);
extern unsigned int il_jpeg_write_ready(il_container *ic);
extern void il_jpeg_abort(il_container *ic);

View File

@@ -0,0 +1,99 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
#
#------------------------------------------------------------------------
#
# Makefile to build the IMGLIB LIB
#
#------------------------------------------------------------------------
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
LIBRARY_NAME = nsjpg
#
# 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\plc3.lib \
$(DIST)\lib\util.lib \
$(DIST)\lib\jpeg3250.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
!ifdef NU_CACHE
$(DIST)\lib\cache.lib \
!endif
$(NULL)
MISCDEP=$(LLIBS)
LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
LIBRARY_SUFFIX = $(MOZ_BITS)$(VERSION_NUMBER)
MAKE_OBJ_TYPE=DLL
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
DLLNAME=nsjpg$(MOZ_BITS)$(VERSION_NUMBER)
DLL1NAME=nsjpg$(MOZ_BITS)$(VERSION_NUMBER)
PDBFILE=$(DLLNAME).pdb
MAPFILE=$(DLLNAME).map
DEFFILE=nsjpg.def
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
DLL=.\$(OBJDIR)\$(DLLNAME).dll
MAPFILE= $(DLLNAME).map
MODULE=img
DEPTH=..\..\..
LINCS=-I$(DEPTH)/dist/public/xpcom -I. -I$(DEPTH)/dist/public/raptor -I$(DEPTH)/dist/public/jpeg
REQUIRES=nspr xpcom util raptor jpeg
CPPSRCS= nsJPGDecoder.cpp nsJPGCallback.cpp jpeg.cpp dllcompat.cpp
CPP_OBJS= .\$(OBJDIR)\nsJPGDecoder.obj .\$(OBJDIR)\dllcompat.obj \
.\$(OBJDIR)\nsJPGCallback.obj .\$(OBJDIR)\jpeg.obj
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib

View File

@@ -0,0 +1,58 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsJPGDecoder.cpp --- interface to jpg decoder
*/
#include "nsJPGCallback.h"
/* callbks: */
/*-------------class----------*/
NS_IMETHODIMP JPGCallbk::AddRef()
{
NS_INIT_REFCNT();
return NS_OK;
}
NS_IMETHODIMP JPGCallbk::Release()
{
return NS_OK;
}
NS_IMETHODIMP JPGCallbk::QueryInterface(const nsIID& aIID, void** aResult)
{
if (NULL == aResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kImgDCallbkIID)) {
*aResult = (void*) this;
NS_INIT_REFCNT();
return NS_OK;
}
return NS_NOINTERFACE;
}
/*-----------------------------*/

View File

@@ -0,0 +1,56 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsJPGDecoder.cpp --- interface to jpg decoder
*/
#ifndef _nsJPGCallbk_h
#define _nsJPGCallbk_h
#include "nsIImgDecoder.h"
#include "nsJPGDecoder.h"
/* 2b0c6b90-d8b1-11d2-802c-0060088f91a3 */
#define NS_JPGCALLBK_CID \
{ 0x2b0c6b90, 0xd8b1, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/* 5cb47c60-d8b1-11d2-802c-0060088f91a3 */
#define NS_JPGCALLBK_IID \
{ 0x5cb47c60, 0xd8b1, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
class JPGCallbk : public nsIImgDCallbk {
public:
NS_DECL_ISUPPORTS
il_container *GetContainer() {return mContainer;};
il_container *SetContainer(il_container *ic) {mContainer=ic; return ic;};
JPGCallbk(il_container *aContainer){mContainer=aContainer;};
~JPGCallbk();
private:
il_container* mContainer;
};
#endif

View File

@@ -0,0 +1,306 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsJPGDecoder.cpp --- interface to gif decoder
*/
#include "if_struct.h"
#include "jpeg.h"
#include "prmem.h"
#include "merrors.h"
#include "dllcompat.h"
#include "nsJPGDecoder.h"
#include "nsImgDecCID.h"
#include "nsIImgDecoder.h" /* interface class */
#include "nsImgDecoder.h" /* factory */
#include "nscore.h"
/*--- needed for autoregistry ---*/
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
PR_BEGIN_EXTERN_C
extern int MK_OUT_OF_MEMORY;
PR_END_EXTERN_C
/*-----------class----------------*/
class JPGDecoder : public nsIImgDecoder
{
public:
JPGDecoder(il_container* aContainer);
~JPGDecoder();
NS_DECL_ISUPPORTS
/* stream */
NS_IMETHOD ImgDInit();
NS_IMETHOD ImgDWriteReady();
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len);
NS_IMETHOD ImgDComplete();
NS_IMETHOD ImgDAbort();
il_container *SetContainer(il_container *ic){mContainer = ic; return ic;}
il_container *GetContainer() {return mContainer;}
private:
il_container* mContainer;
};
/*-------------------------------------------------*/
JPGDecoder::JPGDecoder(il_container* aContainer)
{
NS_INIT_REFCNT();
mContainer = aContainer;
};
JPGDecoder::~JPGDecoder(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
};
NS_IMETHODIMP
JPGDecoder::QueryInterface(const nsIID& aIID, void** aInstPtr)
{
if (NULL == aInstPtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kJPGDecoderIID) ||
aIID.Equals(kImgDecoderIID) ||
aIID.Equals(kISupportsIID)) {
*aInstPtr = (void*) this;
NS_INIT_REFCNT();
return NS_OK;
}
return NS_NOINTERFACE;
}
/*----------------------------------for autoregistration ----*/
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
extern "C" NS_EXPORT nsresult
NSRegisterSelf(nsISupports* aServMgr, const char *path)
{
nsresult rv;
/**/
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
if ((rv = nsRepository::RegisterComponent(kJPGDecoderCID, "Netscape JPGDec", "component://netscape/image/decoder&type=image/jpeg", path, PR_TRUE, PR_TRUE)
) != NS_OK) {
return rv;
}
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *path)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterFactory(kJPGDecoderCID, path);
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
/*--------------------*/
NS_IMETHODIMP
JPGDecoder::AddRef()
{
NS_INIT_REFCNT();
return NS_OK;
}
NS_IMETHODIMP
JPGDecoder::Release()
{
return NS_OK;
}
/*-----------class----------------*/
class nsJPGDecFactory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
nsJPGDecFactory(const nsCID &aClass);
~nsJPGDecFactory();
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
private:
nsCID mClassID;
il_container *mContainer;
};
/*-----------------------------------------*/
nsJPGDecFactory* gFactory = NULL;
NS_IMPL_ISUPPORTS(nsJPGDecFactory, kIFactoryIID);
nsJPGDecFactory::nsJPGDecFactory(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
}
nsJPGDecFactory::~nsJPGDecFactory(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMETHODIMP
nsJPGDecFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **ppv)
{
JPGDecoder *jpgdec = NULL;
*ppv = NULL;
il_container* ic = NULL;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE;
ic = new il_container();
jpgdec = new JPGDecoder(ic);
nsresult res = jpgdec->QueryInterface(aIID,(void**)ppv);
//interface is other than nsISupports and gifdecoder
if (NS_FAILED(res)) {
*ppv = NULL;
delete jpgdec;
}
return res;
}
NS_METHOD
nsJPGDecFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}
extern "C" NS_EXPORT nsresult
NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if( !aClass.Equals(kJPGDecoderCID))
return NS_ERROR_FACTORY_NOT_REGISTERED;
if( gFactory == NULL){
gFactory = new nsJPGDecFactory(aClass);
if( gFactory == NULL)
return NS_ERROR_OUT_OF_MEMORY;
gFactory->AddRef(); //for global
}
gFactory->AddRef(); //for client
*aFactory = gFactory;
return NS_OK;
}
/*------------------------------------------------------*/
/* api functions
*/
/*------------------------------------------------------*/
NS_IMETHODIMP
JPGDecoder::ImgDInit()
{
if(mContainer != NULL) {
return(il_jpeg_init(mContainer));
}
else {
return nsnull;
}
}
NS_IMETHODIMP
JPGDecoder::ImgDWriteReady()
{ /* IL_StreamWriteReady needs a return 1 */
return 1;
}
NS_IMETHODIMP
JPGDecoder::ImgDWrite(const unsigned char *buf, int32 len)
{
if( mContainer != NULL ) {
return(il_jpeg_write(mContainer, buf,len));
}
return 0;
}
NS_IMETHODIMP
JPGDecoder::ImgDComplete()
{
if( mContainer != NULL ) {
il_jpeg_complete(mContainer);
}
return 0;
}
NS_IMETHODIMP
JPGDecoder::ImgDAbort()
{
if( mContainer != NULL ) {
il_jpeg_abort(mContainer);
}
return 0;
}

View File

@@ -0,0 +1,39 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsJPGDecoder.cpp --- interface to gif decoder
*/
#ifndef _nsJPGDec_h
#define _nsJPGDec_h
/* 1b0e6b90-d68a-11d2-802e-0060088f91a3 */
#define NS_JPGDECODER_CID \
{ 0x1b0e6b90, 0xd68a, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/* 394711e0-d68a-11d2-802e-0060088f91a3 */
#define NS_JPGDECODER_IID \
{ 0x394711e0, 0xd68a, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
static NS_DEFINE_IID(kJPGDecoderIID, NS_JPGDECODER_IID);
static NS_DEFINE_CID(kJPGDecoderCID, NS_JPGDECODER_CID);
#endif

View File

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

Binary file not shown.

View File

@@ -0,0 +1,15 @@
# target: libimgDebug.shlb
mozilla/modules/libimg/src/color.cpp
mozilla/modules/libimg/src/colormap.cpp
mozilla/modules/libimg/src/dither.cpp
mozilla/modules/libimg/src/gif.cpp
mozilla/modules/libimg/src/if.cpp
mozilla/modules/libimg/src/ilclient.cpp
mozilla/modules/libimg/src/ilNetReader.cpp
mozilla/modules/libimg/src/il_util.cpp
mozilla/modules/libimg/src/ipng.cpp
mozilla/modules/libimg/src/jpeg.cpp
mozilla/modules/libimg/src/png_png.cpp
mozilla/modules/libimg/src/scale.cpp
mozilla/modules/libimg/src/xbm.cpp
mozilla/modules/libimg/src/xpcompat.cpp

Binary file not shown.

View File

@@ -0,0 +1,16 @@
# target: pngDebug.o
mozilla/modules/libimg/png/png.c
mozilla/modules/libimg/png/pngerror.c
mozilla/modules/libimg/png/pngget.c
mozilla/modules/libimg/png/pngmem.c
mozilla/modules/libimg/png/pngpread.c
mozilla/modules/libimg/png/pngread.c
mozilla/modules/libimg/png/pngrio.c
mozilla/modules/libimg/png/pngrtran.c
mozilla/modules/libimg/png/pngrutil.c
mozilla/modules/libimg/png/pngset.c
mozilla/modules/libimg/png/pngtrans.c
mozilla/modules/libimg/png/pngwio.c
mozilla/modules/libimg/png/pngwrite.c
mozilla/modules/libimg/png/pngwtran.c
mozilla/modules/libimg/png/pngwutil.c

View File

@@ -0,0 +1,27 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH=..\..
!ifdef STANDALONE_IMAGE_LIB
DIRS = png public src
!else
DIRS = png classes public src
!endif
!include $(DEPTH)\config\rules.mak

View File

@@ -0,0 +1,6 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
png.h
pngconf.h

View File

@@ -0,0 +1,57 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = png
LIBRARY_NAME = png
CSRCS = png.c \
pngerror.c \
pngget.c \
pngmem.c \
pngpread.c \
pngread.c \
pngrio.c \
pngrutil.c \
pngset.c \
pngtrans.c \
pngwio.c \
pngwrite.c \
pngwtran.c \
pngrtran.c \
pngwutil.c \
$(NULL)
EXPORTS = png.h pngconf.h
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
REQUIRES = util
ifndef MOZ_NATIVE_ZLIB
REQUIRES += zlib
endif
LOCAL_INCLUDES = -I$(srcdir)
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,197 @@
README for libpng 1.0.2 - June 14, 1998 (shared library 2.1)
See the note about version numbers near the top of png.h
See INSTALL for instructions on how to install libpng.
This is the first official release of libpng. Don't let the fact that
it's the first release fool you. The libpng library has been in
extensive use and testing for about two and a half years. However, it's
finally gotten to the stage where there haven't been significant
changes to the API in some time, and people have a bad feeling about
libraries with versions < 1.0.
****
Note that some of the changes to the png_info structure render this
version of the library binary incompatible with libpng-0.89 or
earlier versions if you are using a shared library. The type of the
"filler" parameter for png_set_filler() has changed from png_byte to
png_uint_32, which will affect shared-library applications that use
this function.
To avoid problems with changes to the internals of png_info_struct,
new APIs have been made available in 0.95 to avoid direct application
access to info_ptr. These functions are the png_set_<chunk> and
png_get_<chunk> functions. These functions should be used when
accessing/storing the info_struct data, rather than manipulating it
directly, to avoid such problems in the future.
It is important to note that the APIs do not make current programs
that access the info struct directly incompatible with the new
library. However, it is strongly suggested that new programs use
the new APIs (as shown in example.c), and older programs be converted
to the new format, to facilitate upgrades in the future.
****
Additions since 0.90 include the ability to compile libpng as a
Windows DLL, and new APIs for accessing data in the info struct.
Experimental functions include the ability to set weighting and cost
factors for row filter selection, direct reads of integers from buffers
on big-endian processors that support misaligned data access, faster
methods of doing alpha composition, and more accurate 16->8 bit color
conversion.
The additions since 0.89 include the ability to read from a PNG stream
which has had some (or all) of the signature bytes read by the calling
application. This also allows the reading of embedded PNG streams that
do not have the PNG file signature. As well, it is now possible to set
the library action on the detection of chunk CRC errors. It is possible
to set different actions based on whether the CRC error occurred in a
critical or an ancillary chunk.
The changes made to the library, and bugs fixed are based on discussions
on the PNG implementation mailing list <png-implement@dworking.wustl.edu>
and not on material submitted to Guy.
For a detailed description on using libpng, read libpng.txt. For
examples of libpng in a program, see example.c and pngtest.c. For usage
information and restrictions (what little they are) on libpng, see
png.h. For a description on using zlib (the compression library used by
libpng) and zlib's restrictions, see zlib.h
I have included a general makefile, as well as several machine and
compiler specific ones, but you may have to modify one for your own needs.
You should use zlib 1.0.4 or later to run this, but it MAY work with
versions as old as zlib 0.95. Even so, there are bugs in older zlib
versions which can cause the output of invalid compression streams for
some images. You will definitely need zlib 1.0.4 or later if you are
taking advantage of the MS-DOS "far" structure allocation for the small
and medium memory models. You should also note that zlib is a
compression library that is useful for more things than just PNG files.
You can use zlib as a drop-in replacement for fread() and fwrite() if
you are so inclined.
zlib should be available at the same place that libpng is.
If not, it should be at ftp.uu.net in /graphics/png
Eventually, it will be at ftp.uu.net in /pub/archiving/zip/zlib
You may also want a copy of the PNG specification. It is available
as an RFC and a W3C Recommendation. Failing
these resources you can try ftp.uu.net in the /graphics/png directory.
This code is currently being archived at ftp.uu.net in the
/graphics/png directory, and on CompuServe, Lib 20 (PNG SUPPORT)
at GO GRAPHSUP. If you can't find it in any of those places,
e-mail me, and I'll help you find it.
If you have any code changes, requests, problems, etc., please e-mail
them to me. Also, I'd appreciate any make files or project files,
and any modifications you needed to make to get libpng to compile,
along with a #define variable to tell what compiler/system you are on.
If you needed to add transformations to libpng, or wish libpng would
provide the image in a different way, drop me a note (and code, if
possible), so I can consider supporting the transformation.
Finally, if you get any warning messages when compiling libpng
(note: not zlib), and they are easy to fix, I'd appreciate the
fix. Please mention "libpng" somewhere in the subject line. Thanks.
This release was created and will be supported by myself (of course
based in a large way on Guy's and Andreas' earlier work), and the PNG group.
randeg@alumni.rpi.edu
png-implement@dworkin.wustl.edu
You can't reach Guy, the original libpng author, at the addresses
given in previous versions of this document. He and Andreas will read mail
addressed to the png-implement list, however.
Please do not send general questions about PNG. Send them to
the address in the specification (png-group@w3.org). At the same
time, please do not send libpng questions to that address, send them to me
or to png-implement@dworkin.wustl.edu. I'll
get them in the end anyway. If you have a question about something
in the PNG specification that is related to using libpng, send it
to me. Send me any questions that start with "I was using libpng,
and ...". If in doubt, send questions to me. I'll bounce them
to others, if necessary.
Please do not send suggestions on how to change PNG. We have
been discussing PNG for three years now, and it is official and
finished. If you have suggestions for libpng, however, I'll
gladly listen. Even if your suggestion is not used for version
1.0, it may be used later.
Files in this distribution:
CHANGES => Description of changes between libpng versions
README => This file
TODO => Things not implemented in the current library
ansi2knr.1 => Manual page for ansi2knr
ansi2knr.c => Converts files to K&R style function declarations
build.bat => MS-DOS batch file for Borland compiler
descrip.mms => VMS project file
example.c => Example code for using libpng functions
libpng.3 => manual page for libpng
libpng.txt => Description of libpng and its functions
libpngpf.3 => manual page for libpng's private functions
png.5 => manual page for the PNG format
png.c => Basic interface functions common to library
png.h => Library function and interface declarations
pngconf.h => System specific library configuration
pngerror.c => Error/warning message I/O functions
pngget.c => Functions for retrieving info from struct
pngmem.c => Memory handling functions
pngpread.c => Progressive reading functions
pngread.c => Read data/helper high-level functions
pngrio.c => Lowest-level data read I/O functions
pngrtran.c => Read data transformation functions
pngrutil.c => Read data utility functions
pngset.c => Functions for storing data into the info_struct
pngtest.c => Library test program
pngtest.png => Library test sample image
pngtrans.c => Common data transformation functions
pngwio.c => Lowest-level write I/O functions
pngwrite.c => High-level write functions
pngwtran.c => Write data transformations
pngwutil.c => Write utility functions
scripts => Directory containing scripts for building libpng:
descrip.mms => VMS makefile for MMS or MMK
makefile.std => Generic UNIX makefile
makefile.knr => Archaic UNIX Makefile that converts files with ansi2knr
makefile.dec => DEC Alpha UNIX makefile
makefile.sgi => Silicon Graphics IRIX makefile
makefile.sun => Sun makefile
makefile.s2x => Solaris 2.X makefile (gcc, creates libpng.so.2.1.0)
makefile.lnx => Linux/ELF makefile (gcc, creates libpng.so.2.1.0)
makefile.mip => MIPS makefile
makefile.aco => Acorn makefile
makefile.ama => Amiga makefile
smakefile.ppc => AMIGA smakefile for SAS C V6.58/7.00 PPC compiler
(Requires SCOPTIONS, copied from scripts/SCOPTIONS.ppc)
makefile.atr => Atari makefile
makefile.bor => Borland makefile
build.bat => MS-DOS batch file for Borland compiler
makefile.dj2 => DJGPP 2 makefile
makefile.msc => Microsoft C makefile
makefile.w32 => makefile for Microsoft Visual C++ 4.0 and later
makefile.tc3 => Turbo C 3.0 makefile
makefile.os2 => OS/2 Makefile (gcc and emx, requires pngos2.def)
makefile.wat => Watcom 10a+ Makefile, 32-bit flat memory model
pngos2.def => OS/2 module definition file used by makefile.os2
makevms.com => VMS build script
pngdll.mak => To make a png32bd.dll with Borland C++ 4.5
pngdef.pas => Defines for a png32bd.dll with Borland C++ 4.5
Good luck, and happy coding.
-Glenn Randers-Pehrson
Internet: randeg@alumni.rpi.edu
Web: http://www.rpi.edu/~randeg/index.html
-Andreas Eric Dilger
Internet: adilger@enel.ucalgary.ca
Web: http://www-mddsp.enel.ucalgary.ca/People/adilger/
-Guy Eric Schalnat
(formerly of Group 42, Inc)
Internet: gschal@infinet.com

View File

@@ -0,0 +1,100 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
#
#-----------------------------------------
# makefile to build libpng.lib for wintel
#-----------------------------------------
MAKE_OBJ_TYPE=LIB
!ifdef BUILD_DEBUG_GC
LCFLAGS = $(LCFLAGS) -DDEBUG_GC
!endif
EXPORTS = png.h pngconf.h
MODULE=png
DEPTH=..\..\..
LOCAL_INCLUDES=-I.
LIBRARY_NAME=png
CSRCS=png.c pngerror.c pngget.c pngmem.c pngpread.c pngread.c pngrio.c \
pngrutil.c pngset.c pngtrans.c pngwio.c pngwrite.c pngwtran.c \
pngrtran.c pngwutil.c
REQUIRES=util nspr zlib
C_OBJS=.\$(OBJDIR)\png.obj .\$(OBJDIR)\pngerror.obj \
.\$(OBJDIR)\pngget.obj .\$(OBJDIR)\pngmem.obj \
.\$(OBJDIR)\pngpread.obj .\$(OBJDIR)\pngread.obj \
.\$(OBJDIR)\pngrio.obj .\$(OBJDIR)\pngrutil.obj \
.\$(OBJDIR)\pngset.obj .\$(OBJDIR)\pngtrans.obj \
.\$(OBJDIR)\pngwio.obj .\$(OBJDIR)\pngwrite.obj \
.\$(OBJDIR)\pngwtran.obj .\$(OBJDIR)\pngrtran.obj \
.\$(OBJDIR)\pngwutil.obj
!if "$(MOZ_BITS)" != "16"
LINCS=-I$(XPDIST)\public\util -I$(XPDIST)\public\nspr \
-I$(XPDIST)\public\zlib
!endif
include <$(DEPTH)\config\rules.mak>
#export:: $(LIBRARY)
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib\
#install:: export
!if "$(MOZ_BITS)" == "16"
#// We must turn off register optimization for release builds so interpreter.c
#// can build. Otherwise array accesses for segmented arrays don't work. See
#// bug report 67973 for details. (Note: normal setting for release build is
#// -Ox -Os where -Ox = "-Ob1cegilnot -Gs" so we have removed the -Oe.)
#//
$(OBJDIR)\pngrtran.obj: pngrtran.c
@$(CC) @<<$(CFGFILE)
-c
-Ob1cglnots -Gs -UDEBUG -DNDEBUG
$(CFLAGS)
$(LCFLAGS)
$(LINCS)
$(LINCS_1)
$(INCS)
-Fd$(PDBFILE)
-Fo.\$(OBJDIR)\
$(*B).c
<<KEEP
!ifdef MOZ_DEBUG
$(OBJDIR)\pngrutil.obj: pngrutil.c
@$(CC) @<<$(CFGFILE)
-c
-Ob1cgnots -Gs -UDEBUG -DNDEBUG
$(CFLAGS)
$(LCFLAGS)
$(LINCS)
$(LINCS_1)
$(INCS)
-Fd$(PDBFILE)
-Fo.\$(OBJDIR)\
$(*B).c
<<KEEP
!endif
!endif
#//endif moz_bits == 16

View File

@@ -0,0 +1,347 @@
/* png.c - location for general purpose libpng functions
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*/
#define PNG_INTERNAL
#define PNG_NO_EXTERN
#include "png.h"
/* Version information for C files. This had better match the version
* string defined in png.h.
*/
char png_libpng_ver[12] = "1.0.2";
/* Place to hold the signature string for a PNG file. */
png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
/* Constant strings for known chunk types. If you need to add a chunk,
* add a string holding the name here. If you want to make the code
* portable to EBCDIC machines, use ASCII numbers, not characters.
*/
png_byte FARDATA png_IHDR[5] = { 73, 72, 68, 82, '\0'};
png_byte FARDATA png_IDAT[5] = { 73, 68, 65, 84, '\0'};
png_byte FARDATA png_IEND[5] = { 73, 69, 78, 68, '\0'};
png_byte FARDATA png_PLTE[5] = { 80, 76, 84, 69, '\0'};
png_byte FARDATA png_bKGD[5] = { 98, 75, 71, 68, '\0'};
png_byte FARDATA png_cHRM[5] = { 99, 72, 82, 77, '\0'};
png_byte FARDATA png_gAMA[5] = {103, 65, 77, 65, '\0'};
png_byte FARDATA png_hIST[5] = {104, 73, 83, 84, '\0'};
png_byte FARDATA png_oFFs[5] = {111, 70, 70, 115, '\0'};
png_byte FARDATA png_pCAL[5] = {112, 67, 65, 76, '\0'};
png_byte FARDATA png_pHYs[5] = {112, 72, 89, 115, '\0'};
png_byte FARDATA png_sBIT[5] = {115, 66, 73, 84, '\0'};
png_byte FARDATA png_sRGB[5] = {115, 82, 71, 66, '\0'};
png_byte FARDATA png_tEXt[5] = {116, 69, 88, 116, '\0'};
png_byte FARDATA png_tIME[5] = {116, 73, 77, 69, '\0'};
png_byte FARDATA png_tRNS[5] = {116, 82, 78, 83, '\0'};
png_byte FARDATA png_zTXt[5] = {122, 84, 88, 116, '\0'};
/* arrays to facilitate easy interlacing - use pass (0 - 6) as index */
/* start of interlace block */
int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
/* offset to next interlace block */
int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
/* start of interlace block in the y direction */
int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
/* offset to next interlace block in the y direction */
int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
/* Width of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
int FARDATA png_pass_width[] = {8, 4, 4, 2, 2, 1, 1};
*/
/* Height of interlace block. This is not currently used - if you need
* it, uncomment it here and in png.h
int FARDATA png_pass_height[] = {8, 8, 4, 4, 2, 2, 1};
*/
/* Mask to determine which pixels are valid in a pass */
int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
/* Mask to determine which pixels to overwrite while displaying */
int FARDATA png_pass_dsp_mask[] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
/* Tells libpng that we have already handled the first "num_bytes" bytes
* of the PNG file signature. If the PNG data is embedded into another
* stream we can set num_bytes = 8 so that libpng will not attempt to read
* or write any of the magic bytes before it starts on the IHDR.
*/
void
png_set_sig_bytes(png_structp png_ptr, int num_bytes)
{
png_debug(1, "in png_set_sig_bytes\n");
if (num_bytes > 8)
png_error(png_ptr, "Too many bytes for PNG signature.");
png_ptr->sig_bytes = num_bytes < 0 ? 0 : num_bytes;
}
/* Checks whether the supplied bytes match the PNG signature. We allow
* checking less than the full 8-byte signature so that those apps that
* already read the first few bytes of a file to determine the file type
* can simply check the remaining bytes for extra assurance. Returns
* an integer less than, equal to, or greater than zero if sig is found,
* respectively, to be less than, to match, or be greater than the correct
* PNG signature (this is the same behaviour as strcmp, memcmp, etc).
*/
int
png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
{
if (num_to_check > 8)
num_to_check = 8;
else if (num_to_check < 1)
return (0);
if (start > 7)
return (0);
if (start + num_to_check > 8)
num_to_check = 8 - start;
return ((int)(png_memcmp(&sig[start], &png_sig[start], num_to_check)));
}
/* (Obsolete) function to check signature bytes. It does not allow one
* to check a partial signature. This function will be removed in the
* future - use png_sig_cmp().
*/
int
png_check_sig(png_bytep sig, int num)
{
return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
}
/* Function to allocate memory for zlib. */
voidpf
png_zalloc(voidpf png_ptr, uInt items, uInt size)
{
png_uint_32 num_bytes = (png_uint_32)items * size;
png_voidp ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
if (num_bytes > (png_uint_32)0x8000L)
{
png_memset(ptr, 0, (png_size_t)0x8000L);
png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
(png_size_t)(num_bytes - (png_uint_32)0x8000L));
}
else
{
png_memset(ptr, 0, (png_size_t)num_bytes);
}
return ((voidpf)ptr);
}
/* function to free memory for zlib */
void
png_zfree(voidpf png_ptr, voidpf ptr)
{
png_free((png_structp)png_ptr, (png_voidp)ptr);
}
/* Reset the CRC variable to 32 bits of 1's. Care must be taken
* in case CRC is > 32 bits to leave the top bits 0.
*/
void
png_reset_crc(png_structp png_ptr)
{
png_ptr->crc = crc32(0, Z_NULL, 0);
}
/* Calculate the CRC over a section of data. We can only pass as
* much data to this routine as the largest single buffer size. We
* also check that this data will actually be used before going to the
* trouble of calculating it.
*/
void
png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
{
int need_crc = 1;
if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
{
if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
(PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
need_crc = 0;
}
else /* critical */
{
if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
need_crc = 0;
}
if (need_crc)
png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
}
/* Allocate the memory for an info_struct for the application. We don't
* really need the png_ptr, but it could potentially be useful in the
* future. This should be used in favour of malloc(sizeof(png_info))
* and png_info_init() so that applications that want to use a shared
* libpng don't have to be recompiled if png_info changes size.
*/
png_infop
png_create_info_struct(png_structp png_ptr)
{
png_infop info_ptr;
png_debug(1, "in png_create_info_struct\n");
if(png_ptr == NULL) return (NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if ((info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
png_ptr->malloc_fn)) != NULL)
#else
if ((info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO)) != NULL)
#endif
{
png_info_init(info_ptr);
}
return (info_ptr);
}
/* This function frees the memory associated with a single info struct.
* Normally, one would use either png_destroy_read_struct() or
* png_destroy_write_struct() to free an info struct, but this may be
* useful for some applications.
*/
void
png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
{
png_infop info_ptr = NULL;
png_debug(1, "in png_destroy_info_struct\n");
if (info_ptr_ptr != NULL)
info_ptr = *info_ptr_ptr;
if (info_ptr != NULL)
{
png_info_destroy(png_ptr, info_ptr);
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn);
#else
png_destroy_struct((png_voidp)info_ptr);
#endif
*info_ptr_ptr = (png_infop)NULL;
}
}
/* Initialize the info structure. This is now an internal function (0.89)
* and applications using it are urged to use png_create_info_struct()
* instead.
*/
void
png_info_init(png_infop info_ptr)
{
png_debug(1, "in png_info_init\n");
/* set everything to 0 */
png_memset(info_ptr, 0, sizeof (png_info));
}
/* This is an internal routine to free any memory that the info struct is
* pointing to before re-using it or freeing the struct itself. Recall
* that png_free() checks for NULL pointers for us.
*/
void
png_info_destroy(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_debug(1, "in png_info_destroy\n");
if (info_ptr->text != NULL)
{
int i;
for (i = 0; i < info_ptr->num_text; i++)
{
png_free(png_ptr, info_ptr->text[i].key);
}
png_free(png_ptr, info_ptr->text);
}
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
png_free(png_ptr, info_ptr->pcal_purpose);
png_free(png_ptr, info_ptr->pcal_units);
if (info_ptr->pcal_params != NULL)
{
int i;
for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
{
png_free(png_ptr, info_ptr->pcal_params[i]);
}
png_free(png_ptr, info_ptr->pcal_params);
}
#endif
png_info_init(info_ptr);
}
/* This function returns a pointer to the io_ptr associated with the user
* functions. The application should free any memory associated with this
* pointer before png_write_destroy() or png_read_destroy() are called.
*/
png_voidp
png_get_io_ptr(png_structp png_ptr)
{
return (png_ptr->io_ptr);
}
#if !defined(PNG_NO_STDIO)
/* Initialize the default input/output functions for the PNG file. If you
* use your own read or write routines, you can call either png_set_read_fn()
* or png_set_write_fn() instead of png_init_io().
*/
void
png_init_io(png_structp png_ptr, FILE *fp)
{
png_debug(1, "in png_init_io\n");
png_ptr->io_ptr = (png_voidp)fp;
}
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
/* Convert the supplied time into an RFC 1123 string suitable for use in
* a "Creation Time" or other text-based time string.
*/
png_charp
png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
{
static PNG_CONST char short_months[12][4] =
{"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
if (png_ptr->time_buffer == NULL)
{
png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
sizeof(char)));
}
#ifdef USE_FAR_KEYWORD
{
char near_time_buf[29];
sprintf(near_time_buf, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
png_memcpy(png_ptr->time_buffer, near_time_buf,
29*sizeof(char));
}
#else
sprintf(png_ptr->time_buffer, "%d %s %d %02d:%02d:%02d +0000",
ptime->day % 32, short_months[(ptime->month - 1) % 12],
ptime->year, ptime->hour % 24, ptime->minute % 60,
ptime->second % 61);
#endif
return ((png_charp)png_ptr->time_buffer);
}
#endif /* PNG_TIME_RFC1123_SUPPORTED */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,444 @@
/* pngconf.c - machine configurable file for libpng
libpng 1.0 beta 5 - version 0.95
For conditions of distribution and use, see copyright notice in png.h
Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
Copyright (c) 1996, 1997 Andreas Dilger
March 30, 1997
*/
/* Any machine specific code is near the front of this file, so if you
are configuring libpng for a machine, you may want to read the section
starting here down to where it starts to typedef png_color, png_text,
and png_info */
#ifndef PNGCONF_H
#define PNGCONF_H
/* This is the size of the compression buffer, and thus the size of
an IDAT chunk. Make this whatever size you feel is best for your
machine. One of these will be allocated per png_struct. When this
is full, it writes the data to the disk, and does some other
calculations. Making this an extreamly small size will slow
the library down, but you may want to experiment to determine
where it becomes significant, if you are concerned with memory
usage. Note that zlib allocates at least 32Kb also. For readers,
this describes the size of the buffer available to read the data in.
Unless this gets smaller then the size of a row (compressed),
it should not make much difference how big this is. */
#define PNG_ZBUF_SIZE 0x02000
/* If you are running on a machine where you cannot allocate more
than 64K of memory at once, uncomment this. While libpng will not
normally need that much memory in a chunk (unless you load up a very
large file), zlib needs to know how big of a chunk it can use, and
libpng thus makes sure to check any memory allocation to verify it
will fit into memory.
*/
#define PNG_MAX_MALLOC_64K
#if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
#define PNG_MAX_MALLOC_64K
#endif
/* This protects us against compilers which run on a windowing system
and thus don't have or would rather us not use the stdio types:
stdin, stdout, and stderr. The only one currently used is stderr
in png_error() and png_warning(). #defining PNG_NO_STDIO will
prevent these from being compiled and used. */
/* #define PNG_NO_STDIO */
/* for FILE. If you are not using standard io, you don't need this */
#ifndef PNG_NO_STDIO
#include <stdio.h>
#endif
/* This macro protects us against machines that don't have function
prototypes (ie K&R style headers). If your compiler does not handle
function prototypes, define this macro and use the included ansi2knr.
I've always been able to use _NO_PROTO as the indicator, but you may
need to drag the empty declaration out in front of here, or change the
ifdef to suit your own needs. */
#ifndef PNGARG
#ifdef OF /* zlib prototype munger */
#define PNGARG(arglist) OF(arglist)
#else
#ifdef _NO_PROTO
#define PNGARG(arglist) ()
#else
#define PNGARG(arglist) arglist
#endif /* _NO_PROTO */
#endif /* OF */
#endif /* PNGARG */
/* Try to determine if we are compiling on a Mac */
#if defined(__MWERKS__) ||defined(applec) ||defined(THINK_C) ||defined(__SC__)
#define MACOS
#endif
/* enough people need this for various reasons to include it here */
#if !defined(MACOS) && !defined(RISCOS)
#include <sys/types.h>
#endif
/* This is an attempt to force a single setjmp behaviour on Linux. If
the X config stuff didn't define _BSD_SOURCE we wouldn't need this. */
#if defined(linux) && defined(_BSD_SOURCE)
#define _PNG_SAVE_BSD_SOURCE
#undef _BSD_SOURCE
#endif
/* include setjmp.h for error handling */
#include <setjmp.h>
#if defined(linux) && defined(_PNG_SAVE_BSD_SOURCE)
#define _BSD_SOURCE
#undef _PNG_SAVE_BSD_SOURCE
#endif
#ifdef BSD
#include <strings.h>
#else
#include <string.h>
#endif
/* Other defines for things like memory and the like can go here. */
#ifdef PNG_INTERNAL
#include <stdlib.h>
/* Where do we need this???
#include <ctype.h>
*/
/* The functions exported by PNG_EXTERN are PNG_INTERNAL functions, which
* aren't usually used outside the library (as far as I know), so it is
* debatable if they should be exported at all. In the future, when it is
* possible to have run-time registry of chunk-handling functions, some of
* these will be made available again.
#define PNG_EXTERN extern
*/
#define PNG_EXTERN
/* Other defines specific to compilers can go here. Try to keep
them inside an appropriate ifdef/endif pair for portability */
#if defined(MACOS)
/* We need to check that <math.h> hasn't already been included earlier
as it seems it doesn't agree with <fp.h>, yet we should really use
<fp.h> if possible. */
#if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
#include <fp.h>
#endif
#else
#include <math.h>
#endif
/* For some reason, Borland C++ defines memcmp, etc. in mem.h, not
stdlib.h like it should (I think). Or perhaps this is a C++
"feature"? */
#ifdef __TURBOC__
#include <mem.h>
#include "alloc.h"
#endif
#ifdef _MSC_VER
#include <malloc.h>
#endif
/* This controls how fine the dithering gets. As this allocates
a largish chunk of memory (32K), those who are not as concerned
with dithering quality can decrease some or all of these. */
#define PNG_DITHER_RED_BITS 5
#define PNG_DITHER_GREEN_BITS 5
#define PNG_DITHER_BLUE_BITS 5
/* This controls how fine the gamma correction becomes when you
are only interested in 8 bits anyway. Increasing this value
results in more memory being used, and more pow() functions
being called to fill in the gamma tables. Don't set this
value less then 8, and even that may not work (I haven't tested
it). */
#define PNG_MAX_GAMMA_8 11
/* This controls how much a difference in gamma we can tolerate before
we actually start doing gamma conversion. */
#define PNG_GAMMA_THRESHOLD 0.05
#endif /* PNG_INTERNAL */
/* The following uses const char * instead of char * for error
and warning message functions, so some compilers won't complain.
If you want to use const, define PNG_USE_CONST here. It is not
normally defined to make configuration easier, as it is not a
critical part of the code.
*/
#define PNG_USE_CONST
#ifdef PNG_USE_CONST
# define PNG_CONST const
#else
# define PNG_CONST
#endif
/* The following defines give you the ability to remove code from the
library that you will not be using. I wish I could figure out how to
automate this, but I can't do that without making it seriously hard
on the users. So if you are not using an ability, change the #define
to and #undef, and that part of the library will not be compiled. If
your linker can't find a function, you may want to make sure the
ability is defined here. Some of these depend upon some others being
defined. I haven't figured out all the interactions here, so you may
have to experiment awhile to get everything to compile. If you are
creating or using a shared library, you probably shouldn't touch this,
as it will affect the size of the structures, and this will cause bad
things to happen if the library and/or application ever change. */
/* Any transformations you will not be using can be undef'ed here */
#define PNG_PROGRESSIVE_READ_SUPPORTED
#define PNG_READ_OPT_PLTE_SUPPORTED
#define PNG_READ_INTERLACING_SUPPORTED
#define PNG_READ_EXPAND_SUPPORTED
#define PNG_READ_SHIFT_SUPPORTED
#define PNG_READ_PACK_SUPPORTED
#define PNG_READ_BGR_SUPPORTED
#define PNG_READ_SWAP_SUPPORTED
#define PNG_READ_PACKSWAP_SUPPORTED
#define PNG_READ_INVERT_SUPPORTED
#define PNG_READ_DITHER_SUPPORTED
#define PNG_READ_BACKGROUND_SUPPORTED
#define PNG_READ_16_TO_8_SUPPORTED
#define PNG_READ_FILLER_SUPPORTED
#define PNG_READ_GAMMA_SUPPORTED
#define PNG_READ_GRAY_TO_RGB_SUPPORTED
#define PNG_READ_SWAP_ALPHA_SUPPORTED
#undef PNG_READ_STRIP_ALPHA_SUPPORTED
#define PNG_WRITE_INTERLACING_SUPPORTED
#define PNG_WRITE_SHIFT_SUPPORTED
#define PNG_WRITE_PACK_SUPPORTED
#define PNG_WRITE_BGR_SUPPORTED
#define PNG_WRITE_SWAP_SUPPORTED
#define PNG_WRITE_PACKSWAP_SUPPORTED
#define PNG_WRITE_INVERT_SUPPORTED
#define PNG_WRITE_FILLER_SUPPORTED /* This is the same as WRITE_STRIP_ALPHA */
#define PNG_WRITE_FLUSH_SUPPORTED
#define PNG_WRITE_SWAP_ALPHA_SUPPORTED
#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
/* These are currently experimental features */
#undef PNG_READ_16_TO_8_ACCURATE_SHIFT_SUPPORTED /* very little testing */
#undef PNG_READ_COMPOSITE_NODIV_SUPPORTED /* very little testing */
/* This is only for PowerPC big-endian and 680x0 systems */
#undef PNG_READ_BIG_ENDIAN_SUPPORTED /* some testing */
/* These functions are turned off by default, as they will be phased out. */
#undef PNG_USE_OWN_CRC
#define PNG_USELESS_TESTS_SUPPORTED
#undef PNG_CORRECT_PALETTE_SUPPORTED
/* Any chunks you are not interested in, you can undef here. The
* ones that allocate memory may be expecially important (hIST,
* tEXt, zTXt, tRNS, pCAL). Others will just save time and make png_info
* a bit smaller. OPT_PLTE only disables the optional palette in RGB
* and RGBA images.
*/
#define PNG_READ_bKGD_SUPPORTED
#define PNG_READ_cHRM_SUPPORTED
#define PNG_READ_gAMA_SUPPORTED
#define PNG_READ_hIST_SUPPORTED
#define PNG_READ_oFFs_SUPPORTED
#define PNG_READ_pCAL_SUPPORTED
#define PNG_READ_pHYs_SUPPORTED
#define PNG_READ_sBIT_SUPPORTED
#define PNG_READ_tEXt_SUPPORTED
#define PNG_READ_tIME_SUPPORTED
#define PNG_READ_tRNS_SUPPORTED
#define PNG_READ_zTXt_SUPPORTED
#define PNG_WRITE_bKGD_SUPPORTED
#define PNG_WRITE_cHRM_SUPPORTED
#define PNG_WRITE_gAMA_SUPPORTED
#define PNG_WRITE_hIST_SUPPORTED
#define PNG_WRITE_oFFs_SUPPORTED
#define PNG_WRITE_pCAL_SUPPORTED
#define PNG_WRITE_pHYs_SUPPORTED
#define PNG_WRITE_sBIT_SUPPORTED
#define PNG_WRITE_tEXt_SUPPORTED
#define PNG_WRITE_tIME_SUPPORTED
#define PNG_WRITE_tRNS_SUPPORTED
#define PNG_WRITE_zTXt_SUPPORTED
/* need the time information for reading tIME chunks */
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
#include <time.h>
#endif
/* Some typedefs to get us started. These should be safe on most of the
* common platforms. The typedefs should be at least as large as the
* numbers suggest (a png_uint_32 must be at least 32 bits long), but they
* don't have to be exactly that size. Some compilers dislike passing
* unsigned shorts as function parameters, so you may be better off using
* unsigned int for png_uint_16. Likewise, for 64-bit systems, you may
* want to have unsigned int for png_uint_32 instead of unsigned long.
*/
typedef unsigned long png_uint_32;
typedef long png_int_32;
typedef unsigned short png_uint_16;
typedef short png_int_16;
typedef unsigned char png_byte;
/* This is usually size_t. It is typedef'ed just in case you need it to
change (I'm not sure if you will or not, so I thought I'd be safe) */
typedef size_t png_size_t;
/* The following is needed for medium model support. It cannot be in the
* PNG_INTERNAL section. Needs modification for other compilers besides
* MSC. Model independent support declares all arrays and pointers to be
* large using the far keyword. The zlib version used must also support
* model independent data. As of version zlib 1.0.4, the necessary changes
* have been made in zlib. The USE_FAR_KEYWORD define triggers other
* changes that are needed. (Tim Wegner)
*/
/* Separate compiler dependencies (problem here is that zlib.h always
defines FAR. (SJT) */
#ifdef __BORLANDC__
#if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
#define LDATA 1
#else
#define LDATA 0
#endif
#if !defined(__WIN32__) && !defined(__FLAT__)
#define PNG_MAX_MALLOC_64K
#if (LDATA != 1)
#ifndef FAR
#define FAR __far
#endif
#define USE_FAR_KEYWORD
#endif /* LDATA != 1 */
/* Possibly useful for moving data out of default segment.
Uncomment it if you want. Could also define FARDATA as
const if your compiler supports it. (SJT)
# define FARDATA FAR
*/
#endif /* __WIN32__, __FLAT__ */
#endif /* __BORLANDC__ */
/* Suggest testing for specific compiler first before testing for
FAR. The Watcom compiler defines both __MEDIUM__ and M_I86MM,
making reliance oncertain keywords suspect. (SJT) */
/* MSC Medium model */
#if defined(FAR)
# if defined(M_I86MM)
# define USE_FAR_KEYWORD
# define FARDATA FAR
# include <dos.h>
# endif
#endif
/* SJT: default case */
#ifndef FAR
# define FAR
#endif
#define FAR
/* At this point FAR is always defined */
#ifndef FARDATA
#define FARDATA
#endif
/* Add typedefs for pointers */
typedef void FAR * png_voidp;
typedef png_byte FAR * png_bytep;
typedef png_uint_32 FAR * png_uint_32p;
typedef png_int_32 FAR * png_int_32p;
typedef png_uint_16 FAR * png_uint_16p;
typedef png_int_16 FAR * png_int_16p;
typedef PNG_CONST char FAR * png_const_charp;
typedef char FAR * png_charp;
typedef double FAR * png_doublep;
/* Pointers to pointers; i.e. arrays */
typedef png_byte FAR * FAR * png_bytepp;
typedef png_uint_32 FAR * FAR * png_uint_32pp;
typedef png_int_32 FAR * FAR * png_int_32pp;
typedef png_uint_16 FAR * FAR * png_uint_16pp;
typedef png_int_16 FAR * FAR * png_int_16pp;
typedef PNG_CONST char FAR * FAR * png_const_charpp;
typedef char FAR * FAR * png_charpp;
typedef double FAR * FAR * png_doublepp;
/* Pointers to pointers to pointers; i.e. pointer to array */
typedef char FAR * FAR * FAR * png_charppp;
/* libpng typedefs for types in zlib. If zlib changes
* or another compression library is used, then change these.
* Eliminates need to change all the source files.
*/
typedef charf * png_zcharp;
typedef charf * FAR * png_zcharpp;
typedef z_stream FAR * png_zstreamp;
/* allow for compilation as dll under windows */
#ifdef __WIN32DLL__
#define PNG_EXPORT(type,symbol) __declspec(dllexport) type symbol
#endif
#ifndef PNG_EXPORT
#define PNG_EXPORT(t,s) t s
#endif
/* User may want to use these so not in PNG_INTERNAL. Any library functions
that are passed far data must be model independent. */
#if defined(USE_FAR_KEYWORD) /* memory model independent fns */
/* use this to make far-to-near assignments */
# define CHECK 1
# define NOCHECK 0
# define CVT_PTR(ptr) (far_to_near(png_ptr,ptr,CHECK))
# define CVT_PTR_NOCHECK(ptr) (far_to_near(png_ptr,ptr,NOCHECK))
# define png_strlen _fstrlen
# define png_memcmp _fmemcmp /* SJT: added */
# define png_memcpy _fmemcpy
# define png_memset _fmemset
#else /* use the usual functions */
# define CVT_PTR(ptr) (ptr)
# define CVT_PTR_NOCHECK(ptr) (ptr)
# define png_strlen strlen
# define png_memcmp memcmp /* SJT: added */
# define png_memcpy memcpy
# define png_memset memset
#endif
/* End of memory model independent support */
/* Just a double check that someone hasn't tried to define something
* contradictory.
*/
/*
#if (PNG_ZBUF_SIZE > 65536) && defined(PNG_MAX_MALLOC_64K)
#undef PNG_ZBUF_SIZE
#define PNG_ZBUF_SIZE 65536
#endif
*/
#endif /* PNGCONF_H */

View File

@@ -0,0 +1,173 @@
/* pngerror.c - stub functions for i/o and memory allocation
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*
* This file provides a location for all error handling. Users who
* need special error handling are expected to write replacement functions
* and use png_set_error_fn() to use those functions. See the instructions
* at each function.
*/
#define PNG_INTERNAL
#include "png.h"
static void png_default_error PNGARG((png_structp png_ptr,
png_const_charp message));
static void png_default_warning PNGARG((png_structp png_ptr,
png_const_charp message));
/* This function is called whenever there is a fatal error. This function
* should not be changed. If there is a need to handle errors differently,
* you should supply a replacement error function and use png_set_error_fn()
* to replace the error function at run-time.
*/
void
png_error(png_structp png_ptr, png_const_charp message)
{
if (png_ptr->error_fn != NULL)
(*(png_ptr->error_fn))(png_ptr, message);
/* if the following returns or doesn't exist, use the default function,
which will not return */
png_default_error(png_ptr, message);
}
/* This function is called whenever there is a non-fatal error. This function
* should not be changed. If there is a need to handle warnings differently,
* you should supply a replacement warning function and use
* png_set_error_fn() to replace the warning function at run-time.
*/
void
png_warning(png_structp png_ptr, png_const_charp message)
{
if (png_ptr->warning_fn != NULL)
(*(png_ptr->warning_fn))(png_ptr, message);
else
png_default_warning(png_ptr, message);
}
/* These utilities are used internally to build an error message that relates
* to the current chunk. The chunk name comes from png_ptr->chunk_name,
* this is used to prefix the message. The message is limited in length
* to 63 bytes, the name characters are output as hex digits wrapped in []
* if the character is invalid.
*/
#define isnonalpha(c) ((c) < 41 || (c) > 122 || ((c) > 90 && (c) < 97))
static PNG_CONST char png_digit[16] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
static void
png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp message)
{
int iout = 0, iin = 0;
while (iin < 4) {
int c = png_ptr->chunk_name[iin++];
if (isnonalpha(c)) {
buffer[iout++] = '[';
buffer[iout++] = png_digit[(c & 0xf0) >> 4];
buffer[iout++] = png_digit[c & 0xf];
buffer[iout++] = ']';
} else {
buffer[iout++] = c;
}
}
if (message == NULL)
buffer[iout] = 0;
else {
buffer[iout++] = ':';
buffer[iout++] = ' ';
png_memcpy(buffer+iout, message, 64);
buffer[iout+63] = 0;
}
}
void
png_chunk_error(png_structp png_ptr, png_const_charp message)
{
char msg[16+64];
png_format_buffer(png_ptr, msg, message);
png_error(png_ptr, msg);
}
void
png_chunk_warning(png_structp png_ptr, png_const_charp message)
{
char msg[16+64];
png_format_buffer(png_ptr, msg, message);
png_warning(png_ptr, msg);
}
/* This is the default error handling function. Note that replacements for
* this function MUST NOT RETURN, or the program will likely crash. This
* function is used by default, or if the program supplies NULL for the
* error function pointer in png_set_error_fn().
*/
static void
png_default_error(png_structp png_ptr, png_const_charp message)
{
#ifndef PNG_NO_STDIO
fprintf(stderr, "libpng error: %s\n", message);
#endif
#ifdef USE_FAR_KEYWORD
{
jmp_buf jmpbuf;
png_memcpy(jmpbuf,png_ptr->jmpbuf,sizeof(jmp_buf));
longjmp(jmpbuf, 1);
}
#else
longjmp(png_ptr->jmpbuf, 1);
#endif
}
/* This function is called when there is a warning, but the library thinks
* it can continue anyway. Replacement functions don't have to do anything
* here if you don't want them to. In the default configuration, png_ptr is
* not used, but it is passed in case it may be useful.
*/
static void
png_default_warning(png_structp png_ptr, png_const_charp message)
{
if (png_ptr == NULL)
return;
#ifndef PNG_NO_STDIO
fprintf(stderr, "libpng warning: %s\n", message);
#endif
}
/* This function is called when the application wants to use another method
* of handling errors and warnings. Note that the error function MUST NOT
* return to the calling routine or serious problems will occur. The return
* method used in the default routine calls longjmp(png_ptr->jmpbuf, 1)
*/
void
png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warning_fn)
{
png_ptr->error_ptr = error_ptr;
png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn;
}
/* This function returns a pointer to the error_ptr associated with the user
* functions. The application should free any memory associated with this
* pointer before png_write_destroy and png_read_destroy are called.
*/
png_voidp
png_get_error_ptr(png_structp png_ptr)
{
return ((png_voidp)png_ptr->error_ptr);
}

View File

@@ -0,0 +1,643 @@
/* pngget.c - retrieval of values from info struct
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*/
#define PNG_INTERNAL
#include "png.h"
png_uint_32
png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->valid & flag);
else
return(0);
}
png_uint_32
png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->rowbytes);
else
return(0);
}
#ifdef PNG_EASY_ACCESS_SUPPORTED
/* easy access to info, added in libpng-0.99 */
png_uint_32
png_get_image_width(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->width;
}
return (0);
}
png_uint_32
png_get_image_height(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->height;
}
return (0);
}
png_byte
png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->bit_depth;
}
return (0);
}
png_byte
png_get_color_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->color_type;
}
return (0);
}
png_byte
png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->filter_type;
}
return (0);
}
png_byte
png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->interlace_type;
}
return (0);
}
png_byte
png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
{
return info_ptr->compression_type;
}
return (0);
}
png_uint_32
png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
else return (info_ptr->x_pixels_per_unit);
}
else
#endif
return (0);
}
png_uint_32
png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
return (0);
else return (info_ptr->y_pixels_per_unit);
}
else
#endif
return (0);
}
png_uint_32
png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
return (0);
else return (info_ptr->x_pixels_per_unit);
}
else
#endif
return (0);
}
float
png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
if (info_ptr->x_pixels_per_unit == 0)
return ((float)0.0);
else
return ((float)info_ptr->y_pixels_per_unit
/(float)info_ptr->x_pixels_per_unit);
}
else
#endif
return ((float)0.0);
}
png_uint_32
png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
else return (info_ptr->x_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
return (0);
else return (info_ptr->y_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
else return (info_ptr->x_offset);
}
else
#endif
return (0);
}
png_uint_32
png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
{
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
{
png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
return (0);
else return (info_ptr->y_offset);
}
else
#endif
return (0);
}
#ifdef PNG_INCH_CONVERSIONS
png_uint_32
png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
}
png_uint_32
png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
}
png_uint_32
png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
{
return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
*.03937 +.5)
}
float
png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
*.03937/1000000. +.5)
}
float
png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
{
return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
*.03937/1000000. +.5)
}
#if defined(PNG_READ_pHYs_SUPPORTED)
png_uint_32
png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "pHYs");
if (res_x != NULL)
{
*res_x = info_ptr->x_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (res_y != NULL)
{
*res_y = info_ptr->y_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (unit_type != NULL)
{
*unit_type = (int)info_ptr->phys_unit_type;
retval |= PNG_INFO_pHYs;
if(unit_type == 1)
{
if (res_x != NULL) *res_x = (png_uint_32)(*res_x * 39.37 + .50);
if (res_y != NULL) *res_y = (png_uint_32)(*res_y * 39.37 + .50);
}
}
}
return (retval);
}
#endif /* PNG_READ_pHYs_SUPPORTED */
#endif /* PNG_INCH_CONVERSIONS */
/* png_get_channels really belongs in here, too, but it's been around longer */
#endif /* PNG_EASY_ACCESS_SUPPORTED */
png_byte
png_get_channels(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->channels);
else
return (0);
}
png_bytep
png_get_signature(png_structp png_ptr, png_infop info_ptr)
{
if (png_ptr != NULL && info_ptr != NULL)
return(info_ptr->signature);
else
return (NULL);
}
#if defined(PNG_READ_bKGD_SUPPORTED)
png_uint_32
png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
png_color_16p *background)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
&& background != NULL)
{
png_debug1(1, "in %s retrieval function\n", "bKGD");
*background = &(info_ptr->background);
return (PNG_INFO_bKGD);
}
return (0);
}
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
png_uint_32
png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
double *white_x, double *white_y, double *red_x, double *red_y,
double *green_x, double *green_y, double *blue_x, double *blue_y)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
{
png_debug1(1, "in %s retrieval function\n", "cHRM");
if (white_x != NULL)
*white_x = (double)info_ptr->x_white;
if (white_y != NULL)
*white_y = (double)info_ptr->y_white;
if (red_x != NULL)
*red_x = (double)info_ptr->x_red;
if (red_y != NULL)
*red_y = (double)info_ptr->y_red;
if (green_x != NULL)
*green_x = (double)info_ptr->x_green;
if (green_y != NULL)
*green_y = (double)info_ptr->y_green;
if (blue_x != NULL)
*blue_x = (double)info_ptr->x_blue;
if (blue_y != NULL)
*blue_y = (double)info_ptr->y_blue;
return (PNG_INFO_cHRM);
}
return (0);
}
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
png_uint_32
png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
&& file_gamma != NULL)
{
png_debug1(1, "in %s retrieval function\n", "gAMA");
*file_gamma = (double)info_ptr->gamma;
return (PNG_INFO_gAMA);
}
return (0);
}
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
png_uint_32
png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
&& file_srgb_intent != NULL)
{
png_debug1(1, "in %s retrieval function\n", "sRGB");
*file_srgb_intent = (int)info_ptr->srgb_intent;
return (PNG_INFO_sRGB);
}
return (0);
}
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
png_uint_32
png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
&& hist != NULL)
{
png_debug1(1, "in %s retrieval function\n", "hIST");
*hist = info_ptr->hist;
return (PNG_INFO_hIST);
}
return (0);
}
#endif
png_uint_32
png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *width, png_uint_32 *height, int *bit_depth,
int *color_type, int *interlace_type, int *compression_type,
int *filter_type)
{
if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
bit_depth != NULL && color_type != NULL)
{
int pixel_depth, channels;
png_uint_32 rowbytes_per_pixel;
png_debug1(1, "in %s retrieval function\n", "IHDR");
*width = info_ptr->width;
*height = info_ptr->height;
*bit_depth = info_ptr->bit_depth;
*color_type = info_ptr->color_type;
if (compression_type != NULL)
*compression_type = info_ptr->compression_type;
if (filter_type != NULL)
*filter_type = info_ptr->filter_type;
if (interlace_type != NULL)
*interlace_type = info_ptr->interlace_type;
/* check for potential overflow of rowbytes */
if (*color_type == PNG_COLOR_TYPE_PALETTE)
channels = 1;
else if (*color_type & PNG_COLOR_MASK_COLOR)
channels = 3;
else
channels = 1;
if (*color_type & PNG_COLOR_MASK_ALPHA)
channels++;
pixel_depth = *bit_depth * channels;
rowbytes_per_pixel = (pixel_depth + 7) >> 3;
if ((*width > (png_uint_32)2147483647L/rowbytes_per_pixel))
{
png_warning(png_ptr,
"Width too large for libpng to process image data.");
}
return (1);
}
return (0);
}
#if defined(PNG_READ_oFFs_SUPPORTED)
png_uint_32
png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *offset_x, png_uint_32 *offset_y, int *unit_type)
{
if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
&& offset_x != NULL && offset_y != NULL && unit_type != NULL)
{
png_debug1(1, "in %s retrieval function\n", "oFFs");
*offset_x = info_ptr->x_offset;
*offset_y = info_ptr->y_offset;
*unit_type = (int)info_ptr->offset_unit_type;
return (PNG_INFO_oFFs);
}
return (0);
}
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
png_uint_32
png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
png_charp *units, png_charpp *params)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pCAL &&
purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
nparams != NULL && units != NULL && params != NULL)
{
png_debug1(1, "in %s retrieval function\n", "pCAL");
*purpose = info_ptr->pcal_purpose;
*X0 = info_ptr->pcal_X0;
*X1 = info_ptr->pcal_X1;
*type = (int)info_ptr->pcal_type;
*nparams = (int)info_ptr->pcal_nparams;
*units = info_ptr->pcal_units;
*params = info_ptr->pcal_params;
return (PNG_INFO_pCAL);
}
return (0);
}
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
png_uint_32
png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_pHYs)
{
png_debug1(1, "in %s retrieval function\n", "pHYs");
if (res_x != NULL)
{
*res_x = info_ptr->x_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (res_y != NULL)
{
*res_y = info_ptr->y_pixels_per_unit;
retval |= PNG_INFO_pHYs;
}
if (unit_type != NULL)
{
*unit_type = (int)info_ptr->phys_unit_type;
retval |= PNG_INFO_pHYs;
}
}
return (retval);
}
#endif
png_uint_32
png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
int *num_palette)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_PLTE &&
palette != NULL)
{
png_debug1(1, "in %s retrieval function\n", "PLTE");
*palette = info_ptr->palette;
*num_palette = info_ptr->num_palette;
png_debug1(3, "num_palette = %d\n", *num_palette);
return (PNG_INFO_PLTE);
}
return (0);
}
#if defined(PNG_READ_sBIT_SUPPORTED)
png_uint_32
png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_sBIT &&
sig_bit != NULL)
{
png_debug1(1, "in %s retrieval function\n", "sBIT");
*sig_bit = &(info_ptr->sig_bit);
return (PNG_INFO_sBIT);
}
return (0);
}
#endif
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_uint_32
png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
int *num_text)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
{
png_debug1(1, "in %s retrieval function\n",
(png_ptr->chunk_name[0] == '\0' ? "text"
: (png_const_charp)png_ptr->chunk_name));
if (text_ptr != NULL)
*text_ptr = info_ptr->text;
if (num_text != NULL)
*num_text = info_ptr->num_text;
return ((png_uint_32)info_ptr->num_text);
}
return(0);
}
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
png_uint_32
png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
{
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tIME &&
mod_time != NULL)
{
png_debug1(1, "in %s retrieval function\n", "tIME");
*mod_time = &(info_ptr->mod_time);
return (PNG_INFO_tIME);
}
return (0);
}
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
png_uint_32
png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep *trans, int *num_trans, png_color_16p *trans_values)
{
png_uint_32 retval = 0;
if (png_ptr != NULL && info_ptr != NULL && info_ptr->valid & PNG_INFO_tRNS)
{
png_debug1(1, "in %s retrieval function\n", "tRNS");
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
{
if (trans != NULL)
{
*trans = info_ptr->trans;
retval |= PNG_INFO_tRNS;
}
if (trans_values != NULL)
*trans_values = &(info_ptr->trans_values);
}
else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
{
if (trans_values != NULL)
{
*trans_values = &(info_ptr->trans_values);
retval |= PNG_INFO_tRNS;
}
if(trans != NULL)
*trans = NULL;
}
if(num_trans != NULL)
{
*num_trans = info_ptr->num_trans;
retval |= PNG_INFO_tRNS;
}
}
return (retval);
}
#endif

View File

@@ -0,0 +1,511 @@
/* pngmem.c - stub functions for memory allocation
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*
* This file provides a location for all memory allocation. Users who
* need special memory handling are expected to supply replacement
* functions for png_malloc() and png_free(), and to use
* png_create_read_struct_2() and png_create_write_struct_2() to
* identify the replacement functions.
*/
#define PNG_INTERNAL
#include "png.h"
/* Borland DOS special memory handler */
#if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
/* if you change this, be sure to change the one in png.h also */
/* Allocate memory for a png_struct. The malloc and memset can be replaced
by a single call to calloc() if this is thought to improve performance. */
png_voidp
png_create_struct(int type)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL));
}
/* Alternate version of png_create_struct, for use with user-defined malloc. */
png_voidp
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size;
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
size = sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return ((png_voidp)NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
{
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
{
png_memset(struct_ptr, 0, size);
}
return (struct_ptr);
}
/* Free memory allocated by a png_create_struct() call */
void
png_destroy_struct(png_voidp struct_ptr)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
}
/* Free memory allocated by a png_create_struct() call */
void
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{
#endif
if (struct_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
if(free_fn != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
(*(free_fn))(png_ptr, struct_ptr);
struct_ptr = NULL;
return;
}
#endif /* PNG_USER_MEM_SUPPORTED */
farfree (struct_ptr);
struct_ptr = NULL;
}
}
/* Allocate memory. For reasonable files, size should never exceed
* 64K. However, zlib may allocate more then 64K if you don't tell
* it not to. See zconf.h and png.h for more information. zlib does
* need to allocate exactly 64K, so whatever you call here must
* have the ability to do that.
*
* Borland seems to have a problem in DOS mode for exactly 64K.
* It gives you a segment with an offset of 8 (perhaps to store its
* memory stuff). zlib doesn't like this at all, so we have to
* detect and deal with it. This code should not be needed in
* Windows or OS/2 modes, and only in 16 bit mode. This code has
* been updated by Alexander Lehmann for version 0.89 to waste less
* memory.
*
* Note that we can't use png_size_t for the "size" declaration,
* since on some systems a png_size_t is a 16-bit quantity, and as a
* result, we would be truncating potentially larger memory requests
* (which should cause a fatal error) and introducing major problems.
*/
png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size)
{
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret;
#endif
if (png_ptr == NULL || size == 0)
return ((png_voidp)NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL)
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
else
return png_malloc_default(png_ptr, size);
}
png_voidp
png_malloc_default(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
#endif PNG_USER_MEM_SUPPORTED
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K");
#endif
if (size == (png_uint_32)65536L)
{
if (png_ptr->offset_table == NULL)
{
/* try to see if we need to do any of this fancy stuff */
ret = farmalloc(size);
if (ret == NULL || ((png_size_t)ret & 0xffff))
{
int num_blocks;
png_uint_32 total_size;
png_bytep table;
int i;
png_byte huge * hptr;
if (ret != NULL)
{
farfree(ret);
ret = NULL;
}
num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
if (num_blocks < 1)
num_blocks = 1;
if (png_ptr->zlib_mem_level >= 7)
num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
else
num_blocks++;
total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
table = farmalloc(total_size);
if (table == NULL)
{
png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
}
if ((png_size_t)table & 0xfff0)
{
png_error(png_ptr, "Farmalloc didn't return normalized pointer");
}
png_ptr->offset_table = table;
png_ptr->offset_table_ptr = farmalloc(num_blocks *
sizeof (png_bytep));
if (png_ptr->offset_table_ptr == NULL)
{
png_error(png_ptr, "Out Of memory.");
}
hptr = (png_byte huge *)table;
if ((png_size_t)hptr & 0xf)
{
hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
hptr += 16L;
}
for (i = 0; i < num_blocks; i++)
{
png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
hptr += (png_uint_32)65536L;
}
png_ptr->offset_table_number = num_blocks;
png_ptr->offset_table_count = 0;
png_ptr->offset_table_count_free = 0;
}
}
if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
png_error(png_ptr, "Out of Memory.");
ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
}
else
ret = farmalloc(size);
if (ret == NULL)
{
png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
}
return (ret);
}
/* free a pointer allocated by png_malloc(). In the default
configuration, png_ptr is not used, but is passed in case it
is needed. If ptr is NULL, return without taking any action. */
void
png_free(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
#ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr->free_fn != NULL)
{
(*(png_ptr->free_fn))(png_ptr, ptr);
ptr = NULL;
return;
}
else png_free_default(png_ptr, ptr);
}
void
png_free_default(png_structp png_ptr, png_voidp ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (png_ptr->offset_table != NULL)
{
int i;
for (i = 0; i < png_ptr->offset_table_count; i++)
{
if (ptr == png_ptr->offset_table_ptr[i])
{
ptr = NULL;
png_ptr->offset_table_count_free++;
break;
}
}
if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
{
farfree(png_ptr->offset_table);
farfree(png_ptr->offset_table_ptr);
png_ptr->offset_table = NULL;
png_ptr->offset_table_ptr = NULL;
}
}
if (ptr != NULL)
{
farfree(ptr);
ptr = NULL;
}
}
#else /* Not the Borland DOS special memory handler */
/* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/
png_voidp
png_create_struct(int type)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_struct_2(type, NULL));
}
/* Allocate memory for a png_struct or a png_info. The malloc and
memset can be replaced by a single call to calloc() if this is thought
to improve performance noticably.*/
png_voidp
png_create_struct_2(int type, png_malloc_ptr malloc_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_size_t size;
png_voidp struct_ptr;
if (type == PNG_STRUCT_INFO)
size = sizeof(png_info);
else if (type == PNG_STRUCT_PNG)
size = sizeof(png_struct);
else
return ((png_voidp)NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(malloc_fn != NULL)
{
if ((struct_ptr = (*(malloc_fn))(NULL, size)) != NULL)
png_memset(struct_ptr, 0, size);
return (struct_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__)
if ((struct_ptr = (png_voidp)farmalloc(size)) != NULL)
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
if ((struct_ptr = (png_voidp)halloc(size,1)) != NULL)
# else
if ((struct_ptr = (png_voidp)malloc(size)) != NULL)
# endif
#endif
{
png_memset(struct_ptr, 0, size);
}
return (struct_ptr);
}
/* Free memory allocated by a png_create_struct() call */
void
png_destroy_struct(png_voidp struct_ptr)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2(struct_ptr, (png_free_ptr)NULL);
}
/* Free memory allocated by a png_create_struct() call */
void
png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
if (struct_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
if(free_fn != NULL)
{
png_struct dummy_struct;
png_structp png_ptr = &dummy_struct;
(*(free_fn))(png_ptr, struct_ptr);
struct_ptr = NULL;
return;
}
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__)
farfree(struct_ptr);
struct_ptr = NULL;
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
hfree(struct_ptr);
struct_ptr = NULL;
# else
free(struct_ptr);
struct_ptr = NULL;
# endif
#endif
}
}
/* Allocate memory. For reasonable files, size should never exceed
64K. However, zlib may allocate more then 64K if you don't tell
it not to. See zconf.h and png.h for more information. zlib does
need to allocate exactly 64K, so whatever you call here must
have the ability to do that. */
png_voidp
png_malloc(png_structp png_ptr, png_uint_32 size)
{
#ifndef PNG_USER_MEM_SUPPORTED
png_voidp ret;
#endif
if (png_ptr == NULL || size == 0)
return ((png_voidp)NULL);
#ifdef PNG_USER_MEM_SUPPORTED
if(png_ptr->malloc_fn != NULL)
return ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, size));
else
return (png_malloc_default(png_ptr, size));
}
png_voidp
png_malloc_default(png_structp png_ptr, png_uint_32 size)
{
png_voidp ret;
#endif /* PNG_USER_MEM_SUPPORTED */
#ifdef PNG_MAX_MALLOC_64K
if (size > (png_uint_32)65536L)
png_error(png_ptr, "Cannot Allocate > 64K");
#endif
#if defined(__TURBOC__) && !defined(__FLAT__)
ret = farmalloc(size);
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
ret = halloc(size, 1);
# else
ret = malloc((size_t)size);
# endif
#endif
if (ret == NULL)
{
png_error(png_ptr, "Out of Memory");
}
return (ret);
}
/* Free a pointer allocated by png_malloc(). If ptr is NULL, return
without taking any action. */
void
png_free(png_structp png_ptr, png_voidp ptr)
{
if (png_ptr == NULL || ptr == NULL)
return;
#ifdef PNG_USER_MEM_SUPPORTED
if (png_ptr->free_fn != NULL)
{
(*(png_ptr->free_fn))(png_ptr, ptr);
ptr = NULL;
return;
}
else png_free_default(png_ptr, ptr);
}
void
png_free_default(png_structp png_ptr, png_voidp ptr)
{
#endif /* PNG_USER_MEM_SUPPORTED */
#if defined(__TURBOC__) && !defined(__FLAT__)
farfree(ptr);
ptr = NULL;
#else
# if defined(_MSC_VER) && defined(MAXSEG_64K)
hfree(ptr);
ptr = NULL;
# else
free(ptr);
ptr = NULL;
# endif
#endif
}
#endif /* Not Borland DOS special memory handler */
png_voidp
png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
png_uint_32 length)
{
png_size_t size;
size = (png_size_t)length;
if ((png_uint_32)size != length)
png_error(png_ptr,"Overflow in png_memcpy_check.");
return(png_memcpy (s1, s2, size));
}
png_voidp
png_memset_check (png_structp png_ptr, png_voidp s1, int value,
png_uint_32 length)
{
png_size_t size;
size = (png_size_t)length;
if ((png_uint_32)size != length)
png_error(png_ptr,"Overflow in png_memset_check.");
return (png_memset (s1, value, size));
}
#ifdef PNG_USER_MEM_SUPPORTED
/* This function is called when the application wants to use another method
* of allocating and freeing memory.
*/
void
png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
malloc_fn, png_free_ptr free_fn)
{
png_ptr->mem_ptr = mem_ptr;
png_ptr->malloc_fn = malloc_fn;
png_ptr->free_fn = free_fn;
}
/* This function returns a pointer to the mem_ptr associated with the user
* functions. The application should free any memory associated with this
* pointer before png_write_destroy and png_read_destroy are called.
*/
png_voidp
png_get_mem_ptr(png_structp png_ptr)
{
return ((png_voidp)png_ptr->mem_ptr);
}
#endif /* PNG_USER_MEM_SUPPORTED */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,885 @@
/* pngread.c - read a PNG file
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*
* This file contains routines that an application calls directly to
* read a PNG file or stream.
*/
#define PNG_INTERNAL
#include "png.h"
/* Create a PNG structure for reading, and allocate any memory needed. */
png_structp
png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn)
{
#ifdef PNG_USER_MEM_SUPPORTED
return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
warn_fn, NULL, NULL, NULL));
}
/* Alternate create PNG structure for reading, and allocate any memory needed. */
png_structp
png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
png_malloc_ptr malloc_fn, png_free_ptr free_fn)
{
#endif /* PNG_USER_MEM_SUPPORTED */
png_structp png_ptr;
#ifdef USE_FAR_KEYWORD
jmp_buf jmpbuf;
#endif
png_debug(1, "in png_create_read_struct\n");
#ifdef PNG_USER_MEM_SUPPORTED
if ((png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
(png_malloc_ptr)malloc_fn)) == NULL)
#else
if ((png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG)) == NULL)
#endif
{
return (png_structp)NULL;
}
#ifdef USE_FAR_KEYWORD
if (setjmp(jmpbuf))
#else
if (setjmp(png_ptr->jmpbuf))
#endif
{
png_free(png_ptr, png_ptr->zbuf);
png_destroy_struct(png_ptr);
return (png_structp)NULL;
}
#ifdef USE_FAR_KEYWORD
png_memcpy(png_ptr->jmpbuf,jmpbuf,sizeof(jmp_buf));
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
#endif /* PNG_USER_MEM_SUPPORTED */
png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
/* Libpng 0.90 and later are binary incompatible with libpng 0.89, so
* we must recompile any applications that use any older library version.
* For versions after libpng 1.0, we will be compatible, so we need
* only check the first digit.
*/
if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
(user_png_ver[0] == '0' && user_png_ver[2] < '9'))
{
png_error(png_ptr,
"Incompatible libpng version in application and library");
}
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
switch (inflateInit(&png_ptr->zstream))
{
case Z_OK: /* Do nothing */ break;
case Z_MEM_ERROR:
case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
default: png_error(png_ptr, "Unknown zlib error");
}
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, NULL, NULL);
return (png_ptr);
}
/* Initialize PNG structure for reading, and allocate any memory needed.
This interface is deprecated in favour of the png_create_read_struct(),
and it will eventually disappear. */
void
png_read_init(png_structp png_ptr)
{
jmp_buf tmp_jmp; /* to save current jump buffer */
png_debug(1, "in png_read_init\n");
/* save jump buffer and error functions */
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
/* reset all variables to 0 */
png_memset(png_ptr, 0, sizeof (png_struct));
/* restore jump buffer */
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
/* initialize zbuf - compression buffer */
png_ptr->zbuf_size = PNG_ZBUF_SIZE;
png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
(png_uint_32)png_ptr->zbuf_size);
png_ptr->zstream.zalloc = png_zalloc;
png_ptr->zstream.zfree = png_zfree;
png_ptr->zstream.opaque = (voidpf)png_ptr;
switch (inflateInit(&png_ptr->zstream))
{
case Z_OK: /* Do nothing */ break;
case Z_MEM_ERROR:
case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
default: png_error(png_ptr, "Unknown zlib error");
}
png_ptr->zstream.next_out = png_ptr->zbuf;
png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
png_set_read_fn(png_ptr, NULL, NULL);
}
/* Read the information before the actual image data. This has been
* changed in v0.90 to allow reading a file that already has the magic
* bytes read from the stream. You can tell libpng how many bytes have
* been read from the beginning of the stream (up to the maximum of 8)
* via png_set_sig_bytes(), and we will only check the remaining bytes
* here. The application can then have access to the signature bytes we
* read if it is determined that this isn't a valid PNG file.
*/
void
png_read_info(png_structp png_ptr, png_infop info_ptr)
{
png_debug(1, "in png_read_info\n");
/* save jump buffer and error functions */
/* If we haven't checked all of the PNG signature bytes, do so now. */
if (png_ptr->sig_bytes < 8)
{
png_size_t num_checked = png_ptr->sig_bytes,
num_to_check = 8 - num_checked;
png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
png_ptr->sig_bytes = 8;
if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
{
if (num_checked < 4 &&
png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
png_error(png_ptr, "Not a PNG file");
else
png_error(png_ptr, "PNG file corrupted by ASCII conversion");
}
}
for(;;)
{
png_byte chunk_length[4];
png_uint_32 length;
png_read_data(png_ptr, chunk_length, 4);
length = png_get_uint_32(chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
/* This should be a binary subdivision search or a hash for
* matching the chunk name rather than a linear search.
*/
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
png_handle_IHDR(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
png_handle_IEND(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
{
if (!(png_ptr->mode & PNG_HAVE_IHDR))
png_error(png_ptr, "Missing IHDR before IDAT");
else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
!(png_ptr->mode & PNG_HAVE_PLTE))
png_error(png_ptr, "Missing PLTE before IDAT");
png_ptr->idat_size = length;
png_ptr->mode |= PNG_HAVE_IDAT;
break;
}
#if defined(PNG_READ_bKGD_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
png_handle_bKGD(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
png_handle_cHRM(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
png_handle_gAMA(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
png_handle_hIST(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
png_handle_oFFs(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
png_handle_pCAL(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
png_handle_pHYs(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
png_handle_sBIT(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
png_handle_sRGB(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
png_handle_tEXt(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
png_handle_tIME(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
png_handle_tRNS(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
png_handle_zTXt(png_ptr, info_ptr, length);
#endif
else
png_handle_unknown(png_ptr, info_ptr, length);
}
}
/* optional call to update the users info_ptr structure */
void
png_read_update_info(png_structp png_ptr, png_infop info_ptr)
{
png_debug(1, "in png_read_update_info\n");
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
png_read_transform_info(png_ptr, info_ptr);
}
/* Initialize palette, background, etc, after transformations
* are set, but before any reading takes place. This allows
* the user to obtain a gamma-corrected palette, for example.
* If the user doesn't call this, we will do it ourselves.
*/
void
png_start_read_image(png_structp png_ptr)
{
png_debug(1, "in png_start_read_image\n");
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
}
void
png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
{
int ret;
png_debug2(1, "in png_read_row (row %d, pass %d)\n",
png_ptr->row_number, png_ptr->pass);
/* save jump buffer and error functions */
if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
png_read_start_row(png_ptr);
if (png_ptr->row_number == 0 && png_ptr->pass == 0)
{
/* check for transforms that have been set but were defined out */
#if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_MONO)
png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
if (png_ptr->transformations & PNG_FILLER)
png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
if (png_ptr->transformations & PNG_PACK)
png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
if (png_ptr->transformations & PNG_SHIFT)
png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
if (png_ptr->transformations & PNG_BGR)
png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
#endif
#if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
#endif
}
#if defined(PNG_READ_INTERLACING_SUPPORTED)
/* if interlaced and we do not need a new row, combine row and return */
if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
{
switch (png_ptr->pass)
{
case 0:
if (png_ptr->row_number & 7)
{
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
png_read_finish_row(png_ptr);
return;
}
break;
case 1:
if ((png_ptr->row_number & 7) || png_ptr->width < 5)
{
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
png_read_finish_row(png_ptr);
return;
}
break;
case 2:
if ((png_ptr->row_number & 7) != 4)
{
if (dsp_row != NULL && (png_ptr->row_number & 4))
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
png_read_finish_row(png_ptr);
return;
}
break;
case 3:
if ((png_ptr->row_number & 3) || png_ptr->width < 3)
{
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
png_read_finish_row(png_ptr);
return;
}
break;
case 4:
if ((png_ptr->row_number & 3) != 2)
{
if (dsp_row != NULL && (png_ptr->row_number & 2))
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
png_read_finish_row(png_ptr);
return;
}
break;
case 5:
if ((png_ptr->row_number & 1) || png_ptr->width < 2)
{
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
png_read_finish_row(png_ptr);
return;
}
break;
case 6:
if (!(png_ptr->row_number & 1))
{
png_read_finish_row(png_ptr);
return;
}
break;
}
}
#endif
if (!(png_ptr->mode & PNG_HAVE_IDAT))
png_error(png_ptr, "Invalid attempt to read row data");
png_ptr->zstream.next_out = png_ptr->row_buf;
png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
do
{
if (!(png_ptr->zstream.avail_in))
{
while (!png_ptr->idat_size)
{
png_byte chunk_length[4];
png_crc_finish(png_ptr, 0);
png_read_data(png_ptr, chunk_length, 4);
png_ptr->idat_size = png_get_uint_32(chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
png_error(png_ptr, "Not enough image data");
}
png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
png_ptr->zstream.next_in = png_ptr->zbuf;
if (png_ptr->zbuf_size > png_ptr->idat_size)
png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
png_crc_read(png_ptr, png_ptr->zbuf,
(png_size_t)png_ptr->zstream.avail_in);
png_ptr->idat_size -= png_ptr->zstream.avail_in;
}
ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
if (ret == Z_STREAM_END)
{
if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
png_ptr->idat_size)
png_error(png_ptr, "Extra compressed data");
png_ptr->mode |= PNG_AFTER_IDAT;
png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
break;
}
if (ret != Z_OK)
png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
"Decompression error");
} while (png_ptr->zstream.avail_out);
png_ptr->row_info.color_type = png_ptr->color_type;
png_ptr->row_info.width = png_ptr->iwidth;
png_ptr->row_info.channels = png_ptr->channels;
png_ptr->row_info.bit_depth = png_ptr->bit_depth;
png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
{
png_ptr->row_info.rowbytes = ((png_ptr->row_info.width *
(png_uint_32)png_ptr->row_info.pixel_depth + 7) >> 3);
}
png_read_filter_row(png_ptr, &(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->prev_row + 1,
(int)(png_ptr->row_buf[0]));
png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
png_ptr->rowbytes + 1);
if (png_ptr->transformations)
png_do_read_transformations(png_ptr);
#if defined(PNG_READ_INTERLACING_SUPPORTED)
/* blow up interlaced rows to full size */
if (png_ptr->interlaced &&
(png_ptr->transformations & PNG_INTERLACE))
{
if (png_ptr->pass < 6)
png_do_read_interlace(&(png_ptr->row_info),
png_ptr->row_buf + 1, png_ptr->pass, png_ptr->transformations);
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row,
png_pass_dsp_mask[png_ptr->pass]);
if (row != NULL)
png_combine_row(png_ptr, row,
png_pass_mask[png_ptr->pass]);
}
else
#endif
{
if (row != NULL)
png_combine_row(png_ptr, row, 0xff);
if (dsp_row != NULL)
png_combine_row(png_ptr, dsp_row, 0xff);
}
png_read_finish_row(png_ptr);
if (png_ptr->read_row_fn != NULL)
(*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
}
/* Read one or more rows of image data. If the image is interlaced,
* and png_set_interlace_handling() has been called, the rows need to
* contain the contents of the rows from the previous pass. If the
* image has alpha or transparency, and png_handle_alpha()[*] has been
* called, the rows contents must be initialized to the contents of the
* screen.
*
* "row" holds the actual image, and pixels are placed in it
* as they arrive. If the image is displayed after each pass, it will
* appear to "sparkle" in. "display_row" can be used to display a
* "chunky" progressive image, with finer detail added as it becomes
* available. If you do not want this "chunky" display, you may pass
* NULL for display_row. If you do not want the sparkle display, and
* you have not called png_handle_alpha(), you may pass NULL for rows.
* If you have called png_handle_alpha(), and the image has either an
* alpha channel or a transparency chunk, you must provide a buffer for
* rows. In this case, you do not have to provide a display_row buffer
* also, but you may. If the image is not interlaced, or if you have
* not called png_set_interlace_handling(), the display_row buffer will
* be ignored, so pass NULL to it.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.2.
*/
void
png_read_rows(png_structp png_ptr, png_bytepp row,
png_bytepp display_row, png_uint_32 num_rows)
{
png_uint_32 i;
png_bytepp rp;
png_bytepp dp;
png_debug(1, "in png_read_rows\n");
/* save jump buffer and error functions */
rp = row;
dp = display_row;
if (rp != NULL && dp != NULL)
for (i = 0; i < num_rows; i++)
{
png_bytep rptr = *rp++;
png_bytep dptr = *dp++;
png_read_row(png_ptr, rptr, dptr);
}
else if(rp != NULL)
for (i = 0; i < num_rows; i++)
{
png_bytep rptr = *rp;
png_read_row(png_ptr, rptr, NULL);
rp++;
}
else if(dp != NULL)
for (i = 0; i < num_rows; i++)
{
png_bytep dptr = *dp;
png_read_row(png_ptr, NULL, dptr);
dp++;
}
}
/* Read the entire image. If the image has an alpha channel or a tRNS
* chunk, and you have called png_handle_alpha()[*], you will need to
* initialize the image to the current image that PNG will be overlaying.
* We set the num_rows again here, in case it was incorrectly set in
* png_read_start_row() by a call to png_read_update_info() or
* png_start_read_image() if png_set_interlace_handling() wasn't called
* prior to either of these functions like it should have been. You can
* only call this function once. If you desire to have an image for
* each pass of a interlaced image, use png_read_rows() instead.
*
* [*] png_handle_alpha() does not exist yet, as of libpng version 1.0.2.
*/
void
png_read_image(png_structp png_ptr, png_bytepp image)
{
png_uint_32 i,image_height;
int pass, j;
png_bytepp rp;
png_debug(1, "in png_read_image\n");
/* save jump buffer and error functions */
pass = png_set_interlace_handling(png_ptr);
image_height=png_ptr->height;
png_ptr->num_rows = image_height; /* Make sure this is set correctly */
for (j = 0; j < pass; j++)
{
rp = image;
for (i = 0; i < image_height; i++)
{
png_read_row(png_ptr, *rp, NULL);
rp++;
}
}
}
/* Read the end of the PNG file. Will not read past the end of the
* file, will verify the end is accurate, and will read any comments
* or time information at the end of the file, if info is not NULL.
*/
void
png_read_end(png_structp png_ptr, png_infop info_ptr)
{
png_byte chunk_length[4];
png_uint_32 length;
png_debug(1, "in png_read_end\n");
/* save jump buffer and error functions */
png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
do
{
png_read_data(png_ptr, chunk_length, 4);
length = png_get_uint_32(chunk_length);
png_reset_crc(png_ptr);
png_crc_read(png_ptr, png_ptr->chunk_name, 4);
png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
png_handle_IHDR(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
{
/* Zero length IDATs are legal after the last IDAT has been
* read, but not after other chunks have been read.
*/
if (length > 0 || png_ptr->mode & PNG_AFTER_IDAT)
png_error(png_ptr, "Too many IDAT's found");
else
png_crc_finish(png_ptr, 0);
}
else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
png_handle_PLTE(png_ptr, info_ptr, length);
else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
png_handle_IEND(png_ptr, info_ptr, length);
#if defined(PNG_READ_bKGD_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
png_handle_bKGD(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_cHRM_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
png_handle_cHRM(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_gAMA_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
png_handle_gAMA(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_hIST_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
png_handle_hIST(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_oFFs_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
png_handle_oFFs(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_pCAL_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
png_handle_pCAL(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_pHYs_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
png_handle_pHYs(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_sBIT_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
png_handle_sBIT(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_sRGB_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
png_handle_sRGB(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_tEXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
png_handle_tEXt(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_tIME_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
png_handle_tIME(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_tRNS_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
png_handle_tRNS(png_ptr, info_ptr, length);
#endif
#if defined(PNG_READ_zTXt_SUPPORTED)
else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
png_handle_zTXt(png_ptr, info_ptr, length);
#endif
else
png_handle_unknown(png_ptr, info_ptr, length);
} while (!(png_ptr->mode & PNG_HAVE_IEND));
}
/* free all memory used by the read */
void
png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
png_infopp end_info_ptr_ptr)
{
png_structp png_ptr = NULL;
png_infop info_ptr = NULL, end_info_ptr = NULL;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn = NULL;
#endif /* PNG_USER_MEM_SUPPORTED */
png_debug(1, "in png_destroy_read_struct\n");
/* save jump buffer and error functions */
if (png_ptr_ptr != NULL)
png_ptr = *png_ptr_ptr;
if (info_ptr_ptr != NULL)
info_ptr = *info_ptr_ptr;
if (end_info_ptr_ptr != NULL)
end_info_ptr = *end_info_ptr_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
#endif
png_read_destroy(png_ptr, info_ptr, end_info_ptr);
if (info_ptr != NULL)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_free(png_ptr, info_ptr->text);
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)info_ptr, free_fn);
#else
png_destroy_struct((png_voidp)info_ptr);
#endif
*info_ptr_ptr = (png_infop)NULL;
}
if (end_info_ptr != NULL)
{
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_READ_zTXt_SUPPORTED)
png_free(png_ptr, end_info_ptr->text);
#endif
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)end_info_ptr, free_fn);
#else
png_destroy_struct((png_voidp)end_info_ptr);
#endif
*end_info_ptr_ptr = (png_infop)NULL;
}
if (png_ptr != NULL)
{
#ifdef PNG_USER_MEM_SUPPORTED
png_destroy_struct_2((png_voidp)png_ptr, free_fn);
#else
png_destroy_struct((png_voidp)png_ptr);
#endif
*png_ptr_ptr = (png_structp)NULL;
}
}
/* free all memory used by the read (old method) */
void
png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
{
jmp_buf tmp_jmp;
png_error_ptr error_fn;
png_error_ptr warning_fn;
png_voidp error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
png_free_ptr free_fn;
#endif
png_debug(1, "in png_read_destroy\n");
/* save jump buffer and error functions */
if (info_ptr != NULL)
png_info_destroy(png_ptr, info_ptr);
if (end_info_ptr != NULL)
png_info_destroy(png_ptr, end_info_ptr);
png_free(png_ptr, png_ptr->zbuf);
png_free(png_ptr, png_ptr->row_buf);
png_free(png_ptr, png_ptr->prev_row);
#if defined(PNG_READ_DITHER_SUPPORTED)
png_free(png_ptr, png_ptr->palette_lookup);
png_free(png_ptr, png_ptr->dither_index);
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
png_free(png_ptr, png_ptr->gamma_table);
#endif
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
png_free(png_ptr, png_ptr->gamma_from_1);
png_free(png_ptr, png_ptr->gamma_to_1);
#endif
if (png_ptr->flags & PNG_FLAG_FREE_PALETTE)
png_zfree(png_ptr, png_ptr->palette);
if (png_ptr->flags & PNG_FLAG_FREE_TRANS)
png_free(png_ptr, png_ptr->trans);
#if defined(PNG_READ_hIST_SUPPORTED)
if (png_ptr->flags & PNG_FLAG_FREE_HIST)
png_free(png_ptr, png_ptr->hist);
#endif
#if defined(PNG_READ_GAMMA_SUPPORTED)
if (png_ptr->gamma_16_table != NULL)
{
int i;
int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++)
{
png_free(png_ptr, png_ptr->gamma_16_table[i]);
}
}
#if defined(PNG_READ_BACKGROUND_SUPPORTED)
png_free(png_ptr, png_ptr->gamma_16_table);
if (png_ptr->gamma_16_from_1 != NULL)
{
int i;
int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++)
{
png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
}
}
png_free(png_ptr, png_ptr->gamma_16_from_1);
if (png_ptr->gamma_16_to_1 != NULL)
{
int i;
int istop = (1 << (8 - png_ptr->gamma_shift));
for (i = 0; i < istop; i++)
{
png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
}
}
png_free(png_ptr, png_ptr->gamma_16_to_1);
#endif
#endif
#if defined(PNG_TIME_RFC1123_SUPPORTED)
png_free(png_ptr, png_ptr->time_buffer);
#endif /* PNG_TIME_RFC1123_SUPPORTED */
inflateEnd(&png_ptr->zstream);
#ifdef PNG_PROGRESSIVE_READ_SUPPORTED
png_free(png_ptr, png_ptr->save_buffer);
#endif
/* Save the important info out of the png_struct, in case it is
* being used again.
*/
png_memcpy(tmp_jmp, png_ptr->jmpbuf, sizeof (jmp_buf));
error_fn = png_ptr->error_fn;
warning_fn = png_ptr->warning_fn;
error_ptr = png_ptr->error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
free_fn = png_ptr->free_fn;
#endif
png_memset(png_ptr, 0, sizeof (png_struct));
png_ptr->error_fn = error_fn;
png_ptr->warning_fn = warning_fn;
png_ptr->error_ptr = error_ptr;
#ifdef PNG_USER_MEM_SUPPORTED
png_ptr->free_fn = free_fn;
#endif
png_memcpy(png_ptr->jmpbuf, tmp_jmp, sizeof (jmp_buf));
}
void
png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
{
png_ptr->read_row_fn = read_row_fn;
}

View File

@@ -0,0 +1,151 @@
/* pngrio.c - functions for data input
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*
* This file provides a location for all input. Users who need
* special handling are expected to write a function that has the same
* arguments as this and performs a similar function, but that possibly
* has a different input method. Note that you shouldn't change this
* function, but rather write a replacement function and then make
* libpng use it at run time with png_set_read_fn(...).
*/
#define PNG_INTERNAL
#include "png.h"
/* Read the data from whatever input you are using. The default routine
reads from a file pointer. Note that this routine sometimes gets called
with very small lengths, so you should implement some kind of simple
buffering if you are using unbuffered reads. This should never be asked
to read more then 64K on a 16 bit machine. */
void
png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_debug1(4,"reading %d bytes\n", length);
if (png_ptr->read_data_fn != NULL)
(*(png_ptr->read_data_fn))(png_ptr, data, length);
else
png_error(png_ptr, "Call to NULL read function");
}
#if !defined(PNG_NO_STDIO)
/* This is the function that does the actual reading of data. If you are
not reading from a standard C stream, you should create a replacement
read_data function and use it at run time with png_set_read_fn(), rather
than changing the library. */
#ifndef USE_FAR_KEYWORD
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_size_t check;
/* fread() returns 0 on error, so it is OK to store this in a png_size_t
* instead of an int, which is what fread() actually returns.
*/
check = (png_size_t)fread(data, (png_size_t)1, length,
(FILE *)png_ptr->io_ptr);
if (check != length)
{
png_error(png_ptr, "Read Error");
}
}
#else
/* this is the model-independent version. Since the standard I/O library
can't handle far buffers in the medium and small models, we have to copy
the data.
*/
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
static void
png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
int check;
png_byte *n_data;
FILE *io_ptr;
/* Check if data really is near. If so, use usual code. */
n_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)n_data == data)
{
check = fread(n_data, 1, length, io_ptr);
}
else
{
png_byte buf[NEAR_BUF_SIZE];
png_size_t read, remaining, err;
check = 0;
remaining = length;
do
{
read = MIN(NEAR_BUF_SIZE, remaining);
err = fread(buf, (png_size_t)1, read, io_ptr);
png_memcpy(data, buf, read); /* copy far buffer to near buffer */
if(err != read)
break;
else
check += err;
data += read;
remaining -= read;
}
while (remaining != 0);
}
if ((png_uint_32)check != (png_uint_32)length)
{
png_error(png_ptr, "read Error");
}
}
#endif
#endif
/* This function allows the application to supply a new input function
for libpng if standard C streams aren't being used.
This function takes as its arguments:
png_ptr - pointer to a png input data structure
io_ptr - pointer to user supplied structure containing info about
the input functions. May be NULL.
read_data_fn - pointer to a new input function that takes as its
arguments a pointer to a png_struct, a pointer to
a location where input data can be stored, and a 32-bit
unsigned int that is the number of bytes to be read.
To exit and output any fatal error messages the new write
function should call png_error(png_ptr, "Error msg"). */
void
png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr read_data_fn)
{
png_ptr->io_ptr = io_ptr;
#if !defined(PNG_NO_STDIO)
if (read_data_fn != NULL)
png_ptr->read_data_fn = read_data_fn;
else
png_ptr->read_data_fn = png_default_read_data;
#else
png_ptr->read_data_fn = read_data_fn;
#endif
/* It is an error to write to a read device */
if (png_ptr->write_data_fn != NULL)
{
png_ptr->write_data_fn = NULL;
png_warning(png_ptr,
"It's an error to set both read_data_fn and write_data_fn in the ");
png_warning(png_ptr,
"same structure. Resetting write_data_fn to NULL.");
}
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
png_ptr->output_flush_fn = NULL;
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,380 @@
/* pngset.c - storage of image information into info struct
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*
* The functions here are used during reads to store data from the file
* into the info struct, and during writes to store application data
* into the info struct for writing into the file. This abstracts the
* info struct and allows us to change the structure in the future.
*/
#define PNG_INTERNAL
#include "png.h"
#if defined(PNG_READ_bKGD_SUPPORTED) || defined(PNG_WRITE_bKGD_SUPPORTED)
void
png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
{
png_debug1(1, "in %s storage function\n", "bKGD");
if (png_ptr == NULL || info_ptr == NULL)
return;
png_memcpy(&(info_ptr->background), background, sizeof(png_color_16));
info_ptr->valid |= PNG_INFO_bKGD;
}
#endif
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
void
png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
double white_x, double white_y, double red_x, double red_y,
double green_x, double green_y, double blue_x, double blue_y)
{
png_debug1(1, "in %s storage function\n", "cHRM");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->x_white = (float)white_x;
info_ptr->y_white = (float)white_y;
info_ptr->x_red = (float)red_x;
info_ptr->y_red = (float)red_y;
info_ptr->x_green = (float)green_x;
info_ptr->y_green = (float)green_y;
info_ptr->x_blue = (float)blue_x;
info_ptr->y_blue = (float)blue_y;
info_ptr->valid |= PNG_INFO_cHRM;
}
#endif
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
void
png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
{
png_debug1(1, "in %s storage function\n", "gAMA");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->gamma = (float)file_gamma;
info_ptr->valid |= PNG_INFO_gAMA;
}
#endif
#if defined(PNG_READ_hIST_SUPPORTED) || defined(PNG_WRITE_hIST_SUPPORTED)
void
png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
{
png_debug1(1, "in %s storage function\n", "hIST");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->hist = hist;
info_ptr->valid |= PNG_INFO_hIST;
}
#endif
void
png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
png_uint_32 width, png_uint_32 height, int bit_depth,
int color_type, int interlace_type, int compression_type,
int filter_type)
{
int rowbytes_per_pixel;
png_debug1(1, "in %s storage function\n", "IHDR");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->width = width;
info_ptr->height = height;
info_ptr->bit_depth = (png_byte)bit_depth;
info_ptr->color_type =(png_byte) color_type;
info_ptr->compression_type = (png_byte)compression_type;
info_ptr->filter_type = (png_byte)filter_type;
info_ptr->interlace_type = (png_byte)interlace_type;
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
info_ptr->channels = 1;
else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
info_ptr->channels = 3;
else
info_ptr->channels = 1;
if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
info_ptr->channels++;
info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
/* check for overflow */
rowbytes_per_pixel = (info_ptr->pixel_depth + 7) >> 3;
if (( width > (png_uint_32)2147483647L/rowbytes_per_pixel))
{
png_warning(png_ptr,
"Width too large to process image data; rowbytes will overflow.");
info_ptr->rowbytes = (png_size_t)0;
}
else
info_ptr->rowbytes = (info_ptr->width * info_ptr->pixel_depth + 7) >> 3;
}
#if defined(PNG_READ_oFFs_SUPPORTED) || defined(PNG_WRITE_oFFs_SUPPORTED)
void
png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 offset_x, png_uint_32 offset_y, int unit_type)
{
png_debug1(1, "in %s storage function\n", "oFFs");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->x_offset = offset_x;
info_ptr->y_offset = offset_y;
info_ptr->offset_unit_type = (png_byte)unit_type;
info_ptr->valid |= PNG_INFO_oFFs;
}
#endif
#if defined(PNG_READ_pCAL_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED)
void
png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
png_charp units, png_charpp params)
{
png_uint_32 length;
int i;
png_debug1(1, "in %s storage function\n", "pCAL");
if (png_ptr == NULL || info_ptr == NULL)
return;
length = png_strlen(purpose) + 1;
png_debug1(3, "allocating purpose for info (%d bytes)\n", length);
info_ptr->pcal_purpose = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
png_debug(3, "storing X0, X1, type, and nparams in info\n");
info_ptr->pcal_X0 = X0;
info_ptr->pcal_X1 = X1;
info_ptr->pcal_type = (png_byte)type;
info_ptr->pcal_nparams = (png_byte)nparams;
length = png_strlen(units) + 1;
png_debug1(3, "allocating units for info (%d bytes)\n", length);
info_ptr->pcal_units = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
info_ptr->pcal_params = (png_charpp)png_malloc(png_ptr,
(png_uint_32)((nparams + 1) * sizeof(png_charp)));
info_ptr->pcal_params[nparams] = NULL;
for (i = 0; i < nparams; i++)
{
length = png_strlen(params[i]) + 1;
png_debug2(3, "allocating parameter %d for info (%d bytes)\n", i, length);
info_ptr->pcal_params[i] = (png_charp)png_malloc(png_ptr, length);
png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
}
info_ptr->valid |= PNG_INFO_pCAL;
}
#endif
#if defined(PNG_READ_pHYs_SUPPORTED) || defined(PNG_WRITE_pHYs_SUPPORTED)
void
png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
png_uint_32 res_x, png_uint_32 res_y, int unit_type)
{
png_debug1(1, "in %s storage function\n", "pHYs");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->x_pixels_per_unit = res_x;
info_ptr->y_pixels_per_unit = res_y;
info_ptr->phys_unit_type = (png_byte)unit_type;
info_ptr->valid |= PNG_INFO_pHYs;
}
#endif
void
png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
png_colorp palette, int num_palette)
{
png_debug1(1, "in %s storage function\n", "PLTE");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->palette = palette;
info_ptr->num_palette = (png_uint_16)num_palette;
info_ptr->valid |= PNG_INFO_PLTE;
}
#if defined(PNG_READ_sBIT_SUPPORTED) || defined(PNG_WRITE_sBIT_SUPPORTED)
void
png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
png_color_8p sig_bit)
{
png_debug1(1, "in %s storage function\n", "sBIT");
if (png_ptr == NULL || info_ptr == NULL)
return;
png_memcpy(&(info_ptr->sig_bit), sig_bit, sizeof (png_color_8));
info_ptr->valid |= PNG_INFO_sBIT;
}
#endif
#if defined(PNG_READ_sRGB_SUPPORTED) || defined(PNG_WRITE_sRGB_SUPPORTED)
void
png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
{
png_debug1(1, "in %s storage function\n", "sRGB");
if (png_ptr == NULL || info_ptr == NULL)
return;
info_ptr->srgb_intent = (png_byte)intent;
info_ptr->valid |= PNG_INFO_sRGB;
}
void
png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
int intent)
{
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
float file_gamma;
#endif
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
#endif
png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
if (png_ptr == NULL || info_ptr == NULL)
return;
png_set_sRGB(png_ptr, info_ptr, intent);
#if defined(PNG_READ_gAMA_SUPPORTED) || defined(PNG_WRITE_gAMA_SUPPORTED)
file_gamma = (float).45;
png_set_gAMA(png_ptr, info_ptr, file_gamma);
#endif
#if defined(PNG_READ_cHRM_SUPPORTED) || defined(PNG_WRITE_cHRM_SUPPORTED)
white_x = (float).3127;
white_y = (float).3290;
red_x = (float).64;
red_y = (float).33;
green_x = (float).30;
green_y = (float).60;
blue_x = (float).15;
blue_y = (float).06;
png_set_cHRM(png_ptr, info_ptr,
white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
#endif
}
#endif
#if defined(PNG_READ_tEXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_WRITE_zTXt_SUPPORTED)
void
png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
int num_text)
{
int i;
png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
"text" : (png_const_charp)png_ptr->chunk_name));
if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
return;
/* Make sure we have enough space in the "text" array in info_struct
* to hold all of the incoming text_ptr objects.
*/
if (info_ptr->num_text + num_text > info_ptr->max_text)
{
if (info_ptr->text != NULL)
{
png_textp old_text;
int old_max;
old_max = info_ptr->max_text;
info_ptr->max_text = info_ptr->num_text + num_text + 8;
old_text = info_ptr->text;
info_ptr->text = (png_textp)png_malloc(png_ptr,
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
sizeof(png_text)));
png_free(png_ptr, old_text);
}
else
{
info_ptr->max_text = num_text + 8;
info_ptr->num_text = 0;
info_ptr->text = (png_textp)png_malloc(png_ptr,
(png_uint_32)(info_ptr->max_text * sizeof (png_text)));
}
png_debug1(3, "allocated %d entries for info_ptr->text\n",
info_ptr->max_text);
}
for (i = 0; i < num_text; i++)
{
png_textp textp = &(info_ptr->text[info_ptr->num_text]);
if (text_ptr[i].text == NULL)
text_ptr[i].text = (png_charp)"";
if (text_ptr[i].text[0] == '\0')
{
textp->text_length = 0;
textp->compression = PNG_TEXT_COMPRESSION_NONE;
}
else
{
textp->text_length = png_strlen(text_ptr[i].text);
textp->compression = text_ptr[i].compression;
}
textp->text = text_ptr[i].text;
textp->key = text_ptr[i].key;
info_ptr->num_text++;
png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
}
}
#endif
#if defined(PNG_READ_tIME_SUPPORTED) || defined(PNG_WRITE_tIME_SUPPORTED)
void
png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
{
png_debug1(1, "in %s storage function\n", "tIME");
if (png_ptr == NULL || info_ptr == NULL)
return;
png_memcpy(&(info_ptr->mod_time), mod_time, sizeof (png_time));
info_ptr->valid |= PNG_INFO_tIME;
}
#endif
#if defined(PNG_READ_tRNS_SUPPORTED) || defined(PNG_WRITE_tRNS_SUPPORTED)
void
png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
png_bytep trans, int num_trans, png_color_16p trans_values)
{
png_debug1(1, "in %s storage function\n", "tRNS");
if (png_ptr == NULL || info_ptr == NULL)
return;
if (trans != NULL)
{
info_ptr->trans = trans;
}
if (trans_values != NULL)
{
png_memcpy(&(info_ptr->trans_values), trans_values,
sizeof(png_color_16));
if (num_trans == 0)
num_trans = 1;
}
info_ptr->num_trans = (png_uint_16)num_trans;
info_ptr->valid |= PNG_INFO_tRNS;
}
#endif

View File

@@ -0,0 +1,554 @@
/* pngtrans.c - transforms the data in a row (used by both readers and writers)
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*/
#define PNG_INTERNAL
#include "png.h"
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* turn on bgr to rgb mapping */
void
png_set_bgr(png_structp png_ptr)
{
png_debug(1, "in png_set_bgr\n");
png_ptr->transformations |= PNG_BGR;
}
#endif
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
/* turn on 16 bit byte swapping */
void
png_set_swap(png_structp png_ptr)
{
png_debug(1, "in png_set_swap\n");
if (png_ptr->bit_depth == 16)
png_ptr->transformations |= PNG_SWAP_BYTES;
}
#endif
#if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
/* turn on pixel packing */
void
png_set_packing(png_structp png_ptr)
{
png_debug(1, "in png_set_packing\n");
if (png_ptr->bit_depth < 8)
{
png_ptr->transformations |= PNG_PACK;
png_ptr->usr_bit_depth = 8;
}
}
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
/* turn on packed pixel swapping */
void
png_set_packswap(png_structp png_ptr)
{
png_debug(1, "in png_set_packswap\n");
if (png_ptr->bit_depth < 8)
png_ptr->transformations |= PNG_PACKSWAP;
}
#endif
#if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
void
png_set_shift(png_structp png_ptr, png_color_8p true_bits)
{
png_debug(1, "in png_set_shift\n");
png_ptr->transformations |= PNG_SHIFT;
png_ptr->shift = *true_bits;
}
#endif
#if defined(PNG_READ_INTERLACING_SUPPORTED) || \
defined(PNG_WRITE_INTERLACING_SUPPORTED)
int
png_set_interlace_handling(png_structp png_ptr)
{
png_debug(1, "in png_set_interlace handling\n");
if (png_ptr->interlaced)
{
png_ptr->transformations |= PNG_INTERLACE;
return (7);
}
return (1);
}
#endif
#if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
/* Add a filler byte on read, or remove a filler or alpha byte on write.
* The filler type has changed in v0.95 to allow future 2-byte fillers
* for 48-bit input data, as well as to avoid problems with some compilers
* that don't like bytes as parameters.
*/
void
png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
{
png_debug(1, "in png_set_filler\n");
png_ptr->transformations |= PNG_FILLER;
png_ptr->filler = (png_byte)filler;
if (filler_loc == PNG_FILLER_AFTER)
png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
else
png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
}
#endif
#if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
void
png_set_swap_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_swap_alpha\n");
png_ptr->transformations |= PNG_SWAP_ALPHA;
}
#endif
#if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
void
png_set_invert_alpha(png_structp png_ptr)
{
png_debug(1, "in png_set_invert_alpha\n");
png_ptr->transformations |= PNG_INVERT_ALPHA;
}
#endif
#if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
void
png_set_invert_mono(png_structp png_ptr)
{
png_debug(1, "in png_set_invert_mono\n");
png_ptr->transformations |= PNG_INVERT_MONO;
}
/* invert monochrome grayscale data */
void
png_do_invert(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_invert\n");
if (row_info->bit_depth == 1 &&
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
#endif
row_info->color_type == PNG_COLOR_TYPE_GRAY)
{
png_bytep rp = row;
png_uint_32 i;
png_uint_32 istop = row_info->rowbytes;
for (i = 0; i < istop; i++)
{
*rp = (png_byte)(~(*rp));
rp++;
}
}
}
#endif
#if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
/* swaps byte order on 16 bit depth images */
void
png_do_swap(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_swap\n");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
#endif
row_info->bit_depth == 16)
{
png_bytep rp = row;
png_uint_32 i;
png_uint_32 istop= row_info->width * row_info->channels;
for (i = 0; i < istop; i++, rp += 2)
{
png_byte t = *rp;
*rp = *(rp + 1);
*(rp + 1) = t;
}
}
}
#endif
#if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
static png_byte onebppswaptable[256] = {
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
};
static png_byte twobppswaptable[256] = {
0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
};
static png_byte fourbppswaptable[256] = {
0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
};
/* swaps pixel packing order within bytes */
void
png_do_packswap(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_packswap\n");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
#endif
row_info->bit_depth < 8)
{
png_bytep rp, end, table;
end = row + row_info->rowbytes;
if (row_info->bit_depth == 1)
table = onebppswaptable;
else if (row_info->bit_depth == 2)
table = twobppswaptable;
else if (row_info->bit_depth == 4)
table = fourbppswaptable;
else
return;
for (rp = row; rp < end; rp++)
*rp = table[*rp];
}
}
#endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
#if defined(PNG_WRITE_FILLER_SUPPORTED) || \
defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
/* remove filler or alpha byte(s) */
void
png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
{
png_debug(1, "in png_do_strip_filler\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL)
#endif
{
/*
if (row_info->color_type == PNG_COLOR_TYPE_RGB ||
row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
*/
png_bytep sp=row;
png_bytep dp=row;
png_uint_32 row_width=row_info->width;
png_uint_32 i;
if (row_info->channels == 4)
{
if (row_info->bit_depth == 8)
{
/* This converts from RGBX or RGBA to RGB */
if (flags & PNG_FLAG_FILLER_AFTER)
{
dp+=3; sp+=4;
for (i = 1; i < row_width; i++)
{
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
sp++;
}
}
/* This converts from XRGB or ARGB to RGB */
else
{
for (i = 0; i < row_width; i++)
{
sp++;
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
}
}
row_info->pixel_depth = 24;
row_info->rowbytes = row_width * 3;
}
else /* if (row_info->bit_depth == 16) */
{
if (flags & PNG_FLAG_FILLER_AFTER)
{
/* This converts from RRGGBBXX or RRGGBBAA to RRGGBB */
sp += 8; dp += 6;
for (i = 1; i < row_width; i++)
{
/* This could be (although memcpy is probably slower):
png_memcpy(dp, sp, 6);
sp += 8;
dp += 6;
*/
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
sp += 2;
}
}
else
{
/* This converts from XXRRGGBB or AARRGGBB to RRGGBB */
for (i = 0; i < row_width; i++)
{
/* This could be (although memcpy is probably slower):
png_memcpy(dp, sp, 6);
sp += 8;
dp += 6;
*/
sp+=2;
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
*dp++ = *sp++;
}
}
row_info->pixel_depth = 48;
row_info->rowbytes = row_width * 6;
}
row_info->channels = 3;
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
}
/*
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY ||
row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
*/
else if (row_info->channels == 2)
{
if (row_info->bit_depth == 8)
{
/* This converts from GX or GA to G */
if (flags & PNG_FLAG_FILLER_AFTER)
{
for (i = 0; i < row_width; i++)
{
*dp++ = *sp++;
sp++;
}
}
/* This converts from XG or AG to G */
else
{
for (i = 0; i < row_width; i++)
{
sp++;
*dp++ = *sp++;
}
}
row_info->pixel_depth = 8;
row_info->rowbytes = row_width;
}
else /* if (row_info->bit_depth == 16) */
{
if (flags & PNG_FLAG_FILLER_AFTER)
{
/* This converts from GGXX or GGAA to GG */
sp += 4; dp += 2;
for (i = 1; i < row_width; i++)
{
*dp++ = *sp++;
*dp++ = *sp++;
sp += 2;
}
}
else
{
/* This converts from XXGG or AAGG to GG */
for (i = 0; i < row_width; i++)
{
sp += 2;
*dp++ = *sp++;
*dp++ = *sp++;
}
}
row_info->pixel_depth = 16;
row_info->rowbytes = row_width * 2;
}
row_info->channels = 1;
row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
}
}
}
#endif
#if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
/* swaps red and blue bytes within a pixel */
void
png_do_bgr(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_bgr\n");
if (
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
#endif
(row_info->color_type & PNG_COLOR_MASK_COLOR))
{
png_uint_32 row_width = row_info->width;
if (row_info->bit_depth == 8)
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
{
png_bytep rp;
png_uint_32 i;
for (i = 0, rp = row; i < row_width; i++, rp += 3)
{
png_byte save = *rp;
*rp = *(rp + 2);
*(rp + 2) = save;
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
png_bytep rp;
png_uint_32 i;
for (i = 0, rp = row; i < row_width; i++, rp += 4)
{
png_byte save = *rp;
*rp = *(rp + 2);
*(rp + 2) = save;
}
}
}
else if (row_info->bit_depth == 16)
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB)
{
png_bytep rp;
png_uint_32 i;
for (i = 0, rp = row; i < row_width; i++, rp += 6)
{
png_byte save = *rp;
*rp = *(rp + 4);
*(rp + 4) = save;
save = *(rp + 1);
*(rp + 1) = *(rp + 5);
*(rp + 5) = save;
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
png_bytep rp;
png_uint_32 i;
for (i = 0, rp = row; i < row_width; i++, rp += 8)
{
png_byte save = *rp;
*rp = *(rp + 4);
*(rp + 4) = save;
save = *(rp + 1);
*(rp + 1) = *(rp + 5);
*(rp + 5) = save;
}
}
}
}
}
#endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */

View File

@@ -0,0 +1,213 @@
/* pngwio.c - functions for data output
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*
* This file provides a location for all output. Users who need
* special handling are expected to write functions that have the same
* arguments as these and perform similar functions, but that possibly
* use different output methods. Note that you shouldn't change these
* functions, but rather write replacement functions and then change
* them at run time with png_set_write_fn(...).
*/
#define PNG_INTERNAL
#include "png.h"
/* Write the data to whatever output you are using. The default routine
writes to a file pointer. Note that this routine sometimes gets called
with very small lengths, so you should implement some kind of simple
buffering if you are using unbuffered writes. This should never be asked
to write more than 64K on a 16 bit machine. */
void
png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
if (png_ptr->write_data_fn != NULL )
(*(png_ptr->write_data_fn))(png_ptr, data, length);
else
png_error(png_ptr, "Call to NULL write function");
}
#if !defined(PNG_NO_STDIO)
/* This is the function that does the actual writing of data. If you are
not writing to a standard C stream, you should create a replacement
write_data function and use it at run time with png_set_write_fn(), rather
than changing the library. */
#ifndef USE_FAR_KEYWORD
static void
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_uint_32 check;
check = fwrite(data, 1, length, (FILE *)(png_ptr->io_ptr));
if (check != length)
{
png_error(png_ptr, "Write Error");
}
}
#else
/* this is the model-independent version. Since the standard I/O library
can't handle far buffers in the medium and small models, we have to copy
the data.
*/
#define NEAR_BUF_SIZE 1024
#define MIN(a,b) (a <= b ? a : b)
static void
png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
{
png_uint_32 check;
png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
FILE *io_ptr;
/* Check if data really is near. If so, use usual code. */
near_data = (png_byte *)CVT_PTR_NOCHECK(data);
io_ptr = (FILE *)CVT_PTR(png_ptr->io_ptr);
if ((png_bytep)near_data == data)
{
check = fwrite(near_data, 1, length, io_ptr);
}
else
{
png_byte buf[NEAR_BUF_SIZE];
png_size_t written, remaining, err;
check = 0;
remaining = length;
do
{
written = MIN(NEAR_BUF_SIZE, remaining);
png_memcpy(buf, data, written); /* copy far buffer to near buffer */
err = fwrite(buf, 1, written, io_ptr);
if (err != written)
break;
else
check += err;
data += written;
remaining -= written;
}
while (remaining != 0);
}
if (check != length)
{
png_error(png_ptr, "Write Error");
}
}
#endif
#endif
/* This function is called to output any data pending writing (normally
to disk). After png_flush is called, there should be no data pending
writing in any buffers. */
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
void
png_flush(png_structp png_ptr)
{
if (png_ptr->output_flush_fn != NULL)
(*(png_ptr->output_flush_fn))(png_ptr);
}
#if !defined(PNG_NO_STDIO)
static void
png_default_flush(png_structp png_ptr)
{
FILE *io_ptr;
io_ptr = (FILE *)CVT_PTR((png_ptr->io_ptr));
if (io_ptr != NULL)
fflush(io_ptr);
}
#endif
#endif
/* This function allows the application to supply new output functions for
libpng if standard C streams aren't being used.
This function takes as its arguments:
png_ptr - pointer to a png output data structure
io_ptr - pointer to user supplied structure containing info about
the output functions. May be NULL.
write_data_fn - pointer to a new output function that takes as its
arguments a pointer to a png_struct, a pointer to
data to be written, and a 32-bit unsigned int that is
the number of bytes to be written. The new write
function should call png_error(png_ptr, "Error msg")
to exit and output any fatal error messages.
flush_data_fn - pointer to a new flush function that takes as its
arguments a pointer to a png_struct. After a call to
the flush function, there should be no data in any buffers
or pending transmission. If the output method doesn't do
any buffering of ouput, a function prototype must still be
supplied although it doesn't have to do anything. If
PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile
time, output_flush_fn will be ignored, although it must be
supplied for compatibility. */
void
png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
{
png_ptr->io_ptr = io_ptr;
#if !defined(PNG_NO_STDIO)
if (write_data_fn != NULL)
png_ptr->write_data_fn = write_data_fn;
else
png_ptr->write_data_fn = png_default_write_data;
#else
png_ptr->write_data_fn = write_data_fn;
#endif
#if defined(PNG_WRITE_FLUSH_SUPPORTED)
#if !defined(PNG_NO_STDIO)
if (output_flush_fn != NULL)
png_ptr->output_flush_fn = output_flush_fn;
else
png_ptr->output_flush_fn = png_default_flush;
#else
png_ptr->output_flush_fn = output_flush_fn;
#endif
#endif /* PNG_WRITE_FLUSH_SUPPORTED */
/* It is an error to read while writing a png file */
if (png_ptr->read_data_fn != NULL)
{
png_ptr->read_data_fn = NULL;
png_warning(png_ptr,
"Attempted to set both read_data_fn and write_data_fn in");
png_warning(png_ptr,
"the same structure. Resetting read_data_fn to NULL.");
}
}
#if defined(USE_FAR_KEYWORD)
#if defined(_MSC_VER)
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
{
void *near_ptr;
void FAR *far_ptr;
FP_OFF(near_ptr) = FP_OFF(ptr);
far_ptr = (void FAR *)near_ptr;
if(check != 0)
if(FP_SEG(ptr) != FP_SEG(far_ptr))
png_error(png_ptr,"segment lost in conversion");
return(near_ptr);
}
# else
void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
{
void *near_ptr;
void FAR *far_ptr;
near_ptr = (void FAR *)ptr;
far_ptr = (void FAR *)near_ptr;
if(check != 0)
if(far_ptr != ptr)
png_error(png_ptr,"segment lost in conversion");
return(near_ptr);
}
# endif
# endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,497 @@
/* pngwtran.c - transforms the data in a row for PNG writers
*
* libpng 1.0.2 - June 14, 1998
* For conditions of distribution and use, see copyright notice in png.h
* Copyright (c) 1995, 1996 Guy Eric Schalnat, Group 42, Inc.
* Copyright (c) 1996, 1997 Andreas Dilger
* Copyright (c) 1998, Glenn Randers-Pehrson
*/
#define PNG_INTERNAL
#include "png.h"
/* Transform the data according to the user's wishes. The order of
* transformations is significant.
*/
void
png_do_write_transformations(png_structp png_ptr)
{
png_debug(1, "in png_do_write_transformations\n");
#if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
if (png_ptr->transformations & PNG_USER_TRANSFORM)
if(png_ptr->write_user_transform_fn != NULL)
(*(png_ptr->write_user_transform_fn)) /* user write transform function */
(png_ptr, /* png_ptr */
&(png_ptr->row_info), /* row_info: */
/* png_uint_32 width; width of row */
/* png_uint_32 rowbytes; number of bytes in row */
/* png_byte color_type; color type of pixels */
/* png_byte bit_depth; bit depth of samples */
/* png_byte channels; number of channels (1-4) */
/* png_byte pixel_depth; bits per pixel (depth*channels) */
png_ptr->row_buf + 1); /* start of pixel data for row */
#endif
#if defined(PNG_WRITE_FILLER_SUPPORTED)
if (png_ptr->transformations & PNG_FILLER)
png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
png_ptr->flags);
#endif
#if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
if (png_ptr->transformations & PNG_PACKSWAP)
png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_PACK_SUPPORTED)
if (png_ptr->transformations & PNG_PACK)
png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
(png_uint_32)png_ptr->bit_depth);
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
if (png_ptr->transformations & PNG_SHIFT)
png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
&(png_ptr->shift));
#endif
#if defined(PNG_WRITE_SWAP_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_BYTES)
png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_ALPHA)
png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
if (png_ptr->transformations & PNG_SWAP_ALPHA)
png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_BGR_SUPPORTED)
if (png_ptr->transformations & PNG_BGR)
png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
#if defined(PNG_WRITE_INVERT_SUPPORTED)
if (png_ptr->transformations & PNG_INVERT_MONO)
png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
#endif
}
#if defined(PNG_WRITE_PACK_SUPPORTED)
/* Pack pixels into bytes. Pass the true bit depth in bit_depth. The
* row_info bit depth should be 8 (one pixel per byte). The channels
* should be 1 (this only happens on grayscale and paletted images).
*/
void
png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
{
png_debug(1, "in png_do_pack\n");
if (row_info->bit_depth == 8 &&
#if defined(PNG_USELESS_TESTS_SUPPORTED)
row != NULL && row_info != NULL &&
#endif
row_info->channels == 1)
{
switch ((int)bit_depth)
{
case 1:
{
png_bytep sp, dp;
int mask, v;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
mask = 0x80;
v = 0;
for (i = 0; i < row_width; i++)
{
if (*sp != 0)
v |= mask;
sp++;
if (mask > 1)
mask >>= 1;
else
{
mask = 0x80;
*dp = (png_byte)v;
dp++;
v = 0;
}
}
if (mask != 0x80)
*dp = (png_byte)v;
break;
}
case 2:
{
png_bytep sp, dp;
int shift, v;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
shift = 6;
v = 0;
for (i = 0; i < row_width; i++)
{
png_byte value;
value = (png_byte)(*sp & 0x3);
v |= (value << shift);
if (shift == 0)
{
shift = 6;
*dp = (png_byte)v;
dp++;
v = 0;
}
else
shift -= 2;
sp++;
}
if (shift != 6)
*dp = (png_byte)v;
break;
}
case 4:
{
png_bytep sp, dp;
int shift, v;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
sp = row;
dp = row;
shift = 4;
v = 0;
for (i = 0; i < row_width; i++)
{
png_byte value;
value = (png_byte)(*sp & 0xf);
v |= (value << shift);
if (shift == 0)
{
shift = 4;
*dp = (png_byte)v;
dp++;
v = 0;
}
else
shift -= 4;
sp++;
}
if (shift != 4)
*dp = (png_byte)v;
break;
}
}
row_info->bit_depth = (png_byte)bit_depth;
row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
row_info->rowbytes =
((row_info->width * row_info->pixel_depth + 7) >> 3);
}
}
#endif
#if defined(PNG_WRITE_SHIFT_SUPPORTED)
/* Shift pixel values to take advantage of whole range. Pass the
* true number of bits in bit_depth. The row should be packed
* according to row_info->bit_depth. Thus, if you had a row of
* bit depth 4, but the pixels only had values from 0 to 7, you
* would pass 3 as bit_depth, and this routine would translate the
* data to 0 to 15.
*/
void
png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
{
png_debug(1, "in png_do_shift\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL &&
#else
if (
#endif
row_info->color_type != PNG_COLOR_TYPE_PALETTE)
{
int shift_start[4], shift_dec[4];
int channels = 0;
if (row_info->color_type & PNG_COLOR_MASK_COLOR)
{
shift_start[channels] = row_info->bit_depth - bit_depth->red;
shift_dec[channels] = bit_depth->red;
channels++;
shift_start[channels] = row_info->bit_depth - bit_depth->green;
shift_dec[channels] = bit_depth->green;
channels++;
shift_start[channels] = row_info->bit_depth - bit_depth->blue;
shift_dec[channels] = bit_depth->blue;
channels++;
}
else
{
shift_start[channels] = row_info->bit_depth - bit_depth->gray;
shift_dec[channels] = bit_depth->gray;
channels++;
}
if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
{
shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
shift_dec[channels] = bit_depth->alpha;
channels++;
}
/* with low row depths, could only be grayscale, so one channel */
if (row_info->bit_depth < 8)
{
png_bytep bp = row;
png_uint_32 i;
png_byte mask;
png_uint_32 row_bytes = row_info->rowbytes;
if (bit_depth->gray == 1 && row_info->bit_depth == 2)
mask = 0x55;
else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
mask = 0x11;
else
mask = 0xff;
for (i = 0; i < row_bytes; i++, bp++)
{
png_uint_16 v;
int j;
v = *bp;
*bp = 0;
for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
{
if (j > 0)
*bp |= (png_byte)((v << j) & 0xff);
else
*bp |= (png_byte)((v >> (-j)) & mask);
}
}
}
else if (row_info->bit_depth == 8)
{
png_bytep bp = row;
png_uint_32 i;
png_uint_32 istop = channels * row_info->width;
for (i = 0; i < istop; i++, bp++)
{
png_uint_16 v;
int j;
int c = (int)(i%channels);
v = *bp;
*bp = 0;
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
{
if (j > 0)
*bp |= (png_byte)((v << j) & 0xff);
else
*bp |= (png_byte)((v >> (-j)) & 0xff);
}
}
}
else
{
png_bytep bp;
png_uint_32 i;
png_uint_32 istop = channels * row_info->width;
for (bp = row, i = 0; i < istop; i++)
{
int c = (int)(i%channels);
png_uint_16 value, v;
int j;
v = ((png_uint_16)(*bp) << 8) + *(bp + 1);
value = 0;
for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
{
if (j > 0)
value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
else
value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
}
*bp++ = (png_byte)(value >> 8);
*bp++ = (png_byte)(value & 0xff);
}
}
}
}
#endif
#if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
void
png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_swap_alpha\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL)
#endif
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
/* This converts from ARGB to RGBA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = save;
}
}
/* This converts from AARRGGBB to RRGGBBAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save[2];
save[0] = *(sp++);
save[1] = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = save[0];
*(dp++) = save[1];
}
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* This converts from AG to GA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save = *(sp++);
*(dp++) = *(sp++);
*(dp++) = save;
}
}
/* This converts from AAGG to GGAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
png_byte save[2];
save[0] = *(sp++);
save[1] = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = save[0];
*(dp++) = save[1];
}
}
}
}
}
#endif
#if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
void
png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
{
png_debug(1, "in png_do_write_invert_alpha\n");
#if defined(PNG_USELESS_TESTS_SUPPORTED)
if (row != NULL && row_info != NULL)
#endif
{
if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
{
/* This inverts the alpha channel in RGBA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
}
}
/* This inverts the alpha channel in RRGGBBAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
*(dp++) = 255 - *(sp++);
}
}
}
else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
{
/* This inverts the alpha channel in GA */
if (row_info->bit_depth == 8)
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
}
}
/* This inverts the alpha channel in GGAA */
else
{
png_bytep sp, dp;
png_uint_32 i;
png_uint_32 row_width = row_info->width;
for (i = 0, sp = dp = row; i < row_width; i++)
{
*(dp++) = *(sp++);
*(dp++) = *(sp++);
*(dp++) = 255 - *(sp++);
*(dp++) = 255 - *(sp++);
}
}
}
}
}
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,54 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = nspng
IS_COMPONENT = 1
LOCAL_INCLUDES = -I$(srcdir)
EXTRA_LIBS =
CPPSRCS = \
ipng.cpp \
png_png.cpp \
nsPNGDecoder.cpp \
nsPNGCallback.cpp \
dllcompat.cpp \
$(NULL)
CPPSRCS += \
$(NULL)
REQUIRES += util png zlib xpcom img
EXTRA_LIBS += $(NSPR_LIBS)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,442 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* 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.
*/
/* This file has func's from
xpcompat that are needed by
the local dll. So far,
1> Mac stuff.
2> NET_BACat
*/
#include "prtypes.h"
#include "prlog.h"
#include "prmem.h"
#include "xp_mcom.h"
PR_BEGIN_EXTERN_C
int MK_UNABLE_TO_LOCATE_FILE = -1;
int MK_OUT_OF_MEMORY = -2;
int XP_MSG_IMAGE_PIXELS = -7;
int XP_MSG_IMAGE_NOT_FOUND = -8;
int XP_MSG_XBIT_COLOR = -9;
int XP_MSG_1BIT_MONO = -10;
int XP_MSG_XBIT_GREYSCALE = -11;
int XP_MSG_XBIT_RGB = -12;
int XP_MSG_DECODED_SIZE = -13;
int XP_MSG_WIDTH_HEIGHT = -14;
int XP_MSG_SCALED_FROM = -15;
int XP_MSG_IMAGE_DIM = -16;
int XP_MSG_COLOR = -17;
int XP_MSG_NB_COLORS = -18;
int XP_MSG_NONE = -19;
int XP_MSG_COLORMAP = -20;
int XP_MSG_BCKDRP_VISIBLE = -21;
int XP_MSG_SOLID_BKGND = -22;
int XP_MSG_JUST_NO = -23;
int XP_MSG_TRANSPARENCY = -24;
int XP_MSG_COMMENT = -25;
int XP_MSG_UNKNOWN = -26;
int XP_MSG_COMPRESS_REMOVE = -27;
PR_END_EXTERN_C
/* binary block Allocate and Concatenate
*
* destination_length is the length of the existing block
* source_length is the length of the block being added to the
* destination block
*/
char *
NET_BACat (char **destination,
size_t destination_length,
const char *source,
size_t source_length)
{
if (source)
{
if (*destination)
{
*destination = (char *) PR_REALLOC (*destination, destination_length + source_length);
if (*destination == NULL)
return(NULL);
XP_MEMMOVE (*destination + destination_length, source, source_length);
}
else
{
*destination = (char *) PR_MALLOC (source_length);
if (*destination == NULL)
return(NULL);
XP_MEMCPY(*destination, source, source_length);
}
}
return *destination;
}
#if defined(XP_MAC)
/* prototypes for local routines */
static void shortsort(char *lo, char *hi, unsigned width,
int ( *comp)(const void *, const void *));
static void swap(char *p, char *q, unsigned int width);
/* this parameter defines the cutoff between using quick sort and
insertion sort for arrays; arrays with lengths shorter or equal to the
below value use insertion sort */
#define CUTOFF 8 /* testing shows that this is good value */
/***
*XP_QSORT(base, num, wid, comp) - quicksort function for sorting arrays
*
*Purpose:
* quicksort the array of elements
* side effects: sorts in place
*
*Entry:
* char *base = pointer to base of array
* unsigned num = number of elements in the array
* unsigned width = width in bytes of each array element
* int (*comp)() = pointer to function returning analog of strcmp for
* strings, but supplied by user for comparing the array elements.
* it accepts 2 pointers to elements and returns neg if 1<2, 0 if
* 1=2, pos if 1>2.
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
/* sort the array between lo and hi (inclusive) */
void XP_QSORT (
void *base,
size_t num,
size_t width,
int ( *comp)(const void *, const void *)
)
{
char *lo, *hi; /* ends of sub-array currently sorting */
char *mid; /* points to middle of subarray */
char *loguy, *higuy; /* traveling pointers for partition step */
unsigned size; /* size of the sub-array */
char *lostk[30], *histk[30];
int stkptr; /* stack for saving sub-array to be processed */
/* Note: the number of stack entries required is no more than
1 + log2(size), so 30 is sufficient for any array */
if (num < 2 || width == 0)
return; /* nothing to do */
stkptr = 0; /* initialize stack */
lo = (char*)base;
hi = (char *)base + width * (num-1); /* initialize limits */
/* this entry point is for pseudo-recursion calling: setting
lo and hi and jumping to here is like recursion, but stkptr is
prserved, locals aren't, so we preserve stuff on the stack */
recurse:
size = (hi - lo) / width + 1; /* number of el's to sort */
/* below a certain size, it is faster to use a O(n^2) sorting method */
if (size <= CUTOFF) {
shortsort(lo, hi, width, comp);
}
else {
/* First we pick a partititioning element. The efficiency of the
algorithm demands that we find one that is approximately the
median of the values, but also that we select one fast. Using
the first one produces bad performace if the array is already
sorted, so we use the middle one, which would require a very
wierdly arranged array for worst case performance. Testing shows
that a median-of-three algorithm does not, in general, increase
performance. */
mid = lo + (size / 2) * width; /* find middle element */
swap(mid, lo, width); /* swap it to beginning of array */
/* We now wish to partition the array into three pieces, one
consisiting of elements <= partition element, one of elements
equal to the parition element, and one of element >= to it. This
is done below; comments indicate conditions established at every
step. */
loguy = lo;
higuy = hi + width;
/* Note that higuy decreases and loguy increases on every iteration,
so loop must terminate. */
for (;;) {
/* lo <= loguy < hi, lo < higuy <= hi + 1,
A[i] <= A[lo] for lo <= i <= loguy,
A[i] >= A[lo] for higuy <= i <= hi */
do {
loguy += width;
} while (loguy <= hi && comp(loguy, lo) <= 0);
/* lo < loguy <= hi+1, A[i] <= A[lo] for lo <= i < loguy,
either loguy > hi or A[loguy] > A[lo] */
do {
higuy -= width;
} while (higuy > lo && comp(higuy, lo) >= 0);
/* lo-1 <= higuy <= hi, A[i] >= A[lo] for higuy < i <= hi,
either higuy <= lo or A[higuy] < A[lo] */
if (higuy < loguy)
break;
/* if loguy > hi or higuy <= lo, then we would have exited, so
A[loguy] > A[lo], A[higuy] < A[lo],
loguy < hi, highy > lo */
swap(loguy, higuy, width);
/* A[loguy] < A[lo], A[higuy] > A[lo]; so condition at top
of loop is re-established */
}
/* A[i] >= A[lo] for higuy < i <= hi,
A[i] <= A[lo] for lo <= i < loguy,
higuy < loguy, lo <= higuy <= hi
implying:
A[i] >= A[lo] for loguy <= i <= hi,
A[i] <= A[lo] for lo <= i <= higuy,
A[i] = A[lo] for higuy < i < loguy */
swap(lo, higuy, width); /* put partition element in place */
/* OK, now we have the following:
A[i] >= A[higuy] for loguy <= i <= hi,
A[i] <= A[higuy] for lo <= i < higuy
A[i] = A[lo] for higuy <= i < loguy */
/* We've finished the partition, now we want to sort the subarrays
[lo, higuy-1] and [loguy, hi].
We do the smaller one first to minimize stack usage.
We only sort arrays of length 2 or more.*/
if ( higuy - 1 - lo >= hi - loguy ) {
if (lo + width < higuy) {
lostk[stkptr] = lo;
histk[stkptr] = higuy - width;
++stkptr;
} /* save big recursion for later */
if (loguy < hi) {
lo = loguy;
goto recurse; /* do small recursion */
}
}
else {
if (loguy < hi) {
lostk[stkptr] = loguy;
histk[stkptr] = hi;
++stkptr; /* save big recursion for later */
}
if (lo + width < higuy) {
hi = higuy - width;
goto recurse; /* do small recursion */
}
}
}
/* We have sorted the array, except for any pending sorts on the stack.
Check if there are any, and do them. */
--stkptr;
if (stkptr >= 0) {
lo = lostk[stkptr];
hi = histk[stkptr];
goto recurse; /* pop subarray from stack */
}
else
return; /* all subarrays done */
}
/***
*shortsort(hi, lo, width, comp) - insertion sort for sorting short arrays
*
*Purpose:
* sorts the sub-array of elements between lo and hi (inclusive)
* side effects: sorts in place
* assumes that lo < hi
*
*Entry:
* char *lo = pointer to low element to sort
* char *hi = pointer to high element to sort
* unsigned width = width in bytes of each array element
* int (*comp)() = pointer to function returning analog of strcmp for
* strings, but supplied by user for comparing the array elements.
* it accepts 2 pointers to elements and returns neg if 1<2, 0 if
* 1=2, pos if 1>2.
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
static void shortsort (
char *lo,
char *hi,
unsigned width,
int ( *comp)(const void *, const void *)
)
{
char *p, *max;
/* Note: in assertions below, i and j are alway inside original bound of
array to sort. */
while (hi > lo) {
/* A[i] <= A[j] for i <= j, j > hi */
max = lo;
for (p = lo+width; p <= hi; p += width) {
/* A[i] <= A[max] for lo <= i < p */
if (comp(p, max) > 0) {
max = p;
}
/* A[i] <= A[max] for lo <= i <= p */
}
/* A[i] <= A[max] for lo <= i <= hi */
swap(max, hi, width);
/* A[i] <= A[hi] for i <= hi, so A[i] <= A[j] for i <= j, j >= hi */
hi -= width;
/* A[i] <= A[j] for i <= j, j > hi, loop top condition established */
}
/* A[i] <= A[j] for i <= j, j > lo, which implies A[i] <= A[j] for i < j,
so array is sorted */
}
/***
*swap(a, b, width) - swap two elements
*
*Purpose:
* swaps the two array elements of size width
*
*Entry:
* char *a, *b = pointer to two elements to swap
* unsigned width = width in bytes of each array element
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
static void swap (
char *a,
char *b,
unsigned width
)
{
char tmp;
if ( a != b )
/* Do the swap one character at a time to avoid potential alignment
problems. */
while ( width-- ) {
tmp = *a;
*a++ = *b;
*b++ = tmp;
}
}
#endif /* XP_MAC */
#ifdef XP_MAC
#include <OSUtils.h>
static void MyReadLocation(MachineLocation * loc)
{
static MachineLocation storedLoc; // InsideMac, OSUtilities, page 4-20
static Boolean didReadLocation = FALSE;
if (!didReadLocation)
{
ReadLocation(&storedLoc);
didReadLocation = TRUE;
}
*loc = storedLoc;
}
// current local time = GMTDelta() + GMT
// GMT = local time - GMTDelta()
static long GMTDelta()
{
MachineLocation loc;
long gmtDelta;
MyReadLocation(&loc);
gmtDelta = loc.u.gmtDelta & 0x00FFFFFF;
if ((gmtDelta & 0x00800000) != 0)
gmtDelta |= 0xFF000000;
return gmtDelta;
}
// This routine simulates stdclib time(), time in seconds since 1.1.1970
// The time is in GMT
time_t GetTimeMac()
{
unsigned long maclocal;
// Get Mac local time
GetDateTime(&maclocal);
// Get Mac GMT
maclocal -= GMTDelta();
// return unix GMT
return (maclocal - UNIXMINUSMACTIME);
}
// Returns the GMT times
time_t Mactime(time_t *timer)
{
time_t t = GetTimeMac();
if (timer != NULL)
*timer = t;
return t;
}
#endif /* XP_MAC */

View File

@@ -0,0 +1,291 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "png.h"
#include "if_struct.h"
#include "ipng.h"
#include "dllcompat.h"
#include "pngdec.h"
#include "nsIImgDecoder.h"
#include "nsPNGDecoder.h"
#include "nsPNGCallback.h"
#include "ilISystemServices.h"
#define OK 1
#define MINIMUM_DELAY_TIME 10
void row_callback( png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass /*, il_container *ic*/);
extern void end_callback(png_structp png_ptr, png_infop info);
extern void info_callback(png_structp png_ptr, png_infop info);
extern void il_create_alpha_mask( il_container *, int, int, int );
#if defined(PNG_LIBPNG_VER) && (PNG_LIBPNG_VER < 100)
extern png_structp png_create_read_struct(png_charp user_png_ver, png_voidp, png_error_ptr, png_error_ptr);
extern png_infop png_create_info_struct(png_structp png_ptr);
extern void png_destroy_read_struct(png_structpp, png_infopp, png_infopp);
extern void png_set_progressive_read_fn(png_structp, png_voidp, png_progressive_info_ptr, png_progressive_row_ptr, png_progressive_end_ptr);
extern void png_process_data(png_structp, png_infop, png_bytep, png_size_t);
#endif
int
il_png_init(il_container *ic)
{
ipng_struct *ipngs;
NI_ColorSpace *src_color_space = ic->src_header->color_space;
ipngs = PR_NEWZAP(ipng_struct);
if (ipngs)
{
ic->ds = ipngs;
ipngs->state = PNG_INIT;
ipngs->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;
return (ipngs != 0);
}
/* 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_ptr;
png_structp png_ptr;
png_infop info_ptr;
/*------*/
ipng_ptr = (ipng_structp)ic->ds;
if(ipng_ptr->state == PNG_INIT ){
png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL );
ipng_ptr->pngs_p = png_ptr;
/* Allocate/initialize the memory for image information. REQUIRED. */
info_ptr = png_create_info_struct(png_ptr);
ipng_ptr->info_p = info_ptr;
if (info_ptr == NULL){
png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
return !OK;
}
png_set_progressive_read_fn(png_ptr, (void *)buf,
info_callback, row_callback, end_callback);
}
else{
png_ptr = ipng_ptr->pngs_p;
info_ptr = ipng_ptr->info_p;
}
/* note addition of ic to png structure.... */
png_ptr->io_ptr = ic;
png_process_data( png_ptr, info_ptr, (unsigned char *)buf, len );
ipng_ptr->state = PNG_CONTINUE;
return OK;
}
void
png_set_dims( il_container *ic, png_structp png_ptr)
{
int status;
NI_PixmapHeader *img_hdr = &ic->image->header;
NI_PixmapHeader *src_hdr = ic->src_header;
src_hdr->width = img_hdr->width = png_ptr->width;
src_hdr->height = img_hdr->height = png_ptr->height;
if((png_ptr->channels > 3 )||(png_ptr->trans)){
il_create_alpha_mask( (il_container *)png_ptr->io_ptr, 0, png_ptr->width, png_ptr->height);
ic->image->header.is_interleaved_alpha = TRUE;
//il_init_image_transparent_pixel(ic);
ic->imgdcb->ImgDCBInitTransparentPixel();
}
//status = il_size(ic);
status = ic->imgdcb->ImgDCBImageSize();
/*Note: all png's are decoded to RGB or RGBa and
converted by imglib to appropriate pixdepth*/
ic->imgdcb->ImgDCBSetupColorspaceConverter();
return;
}
void
il_png_init_transparency(png_structp png_ptr, il_container *ic, int index)
{
IL_IRGB *src_trans_pixel /*= ic->src_header->transparent_pixel*/;
IL_IRGB *img_trans_pixel;
if (ic->src_header) {
ic->src_header->transparent_pixel = PR_NEWZAP(IL_IRGB);
}
src_trans_pixel = ic->src_header->transparent_pixel;
/* Initialize the destination image's transparent pixel. */
//il_init_image_transparent_pixel(ic);
ic->imgdcb->ImgDCBInitTransparentPixel();
/* Set the source image's transparent pixel color to be the preferred
transparency color of the destination image. */
img_trans_pixel = ic->image->header.transparent_pixel;
src_trans_pixel->red = png_ptr->trans_values.red;
src_trans_pixel->green = png_ptr->trans_values.green;
src_trans_pixel->blue = png_ptr->trans_values.blue;
/*
src_trans_pixel->red = img_trans_pixel->red;
src_trans_pixel->green = img_trans_pixel->green;
src_trans_pixel->blue = img_trans_pixel->blue;
*/
/* Set the source image's transparent pixel index. Do this even if the source
image's transparent pixel has previously been set, since the index can vary
from frame to frame in an animated png. */
src_trans_pixel->index = index;
return;
}
static void
il_png_destroy_transparency(il_container *ic)
{
NI_PixmapHeader *src_header = ic->src_header;
if (src_header->transparent_pixel) {
/* Destroy the source image's transparent pixel. */
PR_FREEIF(src_header->transparent_pixel);
src_header->transparent_pixel = NULL;
/* Destroy the destination image's transparent pixel. */
//il_destroy_image_transparent_pixel(ic);
ic->imgdcb->ImgDCBDestroyTransparentPixel();
}
}
void
png_delay_time_callback(void *closure)
{
ipng_struct *ipng_ptr = (ipng_struct *)closure;
PR_ASSERT(ipng_ptr->state == PNG_DELAY);
ipng_ptr->delay_time = NULL;
if (ipng_ptr->ic->state == IC_ABORT_PENDING)
return;
ipng_ptr->delay_time = 0; /* Reset for next image */
}
void
il_png_complete(il_container *ic)
{
ipng_structp ipng_ptr;
ipng_ptr = (ipng_structp)ic->ds;
il_png_abort(ic);
/* notify observers that the current frame has completed. */
//il_frame_complete_notify(ic);
ic->imgdcb->ImgDCBHaveImageFrame();
/* An image can specify a delay time before which to display
subsequent images. Block until the appointed time. */
if(ipng_ptr->delay_time < MINIMUM_DELAY_TIME )
ipng_ptr->delay_time = MINIMUM_DELAY_TIME ;
if (ipng_ptr->delay_time){
ipng_ptr->delay_timeout =
ic->imgdcb->ImgDCBSetTimeout(png_delay_time_callback, ipng_ptr, ipng_ptr->delay_time);
/* Essentially, tell the decoder state machine to wait
forever. The delay_time callback routine will wake up the
state machine and force it to decode the next image. */
ipng_ptr->state = PNG_DELAY;
} else {
ipng_ptr->state = PNG_INIT;
}
return;
}
void il_png_abort(il_container *ic)
{
/* il_abort( ic ); */
return;
}
/*-----------------------------------------------------------------------------
* Put alpha channel in a separate 8 bit input
*---------------------------------------------------------------------------*/
void
il_get_alpha_channel(
uint8 *src, /* RGBa, input data */
int src_len, /* Number of pixels in source row */
uint8 *maskp, /* Output pointer, left-justified bitmask */
int mask_len /* Number of pixels in output row */
)
{
if (!src || !mask_len)
return;
if (src_len == mask_len)
{
int i = src_len;
while (i--) {
*maskp++ = *(src + 3);
src += 4;
}
}
}

View File

@@ -0,0 +1,45 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* 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;
void *delay_timeout;
uint32 delay_time;
png_struct *pngs_p;
png_infop info_p;
/* One scanline's worth of post-processed sample data */
il_container *ic;
} ipng_struct, *ipng_structp;

View File

@@ -0,0 +1,104 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
#
#------------------------------------------------------------------------
#
# Makefile to build the IMGLIB LIB
#
#------------------------------------------------------------------------
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
LIBRARY_NAME = nspng
#
# 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\plc3.lib \
$(DIST)\lib\util.lib \
$(DIST)\lib\png.lib \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\zip3250.lib \
!ifdef NU_CACHE
$(DIST)\lib\cache.lib \
!endif
$(NULL)
MISCDEP=$(LLIBS)
LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
LIBRARY_SUFFIX = $(MOZ_BITS)$(VERSION_NUMBER)
MAKE_OBJ_TYPE=DLL
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
DLLNAME=nspng$(MOZ_BITS)$(VERSION_NUMBER)
DLL1NAME=nspng$(MOZ_BITS)$(VERSION_NUMBER)
PDBFILE=$(DLLNAME).pdb
MAPFILE=$(DLLNAME).map
DEFFILE=nspng.def
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
DLL=.\$(OBJDIR)\$(DLLNAME).dll
MAPFILE= $(DLLNAME).map
MODULE=img
DEPTH=..\..\..
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
REQUIRES=nspr xpcom util raptor png zlib
CPPSRCS= dllcompat.cpp nsPNGDecoder.cpp nsPNGCallback.cpp ipng.cpp png_png.cpp
CPP_OBJS=.\$(OBJDIR)\nsPNGDecoder.obj .\$(OBJ)\nsPNGCallback.obj .\$(OBJDIR)\dllcompat.obj \
.\$(OBJDIR)\ipng.obj .\$(OBJDIR)\png_png.obj
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib

View File

@@ -0,0 +1,58 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsPNGDecoder.cpp --- interface to png decoder
*/
#include "nsPNGCallback.h"
/* callbks: */
/*-------------class----------*/
NS_IMETHODIMP PNGCallbk::AddRef()
{
NS_INIT_REFCNT();
return NS_OK;
}
NS_IMETHODIMP PNGCallbk::Release()
{
return NS_OK;
}
NS_IMETHODIMP PNGCallbk::QueryInterface(const nsIID& aIID, void** aResult)
{
if (NULL == aResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kImgDCallbkIID)) {
*aResult = (void*) this;
NS_INIT_REFCNT();
return NS_OK;
}
return NS_NOINTERFACE;
}
/*-----------------------------*/

View File

@@ -0,0 +1,56 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsPNGDecoder.cpp --- interface to png decoder
*/
#ifndef _nsPNGCallbk_h
#define _nsPNGCallbk_h
#include "nsIImgDecoder.h"
#include "nsPNGDecoder.h"
/* 2b0c6b90-d8b1-11d2-802c-0060088f91a3 */
#define NS_PNGCALLBK_CID \
{ 0x2b0c6b90, 0xd8b1, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/* 5cb47c60-d8b1-11d2-802c-0060088f91a3 */
#define NS_PNGCALLBK_IID \
{ 0x5cb47c60, 0xd8b1, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
class PNGCallbk : public nsIImgDCallbk {
public:
NS_DECL_ISUPPORTS
il_container *GetContainer() {return mContainer;};
il_container *SetContainer(il_container *ic) {mContainer=ic; return ic;};
PNGCallbk(il_container *aContainer){mContainer=aContainer;};
~PNGCallbk();
private:
il_container* mContainer;
};
#endif

View File

@@ -0,0 +1,306 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsPNGDecoder.cpp --- interface to png decoder
*/
#include "if_struct.h"
#include "prmem.h"
#include "merrors.h"
#include "dllcompat.h"
#include "pngdec.h"
#include "nsPNGDecoder.h"
#include "nsImgDecCID.h"
#include "nsIImgDecoder.h" /* interface class */
#include "nsImgDecoder.h" /* factory */
#include "nscore.h"
/*--- needed for autoregistry ---*/
#include "nsIComponentManager.h"
#include "nsIServiceManager.h"
#include "nsCOMPtr.h"
PR_BEGIN_EXTERN_C
extern int MK_OUT_OF_MEMORY;
PR_END_EXTERN_C
/*-----------class----------------*/
class PNGDecoder : public nsIImgDecoder
{
public:
PNGDecoder(il_container* aContainer);
~PNGDecoder();
NS_DECL_ISUPPORTS
/* stream */
NS_IMETHOD ImgDInit();
NS_IMETHOD ImgDWriteReady();
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len);
NS_IMETHOD ImgDComplete();
NS_IMETHOD ImgDAbort();
il_container *SetContainer(il_container *ic){mContainer = ic; return ic;}
il_container *GetContainer() {return mContainer;}
private:
il_container* mContainer;
};
/*-------------------------------------------------*/
PNGDecoder::PNGDecoder(il_container* aContainer)
{
NS_INIT_REFCNT();
mContainer = aContainer;
};
PNGDecoder::~PNGDecoder(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
};
NS_IMETHODIMP
PNGDecoder::QueryInterface(const nsIID& aIID, void** aInstPtr)
{
if (NULL == aInstPtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kPNGDecoderIID) ||
aIID.Equals(kImgDecoderIID) ||
aIID.Equals(kISupportsIID)) {
*aInstPtr = (void*) this;
NS_INIT_REFCNT();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMETHODIMP
PNGDecoder::AddRef()
{
NS_INIT_REFCNT();
return NS_OK;
}
NS_IMETHODIMP
PNGDecoder::Release()
{
return NS_OK;
}
/*-----------class----------------*/
class nsPNGDecFactory : public nsIFactory
{
public:
NS_DECL_ISUPPORTS
nsPNGDecFactory(const nsCID &aClass);
~nsPNGDecFactory();
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
private:
nsCID mClassID;
il_container *mContainer;
};
/*-----------------------------------------*/
nsPNGDecFactory* gFactory = NULL;
NS_IMPL_ISUPPORTS(nsPNGDecFactory, kIFactoryIID);
nsPNGDecFactory::nsPNGDecFactory(const nsCID &aClass)
{
NS_INIT_REFCNT();
mClassID = aClass;
}
nsPNGDecFactory::~nsPNGDecFactory(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
/*----------------------------------for autoregistration ----*/
static NS_DEFINE_CID(kComponentManagerCID, NS_COMPONENTMANAGER_CID);
extern "C" NS_EXPORT nsresult
NSRegisterSelf(nsISupports* aServMgr, const char *path)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
if ((rv = nsRepository::RegisterComponent(kPNGDecoderCID,
"Netscape PNGDec",
"component://netscape/image/decoder&type=image/png", path, PR_TRUE, PR_TRUE)
) != NS_OK) {
return rv;
}
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
extern "C" NS_EXPORT nsresult NSUnregisterSelf(nsISupports* aServMgr, const char *path)
{
nsresult rv;
nsCOMPtr<nsIServiceManager> servMgr(do_QueryInterface(aServMgr, &rv));
if (NS_FAILED(rv)) return rv;
nsIComponentManager* compMgr;
rv = servMgr->GetService(kComponentManagerCID,
nsIComponentManager::GetIID(),
(nsISupports**)&compMgr);
if (NS_FAILED(rv)) return rv;
rv = compMgr->UnregisterFactory(kPNGDecoderCID, path);
(void)servMgr->ReleaseService(kComponentManagerCID, compMgr);
return rv;
}
/*--------------------*/
NS_IMETHODIMP
nsPNGDecFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **ppv)
{
PNGDecoder *pngdec = NULL;
*ppv = NULL;
il_container* ic = NULL;
if (aOuter && !aIID.Equals(kISupportsIID))
return NS_NOINTERFACE;
ic = new il_container();
pngdec = new PNGDecoder(ic);
nsresult res = pngdec->QueryInterface(aIID,(void**)ppv);
//interface is other than nsISupports and pngdecoder
if (NS_FAILED(res)) {
*ppv = NULL;
delete pngdec;
}
return res;
}
NS_METHOD
nsPNGDecFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}
extern "C" NS_EXPORT nsresult
NSGetFactory(nsISupports* serviceMgr,
const nsCID &aClass,
const char *aClassName,
const char *aProgID,
nsIFactory **aFactory)
{
if( !aClass.Equals(kPNGDecoderCID))
return NS_ERROR_FACTORY_NOT_REGISTERED;
if( gFactory == NULL){
gFactory = new nsPNGDecFactory(aClass);
if( gFactory == NULL)
return NS_ERROR_OUT_OF_MEMORY;
gFactory->AddRef(); //for global
}
gFactory->AddRef(); //for client
*aFactory = gFactory;
return NS_OK;
}
/*----------------------------------------------------*/
// api functions
/*------------------------------------------------------*/
NS_IMETHODIMP
PNGDecoder::ImgDInit()
{
if(mContainer != NULL) {
return(il_png_init(mContainer));
}
else {
return nsnull;
}
}
NS_IMETHODIMP
PNGDecoder::ImgDWriteReady()
{
if(mContainer != NULL) {
/* see ImageConsumer::OnDataAvailable(). dummy return */
return 1;
}
return 0;
}
NS_IMETHODIMP
PNGDecoder::ImgDWrite(const unsigned char *buf, int32 len)
{
if( mContainer != NULL ) {
return(il_png_write(mContainer, buf,len));
}
return 0;
}
NS_IMETHODIMP
PNGDecoder::ImgDComplete()
{
if( mContainer != NULL ) {
il_png_complete(mContainer);
}
return 0;
}
NS_IMETHODIMP
PNGDecoder::ImgDAbort()
{
if( mContainer != NULL ) {
il_png_abort(mContainer);
}
return 0;
}

View File

@@ -0,0 +1,40 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http:/www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* nsPNGDecoder.cpp --- interface to png decoder
*/
#ifndef _nsPNGDec_h
#define _nsPNGDec_h
/* 573010b0-de61-11d2-802c-0060088f91a3 */
#define NS_PNGDECODER_CID \
{ 0x573010b0, 0xde61, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
/* 789d4ab0-de61-11d2-802e-0060088f91a3 */
#define NS_PNGDECODER_IID \
{ 0x789d4ab0, 0xde61, 0x11d2, \
{ 0x80, 0x2c, 0x00, 0x60, 0x08, 0x8f, 0x91, 0xa3 } }
static NS_DEFINE_IID(kPNGDecoderIID, NS_PNGDECODER_IID);
static NS_DEFINE_CID(kPNGDecoderCID, NS_PNGDECODER_CID);
#endif

View File

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

View File

@@ -0,0 +1,206 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* png_png.c - modified from example.c code */
#include "png.h"
#include "if_struct.h"
#include "ipng.h"
#include "nsIImgDecoder.h"
#include "nsPNGDecoder.h"
#include "nsPNGCallback.h"
#define OK 1
#define ERROR -1
extern void png_set_expand(png_structp);
extern void png_destroy_read_struct(png_structpp, png_infopp, png_infopp);
extern void png_set_dims(il_container *, png_structp);
extern void il_get_alpha_channel(uint8 *, int,
uint8 *, int);
extern void png_set_strip_alpha(png_structp);
int
process_data(png_structp *png_ptr, png_infop *info_ptr,
png_bytep buffer, png_uint_32 length)
{
if (setjmp((*png_ptr)->jmpbuf))
{
/* Free the png_ptr and info_ptr memory on error */
png_destroy_read_struct(png_ptr, info_ptr, (png_infopp)NULL);
return ERROR;
}
/* This one's new also. Simply give it chunks of data as
* they arrive from the data stream (in order, of course).
* On Segmented machines, don't give it any more than 64K.
* The library seems to run fine with sizes of 4K, although
* you can give it much less if necessary (I assume you can
* give it chunks of 1 byte, but I haven't tried with less
* than 256 bytes yet). When this function returns, you may
* want to display any rows that were generated in the row
* callback, if you aren't already displaying them there.
*/
png_process_data(*png_ptr, *info_ptr, buffer, length);
return OK;
}
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);
// if(png_ptr->color_type & PNG_COLOR_MASK_ALPHA)
// png_set_strip_alpha(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);
/* if(png_ptr->num_trans)
il_png_init_transparency( png_ptr, png_ptr->io_ptr, png_ptr->trans_values.index);
*/
}
void
il_create_alpha_mask( il_container *ic ,/* png_bytep mask, int srcwidth, */int xoffset,
int destwidth, int destheight)
{
if (!ic->mask) {
NI_PixmapHeader *mask_header;
if (!(ic->mask = PR_NEWZAP(IL_Pixmap))) {
return;
}
mask_header = &ic->mask->header;
mask_header->color_space = ic->imgdcb->ImgDCBCreateGreyScaleColorSpace(); //(1,1)
if (!mask_header->color_space)
return; /*MK_OUT_OF_MEMORY*/
mask_header->width = destwidth;
mask_header->height = destheight;
mask_header->widthBytes = (mask_header->width + 7) / 8;
#define HOWMANY(x, r) (((x) + ((r) - 1)) / (r))
#define ROUNDUP(x, r) (HOWMANY(x, r) * (r))
/* Mask data must be quadlet aligned for optimizations */
mask_header->widthBytes = ROUNDUP(mask_header->widthBytes, 4);
}
return;
}
void row_callback( png_structp png_ptr, png_bytep new_row,
png_uint_32 row_num, int pass )
{
/* this function is called for every row in the image. If the
* image is interlacing, and you turned on the interlace handler,
* this function will be called for every row in every pass.
* Some of these rows will not be changed from the previous pass.
* When the row is not changed, the new_row variable will be NULL.
* The rows and passes are called in order, so you don't really
* need the row_num and pass, but I'm supplying them because it
* may make your life easier.
*
* For the non-NULL rows of interlaced images, you must call
* png_progressive_combine_row() passing in the row and the
* old row. You can call this function for NULL rows (it will
* just return) and for non-interlaced images (it just does the
* memcpy for you) if it will make the code easier. Thus, you
* can just do this for all cases:
*/
il_container *ic = (il_container *)png_ptr->io_ptr;
if(new_row){
ic->imgdcb->ImgDCBHaveRow( 0, new_row, 0, png_ptr->width,
row_num, 1, ilErase /* ilOverlay */, png_ptr->pass );
/* il_flush_image_data(png_ptr->io_ptr); */
}
/* where old_row is what was displayed for previous rows. Note
* that the first pass (pass == 0 really) will completely cover
* the old row, so the rows do not have to be initialized. After
* the first pass (and only for interlaced images), you will have
* to pass the current row, and the function will combine the
* old row and the new row.
*/
}
void end_callback(png_structp png_ptr, png_infop info)
{
/* this function is called when the whole image has been read,
* including any chunks after the image (up to and including
* the IEND). You will usually have the same info chunk as you
* had in the header, although some data may have been added
* to the comments and time fields.
*
* Most people won't do much here, perhaps setting a flag that
* marks the image as finished.
*/
il_container *ic = (il_container *)png_ptr->io_ptr;
ic->imgdcb->ImgDCBFlushImage();
}

View File

@@ -0,0 +1,28 @@
/* -*- 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.0 (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.
*/
/* png.h */
extern int il_png_init(il_container *ic);
extern int il_png_write(il_container *, const uint8 *, int32);
extern void il_png_complete(il_container *ic);
extern unsigned int il_png_write_ready(il_container *ic);
extern void il_png_abort(il_container *ic);
extern void png_delay_time_callback(void *closure);

View File

@@ -0,0 +1,16 @@
#
# This is a list of local files which get copied to the mozilla:dist:libimg directory
#
dummy_nc.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

View File

@@ -0,0 +1,40 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
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 \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,42 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* 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"
#include "net.h"
typedef void* IL_NetContext;
PR_BEGIN_EXTERN_C
extern IL_NetContext *
IL_NewDummyNetContext(MWContext *context,
NET_ReloadMethod cache_reload_policy);
extern void
IL_DestroyDummyNetContext(IL_NetContext *net_cx);
PR_END_EXTERN_C
#endif /* _DUMMY_NC_H */

View File

@@ -0,0 +1,158 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ilIImageRenderer_h___
#define ilIImageRenderer_h___
#include <stdio.h>
#include "libimg.h"
#include "nsISupports.h"
// IID for the nsIImageRenderer interface
#define IL_IIMAGERENDERER_IID \
{ 0xec4e9fc0, 0xb1f3, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
/**
* Interface to be implemented by image creation and rendering
* component plugged into the image library.
*/
class ilIImageRenderer : public nsISupports {
public:
/**
* 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.)
*/
virtual void 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.
*/
virtual void UpdatePixmap(void* aDisplayContext,
IL_Pixmap* aImage,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight)=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.
*/
virtual void 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.
*/
virtual void 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.
*/
virtual void DisplayPixmap(void* aDisplayContext,
IL_Pixmap* aImage, IL_Pixmap* aMask,
PRInt32 aX, PRInt32 aY,
PRInt32 aXOffset, PRInt32 aYOffset,
PRInt32 aWidth, PRInt32 aHeight)=0;
/**
* <bold>(Probably temporary and subject to change).</bold>
* Display an icon. x and y are in document coordinates.
*/
virtual void DisplayIcon(void* aDisplayContext,
PRInt32 aX, PRInt32 aY, PRUint32 aIconNumber)=0;
/**
* <bold>(Probably temporary and subject to change).</bold>
* This method should fill in the targets of the width and
* height pointers to indicate icon dimensions
*/
virtual void GetIconDimensions(void* aDisplayContext,
PRInt32 *aWidthPtr, PRInt32 *aHeightPtr,
PRUint32 aIconNumber)=0;
};
#endif

View File

@@ -0,0 +1,62 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ilINetContext_h___
#define ilINetContext_h___
#include <stdio.h>
#include "nsISupports.h"
#include "ntypes.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:
virtual ilINetContext* Clone()=0;
virtual NET_ReloadMethod GetReloadPolicy()=0;
virtual void AddReferer(ilIURL *aUrl)=0;
virtual void Interrupt()=0;
virtual ilIURL* CreateURL(const char *aUrl,
NET_ReloadMethod 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, NET_ReloadMethod aLoadMethod,
ilINetReader *aReader)=0;
};
#endif

View File

@@ -0,0 +1,54 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ilINetReader_h___
#define ilINetReader_h___
#include <stdio.h>
#include "nsISupports.h"
#include "ntypes.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:
virtual unsigned int WriteReady()=0;
virtual int FirstWrite(const unsigned char *str, int32 len)=0;
virtual int Write(const unsigned char *str, int32 len)=0;
virtual void StreamAbort(int status)=0;
virtual void StreamComplete(PRBool is_multipart)=0;
virtual void NetRequestDone(ilIURL *urls, int status)=0;
virtual PRBool StreamCreated(ilIURL *urls, int type)=0;
virtual PRBool IsMulti()=0;
};
#endif

View File

@@ -0,0 +1,41 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ilISystemServices_h___
#define ilISystemServices_h___
#include <stdio.h>
#include "nsISupports.h"
// IID for the ilISystemServices interface
#define IL_ISYSTEMSERVICES_IID \
{ 0xc14659e0, 0xb9fe, 0x11d1, \
{ 0x9b, 0xc3, 0x00, 0x60, 0x08, 0x8c, 0xa6, 0xb3 } }
typedef void (*ilTimeoutCallbackFunction) (void * closure);
class ilISystemServices : public nsISupports {
public:
virtual void * SetTimeout(ilTimeoutCallbackFunction aFunc,
void * aClosure, PRUint32 aMsecs)=0;
virtual void ClearTimeout(void *aTimerID)=0;
};
#endif

View File

@@ -0,0 +1,50 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef ilIURL_h___
#define ilIURL_h___
#include <stdio.h>
#include "nsISupports.h"
#include "ntypes.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 const char* GetAddress()=0;
virtual time_t GetExpires()=0;
virtual void SetBackgroundLoad(PRBool aBgload)=0;
virtual int GetOwnerId()=0;
virtual void SetOwnerId(int)=0;
};
#endif

View File

@@ -0,0 +1,104 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_icons.h --- Image icon enumeration.
* $Id: il_icons.h,v 3.2 1998-07-27 16:09:05 hardts%netscape.com Exp $
*/
#ifndef _IL_ICONS_H_
#define _IL_ICONS_H_
/* Fixed image icons */
#define IL_IMAGE_FIRST 0x11
#define IL_IMAGE_DELAYED 0x11
#define IL_IMAGE_NOT_FOUND 0x12
#define IL_IMAGE_BAD_DATA 0x13
#define IL_IMAGE_INSECURE 0x14
#define IL_IMAGE_EMBED 0x15
#define IL_IMAGE_LAST 0x15
#define IL_NEWS_FIRST 0x21
#define IL_NEWS_CATCHUP 0x21
#define IL_NEWS_CATCHUP_THREAD 0x22
#define IL_NEWS_FOLLOWUP 0x23
#define IL_NEWS_GOTO_NEWSRC 0x24
#define IL_NEWS_NEXT_ART 0x25
#define IL_NEWS_NEXT_ART_GREY 0x26
#define IL_NEWS_NEXT_THREAD 0x27
#define IL_NEWS_NEXT_THREAD_GREY 0x28
#define IL_NEWS_POST 0x29
#define IL_NEWS_PREV_ART 0x2A
#define IL_NEWS_PREV_ART_GREY 0x2B
#define IL_NEWS_PREV_THREAD 0x2C
#define IL_NEWS_PREV_THREAD_GREY 0x2D
#define IL_NEWS_REPLY 0x2E
#define IL_NEWS_RTN_TO_GROUP 0x2F
#define IL_NEWS_SHOW_ALL_ARTICLES 0x30
#define IL_NEWS_SHOW_UNREAD_ARTICLES 0x31
#define IL_NEWS_SUBSCRIBE 0x32
#define IL_NEWS_UNSUBSCRIBE 0x33
#define IL_NEWS_FILE 0x34
#define IL_NEWS_FOLDER 0x35
#define IL_NEWS_FOLLOWUP_AND_REPLY 0x36
#define IL_NEWS_LAST 0x36
#define IL_GOPHER_FIRST 0x41
#define IL_GOPHER_TEXT 0x41
#define IL_GOPHER_IMAGE 0x42
#define IL_GOPHER_BINARY 0x43
#define IL_GOPHER_SOUND 0x44
#define IL_GOPHER_MOVIE 0x45
#define IL_GOPHER_FOLDER 0x46
#define IL_GOPHER_SEARCHABLE 0x47
#define IL_GOPHER_TELNET 0x48
#define IL_GOPHER_UNKNOWN 0x49
#define IL_GOPHER_LAST 0x49
#define IL_EDIT_FIRST 0x60
#define IL_EDIT_NAMED_ANCHOR 0x61
#define IL_EDIT_FORM_ELEMENT 0x62
#define IL_EDIT_UNSUPPORTED_TAG 0x63
#define IL_EDIT_UNSUPPORTED_END_TAG 0x64
#define IL_EDIT_JAVA 0x65
#define IL_EDIT_PLUGIN 0x66
#define IL_EDIT_LAST 0x66
/* Security Advisor and S/MIME icons */
#define IL_SA_FIRST 0x70
#define IL_SA_SIGNED 0x71
#define IL_SA_ENCRYPTED 0x72
#define IL_SA_NONENCRYPTED 0x73
#define IL_SA_SIGNED_BAD 0x74
#define IL_SA_ENCRYPTED_BAD 0x75
#define IL_SMIME_ATTACHED 0x76
#define IL_SMIME_SIGNED 0x77
#define IL_SMIME_ENCRYPTED 0x78
#define IL_SMIME_ENC_SIGNED 0x79
#define IL_SMIME_SIGNED_BAD 0x7A
#define IL_SMIME_ENCRYPTED_BAD 0x7B
#define IL_SMIME_ENC_SIGNED_BAD 0x7C
#define IL_SA_LAST 0x7C
#define IL_MSG_FIRST 0x80
#define IL_MSG_ATTACH 0x80
#define IL_MSG_LAST 0x80
#endif /* _IL_ICONS_H_ */

View File

@@ -0,0 +1,70 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_strm.h --- Stream converters for the image library.
* $Id: il_strm.h,v 3.2 1998-07-27 16:09:06 hardts%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_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 */
#ifndef STANDALONE_IMAGE_LIB
XP_BEGIN_PROTOS
/********************** Image Library stream converters. *********************/
extern int IL_DisplayMemCacheInfoAsHTML(FO_Present_Types format_out,
URL_Struct *urls,
OPAQUE_CONTEXT *net_cx);
/********************** Image Library stream converters. *********************/
/* The standard converter for all types of images which are part of an HTML
document. */
extern NET_StreamClass * IL_NewStream (FO_Present_Types format_out,
void *data_obj,
URL_Struct *urls,
OPAQUE_CONTEXT *cx);
/* The converter used to handle images which are viewed by themselves e.g.
http://home.netscape.com/foo.gif. This generates a fake
HTML document, and ships it off to the parser. */
extern NET_StreamClass * IL_ViewStream (FO_Present_Types format_out,
void *data_obj,
URL_Struct *urls,
OPAQUE_CONTEXT *cx);
XP_END_PROTOS
#endif /* STANDALONE_IMAGE_LIB */

View File

@@ -0,0 +1,292 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_types.h --- Image library data types and structures.
* $Id: il_types.h,v 3.2 1998-07-27 16:09:07 hardts%netscape.com Exp $
*/
#ifndef _IL_TYPES_H_
#define _IL_TYPES_H_
#include "prtypes.h"
#ifdef STANDALONE_IMAGE_LIB
#define IL_EXTERN(__type) PR_EXTERN(__type)
#define IL_IMPLEMENT(__type) PR_IMPLEMENT(__type)
#else
#define IL_EXTERN(__type) __type
#define IL_IMPLEMENT(__type) __type
#endif /* STANDALONE_IMAGE_LIB */
/************************** 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. */
/* A rectangle structure. */
typedef struct _IL_Rect {
uint16 x_origin;
uint16 y_origin;
uint16 width;
uint16 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 {
uint8 index;
uint8 red, green, blue;
} IL_IRGB;
/* A RGB triplet representing a single pixel in the image's colormap
(if present.) */
typedef struct _IL_RGB
{
uint8 red, green, blue, pad; /* Windows requires the fourth byte &
many compilers pad it anyway. */
uint16 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. */
uint16 width; /* Image width. */
uint16 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. */
uint16 icon_width; /* Icon width. */
uint16 icon_height; /* Icon height. */
int32 icon_number; /* Icon number. */
} IL_MessageData;
/************************* Image Group Observer Notification *****************
* - for observers of an IL_GroupContext.
******************************************************************************/
/* Possible image group observer notification messages. Note: animations are
considered to have loaded at the end of the first iteration. A looping
animation is one which is on its second or a subsequent iteration. */
enum {
IL_STARTED_LOADING, /* Start of image loading. Sent when a loading
image is added to an image group which
currently has no loading images. */
IL_ABORTED_LOADING, /* Some images were aborted. A finished
loading message will not be sent until the
aborted images have been destroyed. */
IL_FINISHED_LOADING, /* End of image loading. Sent when the last
of the images currently in the image group
has finished loading. */
IL_STARTED_LOOPING, /* Start of image looping. Sent when an
animated image starts looping in an image
group which currently has no looping
animations. */
IL_FINISHED_LOOPING /* End of image looping. Sent when the last
of the images currently in the image group
has finished looping. */
};
/* Message data passed to the client-provided image group observer
callbacks. */
typedef struct {
void *display_context; /* The Front End display context associated
with the image group context. */
IL_GroupContext *image_context; /* The image group context being
observed. */
} IL_GroupMessageData;
/************************** Display Preferences ******************************/
/* Flags to be passed into IL_SetDisplayMode. */
#define IL_DISPLAY_CONTEXT 0x01
#define IL_DISPLAY_TYPE 0x02
#define IL_COLOR_SPACE 0x04
#define IL_PROGRESSIVE_DISPLAY 0x08
#define IL_DITHER_MODE 0x10
/* The display type. */
typedef enum {
IL_Console = 0,
IL_Printer = 1,
IL_PostScript = 2,
IL_MetaFile = 3
} IL_DisplayType;
/* Dithering preference. */
typedef enum IL_DitherMode {
IL_ClosestColor = 0,
IL_Dither = 1,
IL_Auto = 2
} IL_DitherMode;
/* Data for setting the display mode. */
typedef struct {
void *display_context; /* The FE's display context. */
IL_DisplayType display_type; /* IL_Console, IL_Printer, IL_PostScript, or
IL_MetaFile. */
IL_ColorSpace *color_space; /* Display colorspace. */
PRBool progressive_display; /* Toggle for progressive image display. */
IL_DitherMode dither_mode; /* IL_ClosestColor, IL_Dither or IL_Auto. */
} IL_DisplayData;
#endif /* _IL_TYPES_H_ */

View File

@@ -0,0 +1,133 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_util.h Colormap and colorspace utilities.
*
* $Id: il_util.h,v 3.2 1998-07-27 16:09:08 hardts%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, uint16 num_reserved_colors,
uint16 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, uint16 num_reserved_colors,
uint16 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, uint16 *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, uint8 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, uint8 index_depth,
uint8 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(IL_ColorSpace *)
IL_CreateGreyScaleColorSpace(uint8 index_depth, uint8 pixmap_depth);
/* Decrements the reference count for an IL_ColorSpace. If the reference
count reaches zero, all memory associated with the colorspace (including
any colormap associated memory) will be freed. */
IL_EXTERN(void)
IL_ReleaseColorSpace(IL_ColorSpace *color_space);
/* Increment the reference count for an IL_ColorSpace. */
IL_EXTERN(void)
IL_AddRefToColorSpace(IL_ColorSpace *color_space);
XP_END_PROTOS
#endif /* _IL_UTIL_H */

View File

@@ -0,0 +1,339 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* libimg.h --- API calls to the Image Library.
* $Id: libimg.h,v 3.2 1998-07-27 16:09:09 hardts%netscape.com Exp $
*/
#ifndef _LIBIMG_H
#define _LIBIMG_H
#include "prtypes.h"
#include "il_types.h"
#include "dummy_nc.h"
#ifdef STANDALONE_IMAGE_LIB
#include "ilISystemServices.h"
#include "ilIImageRenderer.h"
#else
#include "MIMGCBIF.h" /* JMC generated callback interface. */
#include "MIMGCB.h" /* JMC generated callback interface
implementation. */
#include "MPSIMGCB.h" /* JMC generated callback interface
implementation for PostScript Front End. */
#endif /* STANDALONE_IMAGE_LIB */
/*********************** 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. */
#ifdef STANDALONE_IMAGE_LIB
IL_EXTERN(int)
IL_Init(ilISystemServices *ss);
#else
IL_EXTERN(int)
IL_Init(void);
#endif /* STANDALONE_IMAGE_LIB */
/* 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. */
#ifdef STANDALONE_IMAGE_LIB
IL_EXTERN(IL_GroupContext *)
IL_NewGroupContext(void *display_context,
ilIImageRenderer *image_render);
#else
IL_EXTERN(IL_GroupContext *)
IL_NewGroupContext(void *display_context,
IMGCBIF *image_callbacks);
#endif /* STANDALONE_IMAGE_LIB */
/* 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,
uint32 width, uint32 height,
uint32 flags,
void *net_context);
/* 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, uint32 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(uint32 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, uint32 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(uint32)
IL_ShrinkCache(void);
/* Return the approximate storage consumed by the imagelib cache, in bytes */
IL_EXTERN(uint32)
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);
#ifndef STANDALONE_IMAGE_LIB
/* Wacky netlib callback designed to give precedence to streams that block
layout. */
IL_EXTERN(PRBool)
IL_PreferredStream(URL_Struct *urls);
#endif
/* This is a legacy "safety-valve" routine, called each time a new HTML page
is loaded. It causes remaining references to images in the given group
context to be freed, i.e. like calling IL_DestroyImage on each of them.
This is primarily required because layout sometimes leaks images, and it
should go away when we can fix layout. */
IL_EXTERN(void)
IL_DestroyImageGroup(IL_GroupContext *image_context);
PR_END_EXTERN_C
#endif /* _LIBIMG_H */

View File

@@ -0,0 +1,100 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
#
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
!if "$(MOZ_BITS)" != "16"
INSTALL_DIR=$(PUBLIC)\img
!else
INSTALL_DIR=$(PUBLIC)\win16
!endif
LCFLAGS = $(LCFLAGS) /TP
MODULE=img
DEPTH=..\..\..
!ifdef MOZ_JAVA
!ifndef STANDALONE_IMAGE_LIB
JMC_GEN=MIMGCBIF MIMGCB MPSIMGCB
JMC_GEN_FLAGS=-cimpl -noexc -interface
EXPORTS=il_types.h ni_pixmp.h libimg.h il_icons.h il_strm.h il_util.h \
dummy_nc.h $(JMC_GEN_DIR)/MIMGCBIF.h $(JMC_GEN_DIR)/MIMGCB.h \
$(JMC_GEN_DIR)/MPSIMGCB.h
JMC_HEADERS=$(JMC_GEN_DIR)\MIMGCBIF.h $(JMC_GEN_DIR)\MIMGCB.h \
$(JMC_GEN_DIR)\MPSIMGCB.h
JMC_STUBS=$(JMC_GEN_DIR)\MIMGCBIF.c $(JMC_GEN_DIR)\MIMGCB.c \
$(JMC_GEN_DIR)\MPSIMGCB.c
JMC_OBJS=.\$(OBJDIR)\MIMGCBIF.obj .\$(OBJDIR)\MIMGCB.obj \
.\$(OBJDIR)\MPSIMGCB.obj
!endif
!else
!ifdef STANDALONE_IMAGE_LIB
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
!else
EXPORTS=il_types.h ni_pixmp.h libimg.h il_icons.h il_strm.h il_util.h \
dummy_nc.h MIMGCBIF.h MIMGCB.h MPSIMGCB.h
!endif
!endif
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include <$(DEPTH)/config/rules.mak>
!ifdef MOZ_JAVA
!ifndef STANDALONE_IMAGE_LIB
$(JMC_GEN_DIR)\MIMGCBIF.h: $(JMCSRCDIR)\IMGCBIF.class
$(JMC) -d $(JMC_GEN_DIR) -interface $(JMC_GEN_FLAGS) $(?F:.class=)
$(JMC_GEN_DIR)\MIMGCBIF.c: $(JMCSRCDIR)\IMGCBIF.class
$(JMC) -d $(JMC_GEN_DIR) -module $(JMC_GEN_FLAGS) $(?F:.class=)
$(JMC_GEN_DIR)\MIMGCB.h: $(JMCSRCDIR)\IMGCB.class
$(JMC) -d $(JMC_GEN_DIR) -interface $(JMC_GEN_FLAGS) $(?F:.class=)
$(JMC_GEN_DIR)\MIMGCB.c: $(JMCSRCDIR)\IMGCB.class
$(JMC) -d $(JMC_GEN_DIR) -module $(JMC_GEN_FLAGS) $(?F:.class=)
$(JMC_GEN_DIR)\MPSIMGCB.h: $(JMCSRCDIR)\PSIMGCB.class
$(JMC) -d $(JMC_GEN_DIR) -interface $(JMC_GEN_FLAGS) $(?F:.class=)
$(JMC_GEN_DIR)\MPSIMGCB.c: $(JMCSRCDIR)\PSIMGCB.class
$(JMC) -d $(JMC_GEN_DIR) -module $(JMC_GEN_FLAGS) $(?F:.class=)
!endif
!endif
export:: INSTALL_FILES

View File

@@ -0,0 +1,185 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* ni_pixmp.h --- Cross platform pixmap data structure.
* $Id: ni_pixmp.h,v 3.2 1998-07-27 16:09:11 hardts%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 {
uint8 red_bits; /* Number of bits assigned to red channel. */
uint8 red_shift; /* Offset for red channel bits. */
uint8 green_bits; /* Number of bits assigned to green channel. */
uint8 green_shift; /* Offset for green channel bits. */
uint8 blue_bits; /* Number of bits assigned to blue channel. */
uint8 blue_shift; /* Offset for blue channel bits. */
} NI_RGBBits;
/* An indexed RGB triplet. */
typedef struct _NI_IRGB {
uint8 index;
uint8 red, green, blue;
} NI_IRGB;
/* A RGB triplet representing a single pixel in the image's colormap
(if present.) */
typedef struct _NI_RGB
{
uint8 red, green, blue, pad; /* Windows requires the fourth byte &
many compilers pad it anyway. */
uint16 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. */
uint8 *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. */
uint8 index_depth; /* For PseudoColor and GreyScale. */
} bit_alloc; /* Allocation of bits. */
uint8 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. */
uint8 os_flags; /* Flags are of type NI_OSFlags. */
/* Reference counter. */
uint32 ref_count;
} NI_ColorSpace;
/* A pixmap's header information. */
typedef struct _NI_PixmapHeader
{
/* Size. */
uint32 width; /* Width. */
uint32 height; /* Height. */
uint32 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.) */
uint8 alpha_bits; /* Number of bits assigned to alpha channel. */
uint8 alpha_shift; /* Offset for alpha channel bits. */
int32 is_interleaved_alpha; /* Is alpha channel interleaved with
image data? */
/* 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. */
void *client_data; /* Pixmap-specific data opaque to the Image
Library e.g. display front-ends which
support scaling may use this to store the
actual size at which the image is to be
displayed. */
} NI_Pixmap;
#endif /* _NI_PIXMAP_H */

View File

@@ -0,0 +1,40 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = img
EXPORTS = il.h dllcompat.h if_struct.h il_utilp.h \
nsIImgDecoder.h nsImgDecCID.h nsImgDecoder.h \
nsImgDCallbk.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,42 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* 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 dllcompat_h___
#define dllcompat_h___
#include "platform.h"
#include "prtypes.h"
#include "nsCom.h"
#include "xp_mcom.h"
#include "xp_str.h"
typedef void
(*TimeoutCallbackFunction) (void * closure);
#endif

View File

@@ -0,0 +1,374 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* if.h --- Top-level image library internal routines
*
* $Id: if_struct.h,v 1.1.2.1 1999-04-15 19:58:04 pnunn%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 "dllcompat.h"
#include "nsIImgDecoder.h"
#include "ntypes.h" /* typedefs for commonly used Netscape data
structures */
#ifndef STANDALONE_IMAGE_LIB
#include "net.h"
#endif /* STANDALONE_IMAGE_LIB */
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"
/***************************** also in dllcompat.h ***********************/
#ifndef STANDALONE_IMAGE_LIB
PR_BEGIN_EXTERN_C
typedef void
(*TimeoutCallbackFunction) (void * closure);
extern void *
FE_SetTimeout(TimeoutCallbackFunction func, void * closure, uint32 msecs);
extern void
FE_ClearTimeout(void *timer_id);
PR_END_EXTERN_C
#endif
/********************************* in dllcompat.h *************************************/
#include "il.h"
/* For debugging counts of loading, looping and aborted images, needed for
group observer notification. */
/* #define DEBUG_GROUP_OBSERVER */
#ifdef DEBUG
#define Debug 1
#endif
#ifdef XP_WIN
#define _USD 1 /* scanlines upside-down */
#endif
//extern PRLogModuleInfo *il_log_module;
#ifdef DEBUG
//#define ILTRACE(l,t) { if(il_debug>l) {PR_LOG(il_log_module, 1, t);} }
#else
#define ILTRACE(l,t) {}
#endif
#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 uint8 *mask,
const uint8 *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)==NET_NORMAL_RELOAD) || ((reload_method)==NET_SUPER_RELOAD))
/* 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*/
uint32 hash;
uint32 urlhash;
enum icstate state;
int sized;
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. */
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;
uint32 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. */
intn 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;
uint8 *scalerow;
int pass; /* pass (scan #) of a multi-pass image.
Used for interlaced GIFs & p-JPEGs */
int forced;
uint32 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. */
};
extern int il_debug;
#ifdef DEBUG
#define ILTRACE(l,t) {}
#else
#define ILTRACE(l,t) {}
#endif
#endif
#endif

View File

@@ -0,0 +1,55 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* il.h --- Exported image library interface
*
* $Id: il.h,v 1.1.2.1 1999-04-15 19:58:51 pnunn%netscape.com Exp $
*/
/*
* global defines for image lib users
*/
#ifndef _IL_H
#define _IL_H
#include "ntypes.h"
/* attr values */
#define IL_ATTR_RDONLY 0
#define IL_ATTR_RW 1
#define IL_ATTR_TRANSPARENT 2
#define IL_ATTR_HONOR_INDEX 4
#undef ABS
#define ABS(x) (((x) < 0) ? -(x) : (x))
/* A fast but limited, perceptually-weighted color distance function */
#define IL_COLOR_DISTANCE(r1, r2, g1, g2, b1, b2) \
((ABS((g1) - (g2)) << 2) + (ABS((r1) - (r2)) << 1) + (ABS((b1) - (b2))))
/* We don't distinguish between colors that are "closer" together
than this. The appropriate setting is a subjective matter. */
#define IL_CLOSE_COLOR_THRESHOLD 6
#endif /* _IL_H */

View File

@@ -0,0 +1,78 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- 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.1.2.1 1999-04-15 23:56:49 pnunn%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
uint8 red, green, blue;
uint16 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
uintN. */
void *r8torgbn;
void *g8torgbn;
void *b8torgbn;
} il_ColorSpaceData;

View File

@@ -0,0 +1,81 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef _nsIImgDecoder_h
#define _nsIImgDecoder_h
#include "if_struct.h"
#include "ni_pixmp.h"
#include "nsISupports.h"
#include "nsImgDecCID.h"
class nsIImgDecoder : public nsISupports
{
public:
NS_IMETHOD ImgDInit()=0;
NS_IMETHOD ImgDWriteReady()=0;
NS_IMETHOD ImgDWrite(const unsigned char *buf, int32 len)=0;
NS_IMETHOD ImgDComplete()=0;
NS_IMETHOD ImgDAbort()=0;
private:
void *mContainer;
};
NS_DEFINE_IID(kImgDCallbkIID, NS_IMGDCALLBK_IID);
NS_DEFINE_CID(kImgDCallbkCID, NS_IMGDCALLBK_CID);
class nsIImgDCallbk : public nsISupports
{
public:
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_(NI_ColorSpace *) ImgDCBCreateGreyScaleColorSpace()=0;
NS_IMETHOD_(void*) ImgDCBSetTimeout(TimeoutCallbackFunction func, void* closure, uint32 msecs)=0;
NS_IMETHOD ImgDCBClearTimeout(void *timer_id)=0;
NS_IMETHOD ImgDCBHaveHdr(int destwidth, int destheight )=0;
NS_IMETHOD ImgDCBHaveRow(uint8 *rowbuf, uint8* rgbrow, int x_offset, int len,
int row, int dup_rowcnt, uint8 draw_mode,
int pass )=0;
NS_IMETHOD ImgDCBHaveImageFrame()=0;
NS_IMETHOD ImgDCBHaveImageAll()=0;
NS_IMETHOD ImgDCBError()=0;
private:
void *mContainer;
};
#endif

View File

@@ -0,0 +1,72 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
*
*/
#include "nsIImgDecoder.h"
/*---------------------------------------------*/
/*-----------------class-----------------------*/
class ImgDCallbk : public nsIImgDCallbk
{
public:
NS_DECL_ISUPPORTS
ImgDCallbk(il_container *aContainer){mContainer=aContainer;};
~ImgDCallbk(){};
NS_IMETHOD ImgDCBFlushImage();
NS_IMETHOD ImgDCBImageSize();
NS_IMETHOD ImgDCBResetPalette();
NS_IMETHOD ImgDCBInitTransparentPixel();
NS_IMETHOD ImgDCBDestroyTransparentPixel();
NS_IMETHOD ImgDCBSetupColorspaceConverter();
NS_IMETHOD_(NI_ColorSpace *) ImgDCBCreateGreyScaleColorSpace();
NS_IMETHOD_(void*) ImgDCBSetTimeout(TimeoutCallbackFunction func,
void* closure, uint32 msecs);
NS_IMETHOD ImgDCBClearTimeout(void *timer_id);
/* callbacks from the decoder */
NS_IMETHOD ImgDCBHaveHdr(int destwidth, int destheight);
NS_IMETHOD ImgDCBHaveRow(uint8*, uint8*,
int, int, int, int,
uint8 , 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 mContainer; };
il_container *SetContainer(il_container *ic) {mContainer=ic; return ic; };
private:
il_container* mContainer;
};
/*-------------------------------*/

View File

@@ -0,0 +1,64 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#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);
////////////////////////////////////////////////
NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
/////////////////////////////////////////////////
/* 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

View File

@@ -0,0 +1,26 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsImgDec_h___
#define nsImgDec_h___
#include "nsIFactory.h"
#endif

View File

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

View File

@@ -0,0 +1,57 @@
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
ifndef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
endif
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = img
LIBRARY_NAME = img
LOCAL_INCLUDES = -I$(srcdir) $(PNG_CFLAGS) $(ZLIB_CFLAGS)
EXTRA_LIBS = $(PNG_LIBS) $(ZLIB_LIBS)
CPPSRCS = \
ilNetReader.cpp \
color.cpp \
colormap.cpp \
dither.cpp \
if.cpp \
ilclient.cpp \
il_util.cpp \
scale.cpp \
$(NULL)
CPPSRCS += xpcompat.cpp \
$(NULL)
REQUIRES += util img xpcom
EXTRA_LIBS += $(NSPR_LIBS)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,955 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- 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.8 1999-04-15 03:04:04 alecf%netscape.com Exp $
*/
#include "if.h"
#ifdef XP_MAC
#include "xpcompat.h"
#else
#include "xp_qsort.h"
#endif
#ifdef PROFILE
#pragma profile on
#endif
uint8 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 uint8 *mask,
const uint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
uint8 red, green, blue, map_index;
uint8 XP_HUGE *out = (uint8 XP_HUGE *) vout + x_offset;
const uint8 *end = sp + 3*num;
IL_ColorMap *cmap = &ic->image->header.color_space->cmap;
uint8 *lookup_table = (uint8 *)cmap->table;
uint8 *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 uint8 *mask,
const uint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
uint8 XP_HUGE *out = (uint8 XP_HUGE *) vout + x_offset;
const uint8 XP_HUGE *end = out + num;
uint8 *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, (uint8 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;
uint8 *greypixels;
uint8 *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 = (uint8 *)PR_Calloc(fs->width+7, 1);
fs->bwpixels = (uint8 *)PR_Calloc(fs->width+7, 1);
#ifdef XP_UNIX
{
int i;
/* XXX should not be unix only */
for(i=0; i<fs->width+2; i++)
{
fs->err1[i] = (XP_RANDOM() % 1024 - 512)/4;
}
}
#endif
fs->threshval = 512;
ic->quantize = (void *)fs;
return fs;
}
static void
ConvertRGBToBW(il_container *ic,
const uint8 *mask,
const uint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
uint32 fgmask32, bgmask32;
uint32 *m;
int mask_bit;
struct fs_data *fs = (struct fs_data *)ic->quantize;
uint8 XP_HUGE *out = (uint8 XP_HUGE *)vout;
uint8 *gp, *bp;
int col, limitcol;
long grey;
long sum;
if(!fs)
fs = init_fs_dither(ic);
/* Silently fail if memory exhausted */
if (! fs)
return;
gp = fs->greypixels;
for(col=0; col<fs->width; col++)
{
/* CCIR 709 */
uint8 r = *sp++;
uint8 g = *sp++;
uint8 b = *sp++;
grey = ((uint)(0.299 * 4096) * r +
(uint)(0.587 * 4096) * g +
(uint)(0.114 * 4096) * b) / 4096;
*gp++ = (uint8)grey;
}
#if 0
/* thresholding */
gp = fs->greypixels;
bp = fs->bwpixels;
for(col=0; col<fs->width; col++)
{
*bp++ = (*gp++<128);
}
#else
for(col=0; col<fs->width+2; col++)
{
fs->err2[col] =0;
}
if (fs->direction)
{
col = 0;
limitcol = fs->width;
gp = fs->greypixels;
bp = fs->bwpixels;
}
else
{
col = fs->width - 1;
limitcol = -1;
gp = &(fs->greypixels[col]);
bp = &(fs->bwpixels[col]);
}
do
{
sum = ( (long) *gp * 1024 ) / 256 + fs->err1[col + 1];
if ( sum >= 512)
{
*bp = 0;
sum = sum - 1024;
}
else
*bp = 1;
if ( fs->direction )
{
fs->err1[col + 2] += ( sum * 7 ) / 16;
fs->err2[col ] += ( sum * 3 ) / 16;
fs->err2[col + 1] += ( sum * 5 ) / 16;
fs->err2[col + 2] += ( sum ) / 16;
col++; gp++; bp++;
}
else
{
fs->err1[col ] += ( sum * 7 ) / 16;
fs->err2[col + 2] += ( sum * 3 ) / 16;
fs->err2[col + 1] += ( sum * 5 ) / 16;
fs->err2[col ] += ( sum ) / 16;
col--; gp--; bp--;
}
}
while ( col != limitcol );
fs->err3 = fs->err1;
fs->err1 = fs->err2;
fs->err2 = fs->err3;
fs->direction = !fs->direction;
#endif
bp = fs->bwpixels;
bgmask32 = 0; /* 32-bit temporary mask accumulators */
fgmask32 = 0;
m = ((uint32*)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 |= ((uint32)pixel & opaqueness) << M32(mask_bit); \
bgmask32 |= ((uint32)((pixel ^ 1) & opaqueness)) << M32(mask_bit); \
\
/* Filled up 32-bit mask word. Write it to memory. */ \
if (mask_bit-- == 0) { \
uint32 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) {
uint32 mtmp = *m;
mtmp |= fgmask32;
mtmp &= ~bgmask32;
*m = mtmp;
}
}
static void
ConvertRGBToGrey8(il_container *ic,
const uint8 *mask,
const uint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
uint r, g, b;
uint8 XP_HUGE *out = (uint8 XP_HUGE *)vout + x_offset;
const uint8 *end = sp + num*3;
uint32 grey;
if (!mask)
{
while (sp < end)
{
/* CCIR 709 */
r = sp[0];
g = sp[1];
b = sp[2];
grey = ((uint)(0.299 * 4096) * r +
(uint)(0.587 * 4096) * g +
(uint)(0.114 * 4096) * b) / 4096;
*out = (uint8)grey;
out++;
sp += 3;
}
}
else
{
while (sp < end)
{
if (*mask++)
{
/* CCIR 709 */
r = sp[0];
g = sp[1];
b = sp[2];
grey = ((uint)(0.299 * 4096) * r +
(uint)(0.587 * 4096) * g +
(uint)(0.114 * 4096) * b) / 4096;
*out = (uint8)grey;
}
out++;
sp += 3;
}
}
}
static void
ConvertRGBToRGB8(il_container *ic,
const uint8 *mask,
const uint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
uint r, g, b, pixel;
uint8 XP_HUGE *out = (uint8 XP_HUGE *) vout + x_offset;
const uint8 *end = sp + num*3;
il_ColorSpaceData *private_data =
(il_ColorSpaceData *)ic->image->header.color_space->private_data;
uint8 *rm = (uint8*)private_data->r8torgbn;
uint8 *gm = (uint8*)private_data->g8torgbn;
uint8 *bm = (uint8*)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 uint8 *mask,
const uint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
uint r, g, b, pixel;
uint16 XP_HUGE *out = (uint16 XP_HUGE *) vout + x_offset;
const uint8 *end = sp + num*3;
il_ColorSpaceData *private_data =
(il_ColorSpaceData *)ic->image->header.color_space->private_data;
uint16 *rm = (uint16*)private_data->r8torgbn;
uint16 *gm = (uint16*)private_data->g8torgbn;
uint16 *bm = (uint16*)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 uint8 *mask,
const uint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
uint8 XP_HUGE *out = (uint8 XP_HUGE *) vout + (3 * x_offset);
const uint8 *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)
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)
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 uint8 *mask,
const uint8 *sp,
int x_offset,
int num,
void XP_HUGE *vout)
{
uint r, g, b, pixel;
uint32 XP_HUGE *out = (uint32 XP_HUGE *) vout + x_offset;
const uint8 *end = sp + num*3;
il_ColorSpaceData *private_data =
(il_ColorSpaceData *)ic->image->header.color_space->private_data;
uint32 *rm = (uint32*)private_data->r8torgbn;
uint32 *gm = (uint32*)private_data->g8torgbn;
uint32 *bm = (uint32*)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 qsort() */
static int
compare_uint32(const void *a, const void *b)
{
uint32 a1 = *(uint32*)a;
uint32 b1 = *(uint32*)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)
{
uint i;
uint32 ind[256];
int32 num_colors = cmap->num_colors;
IL_RGB *map = cmap->map;
uint max_colors;
uint 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. */
XP_QSORT(ind, max_colors, sizeof(*ind), compare_uint32);
/* 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 uint8 red_bits, green_bits, blue_bits;
register uint8 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 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. */
{
uint8 *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 FALSE;
}
/* XXXM12N These could be optimized. */
tmp_map = (uint8*)private_data->r8torgbn;
for (j = 0; j < (1 << red_bits); j++)
for (k = 0; k < (1 << (8 - red_bits)); k++)
*tmp_map++ = (uint8)(j << red_shift);
tmp_map = (uint8*)private_data->g8torgbn;
for (j = 0; j < (1 << green_bits); j++)
for (k = 0; k < (1 << (8 - green_bits)); k++)
*tmp_map++ = (uint8)(j << green_shift);
tmp_map = (uint8*)private_data->b8torgbn;
for (j = 0; j < (1 << blue_bits); j++)
for (k = 0; k < (1 << (8 - blue_bits)); k++)
*tmp_map++ = (uint8)(j << blue_shift);
break;
}
case 16: /* Typically 15 or 16-bit TrueColor. */
{
PRBool win95_rounding; /* True if Win95 color quatization bug is
present. */
uint16 *tmp_map; /* Array type corresponds to pixmap depth. */
private_data->r8torgbn = PR_MALLOC(sizeof(uint16) * 256);
private_data->g8torgbn = PR_MALLOC(sizeof(uint16) * 256);
private_data->b8torgbn = PR_MALLOC(sizeof(uint16) * 256);
if (!(private_data->r8torgbn &&
private_data->g8torgbn &&
private_data->b8torgbn)) {
ILTRACE(0,("il: MEM il_init_rgb_tables"));
return 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 = (uint16*)private_data->r8torgbn;
for (j = 0; j < 256; j++)
*tmp_map++ = (uint16)(ROUND(j, red_bits) >> (8 - red_bits) <<
red_shift);
tmp_map = (uint16*)private_data->g8torgbn;
for (j = 0; j < 256; j++)
*tmp_map++ = (uint16)(ROUND(j, green_bits) >> (8 - green_bits) <<
green_shift);
tmp_map = (uint16*)private_data->b8torgbn;
for (j = 0; j < 256; j++)
*tmp_map++ = (uint16)(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. */
{
uint32 *tmp_map; /* Array type corresponds to pixmap depth. */
private_data->r8torgbn = PR_MALLOC(sizeof(uint32) * 256);
private_data->g8torgbn = PR_MALLOC(sizeof(uint32) * 256);
private_data->b8torgbn = PR_MALLOC(sizeof(uint32) * 256);
if (!(private_data->r8torgbn &&
private_data->g8torgbn &&
private_data->b8torgbn)) {
ILTRACE(0,("il: MEM il_init_rgb_tables"));
return FALSE;
}
tmp_map = (uint32*)private_data->r8torgbn;
for (j = 0; j < (1 << red_bits); j++)
*tmp_map++ = j << red_shift;
tmp_map = (uint32*)private_data->g8torgbn;
for (j = 0; j < (1 << green_bits); j++)
*tmp_map++ = j << green_shift;
tmp_map = (uint32*)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 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)
{
uint8 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:
#ifdef STANDALONE_IMAGE_LIB
if (src_color_space == img_color_space) {
ic->converter = NULL;
return PR_TRUE;
} else
#endif
/* Resolve dither_mode if necessary. */
if (dither_mode == IL_Auto) {
int num_colors = src_color_space->cmap.num_colors;
/* Use a simple heuristic to decide whether or not we dither. */
if ((num_colors <= AUTO_DITHER_COLOR_THRESHOLD) &&
(num_colors <= (img_color_space->cmap.num_colors / 2))) {
dither_mode = IL_ClosestColor;
ILTRACE(1,("Dithering turned off; Image has %d colors: %s",
num_colors, ic->url ? ic->url_address : ""));
}
else {
dither_mode = IL_Dither;
}
}
switch (dither_mode) {
case IL_ClosestColor:
converter = ConvertRGBToCI;
break;
case IL_Dither:
/* Build the range limit table if it doesn't exist. */
if (!il_setup_quantize())
return PR_FALSE;
converter = DitherConvertRGBToCI;
break;
default:
break;
}
break;
/* These conversions are accomplished by first converting to RGB24,
followed by conversion to the actual image pixmap depth. */
case IL_TrueToTrue:
case IL_PseudoToTrue:
case IL_GreyToTrue:
switch (img_color_space->pixmap_depth) {
case 8:
/* Build the depth conversion tables if they do not exist. */
if (!il_init_rgb_depth_tables(img_color_space))
return PR_FALSE;
converter = ConvertRGBToRGB8;
break;
case 16:
/* Build the depth conversion tables if they do not exist. */
if (!il_init_rgb_depth_tables(img_color_space))
return PR_FALSE;
converter = ConvertRGBToRGB16;
break;
case 24:
converter = ConvertRGBToRGB24;
break;
case 32:
/* Build the depth conversion tables if they do not exist. */
if (!il_init_rgb_depth_tables(img_color_space))
return PR_FALSE;
converter = ConvertRGBToRGB32;
break;
default:
PR_ASSERT(0);
break;
}
break;
/* These conversions are accomplished by first converting to RGB24,
followed by conversion to the actual image pixmap depth. */
case IL_TrueToGrey:
case IL_PseudoToGrey:
case IL_GreyToGrey:
switch (img_color_space->pixmap_depth) {
case 1:
dither_mode = IL_Dither;
converter = ConvertRGBToBW;
break;
case 8:
converter = ConvertRGBToGrey8;
break;
}
break;
default:
converter = NULL;
PR_ASSERT(0);
break;
}
ic->dither_mode = dither_mode;
ic->converter = converter;
#ifndef M12N /* XXXM12N Fix me. */
/* Allow for custom color palettes */
if (img_header->cs_type == NI_Pseudocolor)
il_set_color_palette(ic->cx, ic);
#endif /* M12N */
return PR_TRUE;
}
#ifdef PROFILE
#pragma profile off
#endif

View File

@@ -0,0 +1,49 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* colormap.c
*
* $Id: colormap.cpp,v 3.1 1998-07-27 16:09:21 hardts%netscape.com Exp $
*/
#include "if.h"
/*
int
IL_ColormapTag(const char* image_url, MWContext* cx)
{
return 0;
}
*/
/* Force il_set_color_palette() to load a new colormap for an image */
void
il_reset_palette(il_container *ic)
{
NI_ColorMap *cmap = &ic->src_header->color_space->cmap;
ic->colormap_serial_num = -1;
ic->dont_use_custom_palette = FALSE;
ic->rendered_with_custom_palette = FALSE;
if (cmap->num_colors > 0)
cmap->num_colors = 0;
}

View File

@@ -0,0 +1,387 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "if.h"
#include "il.h"
#include "jpeglib.h"
#include "jerror.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 */
XP_BZERO(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 */
XP_BZERO(table + (2 * (MAXJSAMPLE+1)),
(2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
XP_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 uint8 *mask,
const uint8 *input_buf, int x_offset,
uint8 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. */
uint8 *lookup_table = (uint8 *)cmap->table; /* Lookup table for the colormap. */
const uint8 *maskp;
uint8 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 {
XP_BZERO((void XP_HUGE *) output_buf,
(size_t) (width * SIZEOF(JSAMPLE)));
}
input_ptr = input_buf;
output_ptr = output_buf;
maskp = mask;
if (cquantize->on_odd_row) {
int total_offset;
/* work right to left in this row */
input_ptr += 3 * width - 1; /* so point to the blue sample of the
rightmost pixel */
output_ptr += width-1;
dir = -1;
/* => entry after last column */
total_offset = x_offset + (width + 1);
r_errorptr = cquantize->fserrors[0] + total_offset;
g_errorptr = cquantize->fserrors[1] + total_offset;
b_errorptr = cquantize->fserrors[2] + total_offset;
maskp += (width - 1);
}
else {
/* work left to right in this row */
dir = 1;
/* => entry before first column */
r_errorptr = cquantize->fserrors[0] + x_offset;
g_errorptr = cquantize->fserrors[1] + x_offset;
b_errorptr = cquantize->fserrors[2] + x_offset;
}
/* Preset error values: no error propagated to first pixel from left */
r_cur = g_cur = b_cur = 0;
/* and no error propagated to row below yet */
r_belowerr = g_belowerr = b_belowerr = 0;
r_bpreverr = g_bpreverr = b_bpreverr = 0;
for (col = width; col > 0; col--) {
/* cur holds the error propagated from the previous pixel on the
* current line. Add the error propagated from the previous line
* to form the complete error correction term for this pixel, and
* round the error term (which is expressed * 16) to an integer.
* RIGHT_SHIFT rounds towards minus infinity, so adding 8 is correct
* for either sign of the error value.
* Note: errorptr points to *previous* column's array entry.
*/
r_cur = RIGHT_SHIFT(r_cur + r_errorptr[dir] + 8, 4);
g_cur = RIGHT_SHIFT(g_cur + g_errorptr[dir] + 8, 4);
b_cur = RIGHT_SHIFT(b_cur + b_errorptr[dir] + 8, 4);
/* Form pixel value + error, and range-limit to 0..MAXJSAMPLE.
* The maximum error is +- MAXJSAMPLE; this sets the required size
* of the range_limit array.
*/
if (dir > 0) {
r_cur += GETJSAMPLE(*input_ptr);
r_cur = GETJSAMPLE(range_limit[r_cur]);
input_ptr++;
g_cur += GETJSAMPLE(*input_ptr);
g_cur = GETJSAMPLE(range_limit[g_cur]);
input_ptr++;
b_cur += GETJSAMPLE(*input_ptr);
b_cur = GETJSAMPLE(range_limit[b_cur]);
input_ptr++;
}
else {
b_cur += GETJSAMPLE(*input_ptr);
b_cur = GETJSAMPLE(range_limit[b_cur]);
input_ptr--;
g_cur += GETJSAMPLE(*input_ptr);
g_cur = GETJSAMPLE(range_limit[g_cur]);
input_ptr--;
r_cur += GETJSAMPLE(*input_ptr);
r_cur = GETJSAMPLE(range_limit[r_cur]);
input_ptr--;
}
/* Select output value, accumulate into output code for this pixel */
map_index = COLORMAP_INDEX(lookup_table, r_cur, g_cur, b_cur);
if (mask) {
if (*maskp)
*output_ptr = map_index;
maskp += dir;
} else {
*output_ptr = map_index;
}
/* Compute the actual representation error at this pixel */
map_entry = map + map_index;
r_cur -= GETJSAMPLE(map_entry->red);
g_cur -= GETJSAMPLE(map_entry->green);
b_cur -= GETJSAMPLE(map_entry->blue);
/* Compute error fractions to be propagated to adjacent pixels.
* Add these into the running sums, and simultaneously shift the
* next-line error sums left by 1 column.
*/
r_bnexterr = r_cur;
delta = r_cur * 2;
r_cur += delta; /* form error * 3 */
r_errorptr[0] = (FSERROR) (r_bpreverr + r_cur);
r_cur += delta; /* form error * 5 */
r_bpreverr = r_belowerr + r_cur;
r_belowerr = r_bnexterr;
r_cur += delta; /* form error * 7 */
g_bnexterr = g_cur;
delta = g_cur * 2;
g_cur += delta; /* form error * 3 */
g_errorptr[0] = (FSERROR) (g_bpreverr + g_cur);
g_cur += delta; /* form error * 5 */
g_bpreverr = g_belowerr + g_cur;
g_belowerr = g_bnexterr;
g_cur += delta; /* form error * 7 */
b_bnexterr = b_cur;
delta = b_cur * 2;
b_cur += delta; /* form error * 3 */
b_errorptr[0] = (FSERROR) (b_bpreverr + b_cur);
b_cur += delta; /* form error * 5 */
b_bpreverr = b_belowerr + b_cur;
b_belowerr = b_bnexterr;
b_cur += delta; /* form error * 7 */
/* At this point cur contains the 7/16 error value to be propagated
* to the next pixel on the current line, and all the errors for the
* next line have been shifted over. We are therefore ready to move on.
* Note: the input_ptr has already been advanced.
*/
output_ptr += dir; /* advance output ptr to next column */
r_errorptr += dir; /* advance errorptr to current column */
g_errorptr += dir; /* advance errorptr to current column */
b_errorptr += dir; /* advance errorptr to current column */
}
/* Post-loop cleanup: we must unload the final error value into the
* final fserrors[] entry. Note we need not unload belowerr because
* it is for the dummy column before or after the actual array.
*/
r_errorptr[0] = (FSERROR) r_bpreverr; /* unload prev err into array */
g_errorptr[0] = (FSERROR) g_bpreverr; /* unload prev err into array */
b_errorptr[0] = (FSERROR) b_bpreverr; /* unload prev err into array */
cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
}
#ifdef XP_MAC
#ifndef powerc
#pragma peephole reset
#endif
#endif
/* END code adapted from jpeg library */

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,540 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* if.h --- Top-level image library internal routines
*
* $Id: if.h,v 3.5.18.1 1999-04-15 20:40:00 pnunn%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"
#ifdef STANDALONE_IMAGE_LIB
#include "xpcompat.h"
#else
#include "xp_mcom.h" /* XP definitions and types. */
#endif /* STANDALONE_IMAGE_LIB */
#include "ntypes.h" /* typedefs for commonly used Netscape data
structures */
#ifndef STANDALONE_IMAGE_LIB
#include "net.h"
#include "nsIImgDecoder.h"
#endif /* STANDALONE_IMAGE_LIB */
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"
#ifdef STANDALONE_IMAGE_LIB
#include "ilIImageRenderer.h"
//#include "nsIImgDecCB.h"
#endif /* STANDALONE_IMAGE_LIB */
/***************************** also in xpcompat.h ***********************/
#ifndef STANDALONE_IMAGE_LIB
PR_BEGIN_EXTERN_C
typedef void
(*TimeoutCallbackFunction) (void * closure);
extern void *
IL_SetTimeout(TimeoutCallbackFunction func, void * closure, uint32 msecs);
extern void
IL_ClearTimeout(void *timer_id);
PR_END_EXTERN_C
#endif
/********************************* in xpcompat.h *************************************/
#include "il.h"
/* For debugging counts of loading, looping and aborted images, needed for
group observer notification. */
/* #define DEBUG_GROUP_OBSERVER */
#ifdef DEBUG
#define Debug 1
#endif
#ifdef XP_WIN
#define _USD 1 /* scanlines upside-down */
#endif
extern PRLogModuleInfo *il_log_module;
#ifdef DEBUG
//#define ILTRACE(l,t) { if(il_debug>l) {PR_LOG(il_log_module, 1, t);} }
#define ILTRACE(l,t){}
#else
#define ILTRACE(l,t) {}
#endif
#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 uint8 *mask,
const uint8 *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)==NET_NORMAL_RELOAD) || ((reload_method)==NET_SUPER_RELOAD))
/* 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*/
uint32 hash;
uint32 urlhash;
enum icstate state;
int sized;
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. */
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;
uint32 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. */
intn type;
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;
uint8 *scalerow;
int pass; /* pass (scan #) of a multi-pass image.
Used for interlaced GIFs & p-JPEGs */
int forced;
uint32 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. */
#ifdef STANDALONE_IMAGE_LIB
ilIImageRenderer *img_cb;
#else
IMGCBIF *img_cb; /* JMC callback interface. */
#endif /* STANDALONE_IMAGE_LIB */
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 {
#ifdef STANDALONE_IMAGE_LIB
ilIImageRenderer *img_cb;
#else
IMGCBIF *img_cb; /* JMC callback interface to front ends. */
#endif /* STANDALONE_IMAGE_LIB */
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 uint8 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);
#ifndef M12N_NEW_DEPENDENCIES /* XXXM12N */
extern unsigned 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, int type);
#else
extern jint
il_write_ready(NET_StreamClass *stream, jint op, struct JMCException* *exceptionThrown);
extern jint
il_first_write(NET_StreamClass *stream, jint op, jbyte* str, jsize len,
struct JMCException* *exceptionThrown);
extern void
il_abort(NET_StreamClass *stream, jint op, jint status,
struct JMCException* *exceptionThrown);
extern void
il_stream_complete(NET_StreamClass *stream, jint op,
struct JMCException* *exceptionThrown);
#endif /* M12N_NEW_DEPENDENCIES */
extern int il_xbm_init(il_container *ic);
extern int il_xbm_write(il_container *, const uint8 *, int32);
extern void il_xbm_complete(il_container *ic);
extern void il_xbm_abort(il_container *ic);
/* 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 uint8* mask,
const uint8 *samp_in,
int x_offset,
uint8 XP_HUGE *samp_out,
int width);
extern void il_emit_row(il_container *ic, uint8 *buf, uint8 *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 void il_reset_palette(il_container *ic);
extern void il_reverse_bits(uint8 *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,
NET_ReloadMethod 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
#ifdef STANDALONE_IMAGE_LIB
il_destroy_pixmap(ilIImageRenderer *img_cb, IL_Pixmap *pixmap);
#else
il_destroy_pixmap(IMGCBIF *img_cb, IL_Pixmap *pixmap);
#endif /* STANDALONE_IMAGE_LIB */
extern uint32 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 void il_reduce_image_cache_size_to(uint32 new_size);
/************************ Image observer notifiers ***************************/
/* Notify observers of image progress. */
extern void
il_progress_notify(il_container *ic);
/* Notify observers that the image pixmap has been updated. */
extern void
il_pixmap_update_notify(il_container *ic);
/* Notify observers that the image has finished decoding. */
extern void
il_image_complete_notify(il_container *ic);
/* Notify observers that one frame of image/animation has finished decoding. */
extern void
il_frame_complete_notify(il_container *ic);
/* Notify observers of a cached image that has already completed decoding.
Note that this notification is per image request and not per image
container. */
extern void
il_cache_return_notify(IL_ImageReq *image_req);
/* Notify observers that the image request is being destroyed. This
provides an opportunity for observers to remove themselves from the
observer callback list and to do any related cleanup. */
extern void
il_image_destroyed_notify(IL_ImageReq *image_req);
/********************* Image group observer notifier *************************/
/* Notify observers that images have started/stopped loading in the context,
or started/stopped looping in the context. */
extern void
il_group_notify(IL_GroupContext *img_cx, XP_ObservableMsg message);
#endif /* _if_h */

View File

@@ -0,0 +1,166 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "if.h"
#include "ilINetReader.h"
static NS_DEFINE_IID(kINetReaderIID, IL_INETREADER_IID);
class NetReaderImpl : public ilINetReader {
public:
NetReaderImpl(il_container *aContainer);
virtual ~NetReaderImpl();
NS_DECL_ISUPPORTS
virtual unsigned int WriteReady();
virtual int FirstWrite(const unsigned char *str, int32 len);
virtual int Write(const unsigned char *str, int32 len);
virtual void StreamAbort(int status);
virtual void StreamComplete(PRBool is_multipart);
virtual void NetRequestDone(ilIURL *urls, int status);
virtual PRBool StreamCreated(ilIURL *urls, int type);
virtual PRBool IsMulti();
il_container *GetContainer() {return mContainer;}
private:
il_container *mContainer;
};
NetReaderImpl::NetReaderImpl(il_container *aContainer)
{
NS_INIT_REFCNT();
mContainer = aContainer;
}
NetReaderImpl::~NetReaderImpl()
{
}
NS_IMPL_ISUPPORTS(NetReaderImpl, kINetReaderIID)
unsigned int
NetReaderImpl::WriteReady()
{
if (mContainer != NULL) {
return IL_StreamWriteReady(mContainer);
}
else {
return 0;
}
}
int
NetReaderImpl::FirstWrite(const unsigned char *str, int32 len)
{
if (mContainer != NULL) {
return IL_StreamFirstWrite(mContainer, str, len);
}
else {
return 0;
}
}
int
NetReaderImpl::Write(const unsigned char *str, int32 len)
{
if (mContainer != NULL) {
return IL_StreamWrite(mContainer, str, len);
}
else {
return 0;
}
}
void
NetReaderImpl::StreamAbort(int status)
{
if (mContainer != NULL) {
IL_StreamAbort(mContainer, status);
}
}
void
NetReaderImpl::StreamComplete(PRBool is_multipart)
{
if (mContainer != NULL) {
IL_StreamComplete(mContainer, is_multipart);
}
}
void
NetReaderImpl::NetRequestDone(ilIURL *urls, int status)
{
if (mContainer != NULL) {
IL_NetRequestDone(mContainer, urls, status);
}
}
PRBool
NetReaderImpl::StreamCreated(ilIURL *urls, int type)
{
if (mContainer != NULL) {
return IL_StreamCreated(mContainer, urls, type);
}
else {
return PR_FALSE;
}
}
PRBool
NetReaderImpl::IsMulti()
{
if (mContainer != NULL) {
return (PRBool)(mContainer->multi > 0);
}
else {
return PR_FALSE;
}
}
ilINetReader *
IL_NewNetReader(il_container *ic)
{
ilINetReader *reader = new NetReaderImpl(ic);
if (reader != NULL) {
NS_ADDREF(reader);
}
return reader;
}
il_container *
IL_GetNetReaderContainer(ilINetReader *reader)
{
if (reader != NULL) {
return ((NetReaderImpl *)reader)->GetContainer();
}
else {
return NULL;
}
}

View File

@@ -0,0 +1,77 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 8 -*-
il_errp.h - Image Library error codes.
*/
#ifndef _IL_ERRORS_H
#define _IL_ERRORS_H
/* XXXM12N Old Netlib error codes used by Image Library. */
/*
* Return codes
*/
#define MK_INTERRUPTED -201
#define MK_IMAGE_LOSSAGE -277
#ifndef M12N /* XXXM12N */
#define MK_UNABLE_TO_CONVERT -208
#define MK_UNABLE_TO_LOGIN -210
#define MK_NO_NEWS_SERVER -224
#define MK_USE_FTP_INSTEAD -225
#define MK_USE_COPY_FROM_CACHE -226
#define MK_EMPTY_NEWS_LIST -227
#define MK_MAILTO_NOT_READY -228
#define MK_OBJECT_NOT_IN_CACHE -239
#define MK_UNABLE_TO_LISTEN_ON_SOCKET -244
#define MK_WAITING_FOR_LOOKUP -248 /* response for async dns */
#define MK_DO_REDIRECT -249 /* tells mkgeturl to redirect */
#define MK_MIME_NEED_B64 -270 /* used internally */
#define MK_MIME_NEED_QP -271 /* used internally */
#define MK_MIME_NEED_TEXT_CONVERTER -272 /* used internally */
#define MK_MIME_NEED_PS_CONVERTER -273 /* used internally */
#define MK_TOO_MANY_OPEN_FILES -310
#define MK_FILE_WRITE_ERROR -350
#define MK_GET_REST_OF_PARTIAL_FILE_FROM_NETWORK -399
#define MK_MULTIPART_MESSAGE_COMPLETED -437
/* success codes */
#define MK_DATA_LOADED 1
#define MK_NO_DATA 2
#define MK_NO_ACTION 3
#define MK_CHANGING_CONTEXT 4
#endif /* M12N */
#endif /* _IL_ERRORS_H */

View File

@@ -0,0 +1,506 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_util.c Colormap and colorspace utilities.
*
* $Id: il_util.cpp,v 3.1 1998-07-27 16:09:35 hardts%netscape.com Exp $
*/
#ifdef STANDALONE_IMAGE_LIB
#include "xpcompat.h"
#else
#include "xp_mcom.h" /* XP definitions and types. */
#endif
#include "ntypes.h" /* typedefs for commonly used Netscape data
structures. */
#ifndef STANDALONE_IMAGE_LIB
#include "xp_core.h"
#endif
#include "prtypes.h"
#include "prmem.h"
/* mwh this is for Win 16 comipler. */
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#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(uint32 red_size, uint32 green_size, uint32 blue_size,
uint32 base_offset)
{
uint8 r, g, b, map_index;
uint32 i, j, k, size, red_offset, green_offset, dmax_val;
uint32 trm1, tgm1, tbm1, dtrm1, dtgm1, dtbm1;
uint32 crm1, cgm1, cbm1, dcrm1, dcgm1, dcbm1;
uint8 *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 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 FALSE;
lookup_table = (uint8 *)PR_Calloc(LOOKUP_TABLE_SIZE, 1);
if (!lookup_table)
return FALSE;
done = (uint8 *)PR_Calloc(size, 1);
if (!done)
return 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 = CUBE_SCALE(i, dcrm1, trm1, dtrm1);
g = CUBE_SCALE(j, dcgm1, tgm1, dtgm1);
b = CUBE_SCALE(k, dcbm1, tbm1, dtbm1);
/* Compute the colormap index. */
map_index = 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 =
CUBE_SCALE(r, dmax_val, crm1, dcrm1);
map[map_index].green =
CUBE_SCALE(g, dmax_val, cgm1, dcgm1);
map[map_index].blue =
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, uint16 num_reserved_colors,
uint16 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);
/* 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, uint16 num_reserved_colors,
uint16 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 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 = num_colors;
cmap->num_colors++;
return 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, uint16 *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, uint8 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. */
XP_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, uint8 index_depth,
uint8 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. */
XP_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. */
IL_IMPLEMENT(IL_ColorSpace *)
IL_CreateGreyScaleColorSpace(uint8 index_depth, uint8 pixmap_depth)
{
IL_ColorSpace *color_space;
color_space = PR_NEWZAP(IL_ColorSpace);
if (!color_space)
return NULL;
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);
return NULL;
}
color_space->ref_count = 1;
return 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_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++;
}

View File

@@ -0,0 +1,78 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* -*- Mode: C; tab-width: 4 -*-
* il_utilp.h Colormap and colorspace utilities - types and definitions
* private to Image Library.
*
* $Id: il_utilp.h,v 3.2 1998-07-27 16:09:36 hardts%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
uint8 red, green, blue;
uint16 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
uintN. */
void *r8torgbn;
void *g8torgbn;
void *b8torgbn;
} il_ColorSpaceData;

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,192 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
#
#------------------------------------------------------------------------
#
# Makefile to build the IMGLIB LIB
#
#------------------------------------------------------------------------
!ifdef MOZ_JAVA
LOCAL_JMC_SUBDIR = .
!endif
#LIBRARY_NAME = img$(MOZ_BITS)
!ifndef STANDALONE_IMAGE_LIB
IMGSRC= $(DEPTH)\modules\libimg\src\_jmc
!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
!ifdef STANDALONE_IMAGE_LIB
LLIBS=$(DIST)\lib\png.lib \
$(LIBNSPR) \
$(LIBJPEG) \
$(DIST)\lib\plc3.lib \
$(DIST)\lib\util.lib \
$(DIST)\lib\zip$(MOZ_BITS)$(VERSION_NUMBER).lib \
$(DIST)\lib\xpcom32.lib \
!ifdef NU_CACHE
$(DIST)\lib\cache.lib \
!endif
$(NULL)
!else
LLIBS=$(DIST)\lib\png.lib \
$(NULL)
!endif
MISCDEP=$(LLIBS)
!ifndef STANDALONE_IMAGE_LIB
OBJS=.\$(OBJDIR)\MIMGCB.obj \
$(NULL)
CSRCS = \
_jmc\MIMGCB.c \
$(NULL)
!endif
#LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
!ifdef STANDALONE_IMAGE_LIB
LIBRARY_SUFFIX = $(MOZ_BITS)$(VERSION_NUMBER)
!else
LIBRARY_SUFFIX = $(MOZ_BITS)
!endif
!ifdef STANDALONE_IMAGE_LIB
MAKE_OBJ_TYPE=DLL
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
DLLNAME=img$(MOZ_BITS)$(VERSION_NUMBER)
DLL1NAME=img$(MOZ_BITS)$(VERSION_NUMBER)
PDBFILE=$(DLLNAME).pdb
MAPFILE=$(DLLNAME).map
!if "$(MOZ_BITS)" == "16"
DEFFILE=$(DLL1NAME).def
!endif
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
DLL=.\$(OBJDIR)\$(DLLNAME).dll
MAPFILE= $(DLLNAME).map
!endif
MODULE=img
DEPTH=..\..\..
LOCAL_INCLUDES=-I../png -I. -I$(DEPTH)/dist/public/zlib
LIBRARY_NAME=img
EXTRA_LIBS=$(DIST)/lib/libzlib.a $(DIST)/lib/libpng.a
### STANDALONE_IMAGE_LIB
!ifdef STANDALONE_IMAGE_LIB
CPPSRCS=color.cpp colormap.cpp dither.cpp gif.cpp if.cpp ilclient.cpp il_util.cpp \
ilNetReader.cpp jpeg.cpp scale.cpp xbm.cpp ipng.cpp png_png.cpp xpcompat.cpp
REQUIRES=zlib nspr jpeg util img png xpcom
CPP_OBJS=.\$(OBJDIR)\color.obj .\$(OBJDIR)\colormap.obj \
.\$(OBJDIR)\dither.obj .\$(OBJDIR)\gif.obj .\$(OBJDIR)\if.obj \
.\$(OBJDIR)\ilclient.obj .\$(OBJDIR)\il_util.obj \
.\$(OBJDIR)\ilNetReader.obj .\$(OBJDIR)\jpeg.obj \
.\$(OBJDIR)\scale.obj .\$(OBJDIR)\xbm.obj \
.\$(OBJDIR)\ipng.obj .\$(OBJDIR)\png_png.obj .\$(OBJDIR)\xpcompat.obj \
!if "$(MOZ_BITS)" != "16"
LINCS=-I$(XPDIST)\public\zlib -I$(XPDIST)\public\nspr \
-I$(XPDIST)\public\jpeg -I$(XPDIST)\public\util -I$(XPDIST)\public\img \
!ifdef NU_CACHE
-I$(XPDIST)\public\cache \
!endif
-I$(XPDIST)\public\png -I$(XPDIST)\public\xpcom \
-I$(XPDIST)\public\raptor
!endif
### non-STANDALONE_IMAGE_LIB
!else
CPPSRCS=color.cpp colormap.cpp dither.cpp dummy_nc.cpp external.cpp gif.cpp if.cpp \
ilclient.cpp il_util.cpp jpeg.cpp scale.cpp xbm.cpp ipng.cpp png_png.cpp ilNetReader.cpp
REQUIRES=jtools java zlib nspr dbm jpeg util img png layer js xpcom
EXPORTS=PIMGCB.h PPSIMGCB.h
JMC_HEADERS=$(JMC_GEN_DIR)\MIMGCB.h $(JMC_GEN_DIR)\MPSIMGCB.h
JMC_STUBS=$(JMC_GEN_DIR)\MIMGCB.c $(JMC_GEN_DIR)\MPSIMGCB.c
JMC_OBJS=.\$(OBJDIR)\MIMGCB.obj .\$(OBJDIR)\MPSIMGCB.obj
JMC_GEN=MIMGCB MPSIMGCB
JMC_GEN_FLAGS=-cimpl -noexc -module
CPP_OBJS=.\$(OBJDIR)\color.obj .\$(OBJDIR)\colormap.obj \
.\$(OBJDIR)\dither.obj .\$(OBJDIR)\dummy_nc.obj \
.\$(OBJDIR)\external.obj .\$(OBJDIR)\gif.obj .\$(OBJDIR)\if.obj \
.\$(OBJDIR)\ilclient.obj .\$(OBJDIR)\il_util.obj \
.\$(OBJDIR)\jpeg.obj .\$(OBJDIR)\scale.obj .\$(OBJDIR)\xbm.obj \
.\$(OBJDIR)\ipng.obj .\$(OBJDIR)\png_png.obj .\$(OBJDIR)\ilNetReader.obj
!if "$(MOZ_BITS)" != "16"
LINCS=-I$(XPDIST)\public\jtools -I$(XPDIST)\public\java \
-I$(XPDIST)\public\zlib -I$(XPDIST)\public\nspr \
-I$(XPDIST)\public\dbm -I$(XPDIST)\public\jpeg \
-I$(XPDIST)\public\util -I$(XPDIST)\public\img \
-I$(XPDIST)\public\png -I$(XPDIST)\public\layer \
!ifdef NU_CACHE
-I$(XPDIST)\public\cache \
!endif
-I$(XPDIST)\public\js -I$(XPDIST)\public\xpcom \
-I$(XPDIST)\public\raptor
!endif
!endif
include <$(DEPTH)\config\rules.mak>
!ifdef STANDALONE_IMAGE_LIB
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).lib $(DIST)\lib
!else
$(JMC_GEN_DIR)\MIMGCB.h: $(JMCSRCDIR)\IMGCB.class
$(JMC) -d $(JMC_GEN_DIR) -interface $(JMC_GEN_FLAGS) $(?F:.class=)
$(JMC_GEN_DIR)\MIMGCB.c: $(JMCSRCDIR)\IMGCB.class
$(JMC) -d $(JMC_GEN_DIR) -module $(JMC_GEN_FLAGS) $(?F:.class=)
$(JMC_GEN_DIR)\MPSIMGCB.h: $(JMCSRCDIR)\PSIMGCB.class
$(JMC) -d $(JMC_GEN_DIR) -interface $(JMC_GEN_FLAGS) $(?F:.class=)
$(JMC_GEN_DIR)\MPSIMGCB.c: $(JMCSRCDIR)\PSIMGCB.class
$(JMC) -d $(JMC_GEN_DIR) -module $(JMC_GEN_FLAGS) $(?F:.class=)
export:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
symbols::
@echo "LIBRARY_NAME is $(LIBRARY_NAME)"
@echo "LIBRARY is $(LIBRARY)"
!endif

View File

@@ -0,0 +1,163 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#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* progID);
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* mProgID;
};
/*---------------------*/
ImgFactoryImpl::ImgFactoryImpl(const nsCID &aClass,
const char* className,
const char* progID)
: mClassID(aClass), mClassName(className), mProgID(progID)
{
NS_INIT_REFCNT();
}
ImgFactoryImpl::~ImgFactoryImpl()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
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 *aProgID,
nsIFactory **aFactory)
{
if (! aFactory)
return NS_ERROR_NULL_POINTER;
ImgFactoryImpl* factory = new ImgFactoryImpl(aClass, aClassName, aProgID);
if (factory == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(factory);
*aFactory = factory;
return NS_OK;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,545 @@
/* -*- 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.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* 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"
#include "xp_mcom.h"
#include <stdlib.h>
/* BSDI did not have this header and we do not need it here. -slamm */
/* #include <search.h> */
#include "prlog.h"
#include "prmem.h"
#include "plstr.h"
#include "ilISystemServices.h"
extern ilISystemServices *il_ss;
PR_BEGIN_EXTERN_C
int MK_UNABLE_TO_LOCATE_FILE = -1;
int MK_OUT_OF_MEMORY = -2;
int XP_MSG_IMAGE_PIXELS = -7;
int XP_MSG_IMAGE_NOT_FOUND = -8;
int XP_MSG_XBIT_COLOR = -9;
int XP_MSG_1BIT_MONO = -10;
int XP_MSG_XBIT_GREYSCALE = -11;
int XP_MSG_XBIT_RGB = -12;
int XP_MSG_DECODED_SIZE = -13;
int XP_MSG_WIDTH_HEIGHT = -14;
int XP_MSG_SCALED_FROM = -15;
int XP_MSG_IMAGE_DIM = -16;
int XP_MSG_COLOR = -17;
int XP_MSG_NB_COLORS = -18;
int XP_MSG_NONE = -19;
int XP_MSG_COLORMAP = -20;
int XP_MSG_BCKDRP_VISIBLE = -21;
int XP_MSG_SOLID_BKGND = -22;
int XP_MSG_JUST_NO = -23;
int XP_MSG_TRANSPARENCY = -24;
int XP_MSG_COMMENT = -25;
int XP_MSG_UNKNOWN = -26;
int XP_MSG_COMPRESS_REMOVE = -27;
PR_END_EXTERN_C
char *XP_GetString(int i)
{
return ("XP_GetString replacement needed");
}
/* Mac's native qsort is broken, and uses this version here
for historical reasons. Mac should point at mozilla/lib/xp/xp_qsort.c
and mozilla/include/xp_qsort.h like the rest of the world. */
#if defined(XP_MAC)
/* prototypes for local routines */
static void shortsort(char *lo, char *hi, unsigned width,
int ( *comp)(const void *, const void *));
static void swap(char *p, char *q, unsigned int width);
/* this parameter defines the cutoff between using quick sort and
insertion sort for arrays; arrays with lengths shorter or equal to the
below value use insertion sort */
#define CUTOFF 8 /* testing shows that this is good value */
/***
*XP_QSORT(base, num, wid, comp) - quicksort function for sorting arrays
*
*Purpose:
* quicksort the array of elements
* side effects: sorts in place
*
*Entry:
* char *base = pointer to base of array
* unsigned num = number of elements in the array
* unsigned width = width in bytes of each array element
* int (*comp)() = pointer to function returning analog of strcmp for
* strings, but supplied by user for comparing the array elements.
* it accepts 2 pointers to elements and returns neg if 1<2, 0 if
* 1=2, pos if 1>2.
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
/* sort the array between lo and hi (inclusive) */
void XP_QSORT (
void *base,
size_t num,
size_t width,
int ( *comp)(const void *, const void *)
)
{
char *lo, *hi; /* ends of sub-array currently sorting */
char *mid; /* points to middle of subarray */
char *loguy, *higuy; /* traveling pointers for partition step */
unsigned size; /* size of the sub-array */
char *lostk[30], *histk[30];
int stkptr; /* stack for saving sub-array to be processed */
/* Note: the number of stack entries required is no more than
1 + log2(size), so 30 is sufficient for any array */
if (num < 2 || width == 0)
return; /* nothing to do */
stkptr = 0; /* initialize stack */
lo = (char*)base;
hi = (char *)base + width * (num-1); /* initialize limits */
/* this entry point is for pseudo-recursion calling: setting
lo and hi and jumping to here is like recursion, but stkptr is
prserved, locals aren't, so we preserve stuff on the stack */
recurse:
size = (hi - lo) / width + 1; /* number of el's to sort */
/* below a certain size, it is faster to use a O(n^2) sorting method */
if (size <= CUTOFF) {
shortsort(lo, hi, width, comp);
}
else {
/* First we pick a partititioning element. The efficiency of the
algorithm demands that we find one that is approximately the
median of the values, but also that we select one fast. Using
the first one produces bad performace if the array is already
sorted, so we use the middle one, which would require a very
wierdly arranged array for worst case performance. Testing shows
that a median-of-three algorithm does not, in general, increase
performance. */
mid = lo + (size / 2) * width; /* find middle element */
swap(mid, lo, width); /* swap it to beginning of array */
/* We now wish to partition the array into three pieces, one
consisiting of elements <= partition element, one of elements
equal to the parition element, and one of element >= to it. This
is done below; comments indicate conditions established at every
step. */
loguy = lo;
higuy = hi + width;
/* Note that higuy decreases and loguy increases on every iteration,
so loop must terminate. */
for (;;) {
/* lo <= loguy < hi, lo < higuy <= hi + 1,
A[i] <= A[lo] for lo <= i <= loguy,
A[i] >= A[lo] for higuy <= i <= hi */
do {
loguy += width;
} while (loguy <= hi && comp(loguy, lo) <= 0);
/* lo < loguy <= hi+1, A[i] <= A[lo] for lo <= i < loguy,
either loguy > hi or A[loguy] > A[lo] */
do {
higuy -= width;
} while (higuy > lo && comp(higuy, lo) >= 0);
/* lo-1 <= higuy <= hi, A[i] >= A[lo] for higuy < i <= hi,
either higuy <= lo or A[higuy] < A[lo] */
if (higuy < loguy)
break;
/* if loguy > hi or higuy <= lo, then we would have exited, so
A[loguy] > A[lo], A[higuy] < A[lo],
loguy < hi, highy > lo */
swap(loguy, higuy, width);
/* A[loguy] < A[lo], A[higuy] > A[lo]; so condition at top
of loop is re-established */
}
/* A[i] >= A[lo] for higuy < i <= hi,
A[i] <= A[lo] for lo <= i < loguy,
higuy < loguy, lo <= higuy <= hi
implying:
A[i] >= A[lo] for loguy <= i <= hi,
A[i] <= A[lo] for lo <= i <= higuy,
A[i] = A[lo] for higuy < i < loguy */
swap(lo, higuy, width); /* put partition element in place */
/* OK, now we have the following:
A[i] >= A[higuy] for loguy <= i <= hi,
A[i] <= A[higuy] for lo <= i < higuy
A[i] = A[lo] for higuy <= i < loguy */
/* We've finished the partition, now we want to sort the subarrays
[lo, higuy-1] and [loguy, hi].
We do the smaller one first to minimize stack usage.
We only sort arrays of length 2 or more.*/
if ( higuy - 1 - lo >= hi - loguy ) {
if (lo + width < higuy) {
lostk[stkptr] = lo;
histk[stkptr] = higuy - width;
++stkptr;
} /* save big recursion for later */
if (loguy < hi) {
lo = loguy;
goto recurse; /* do small recursion */
}
}
else {
if (loguy < hi) {
lostk[stkptr] = loguy;
histk[stkptr] = hi;
++stkptr; /* save big recursion for later */
}
if (lo + width < higuy) {
hi = higuy - width;
goto recurse; /* do small recursion */
}
}
}
/* We have sorted the array, except for any pending sorts on the stack.
Check if there are any, and do them. */
--stkptr;
if (stkptr >= 0) {
lo = lostk[stkptr];
hi = histk[stkptr];
goto recurse; /* pop subarray from stack */
}
else
return; /* all subarrays done */
}
/***
*shortsort(hi, lo, width, comp) - insertion sort for sorting short arrays
*
*Purpose:
* sorts the sub-array of elements between lo and hi (inclusive)
* side effects: sorts in place
* assumes that lo < hi
*
*Entry:
* char *lo = pointer to low element to sort
* char *hi = pointer to high element to sort
* unsigned width = width in bytes of each array element
* int (*comp)() = pointer to function returning analog of strcmp for
* strings, but supplied by user for comparing the array elements.
* it accepts 2 pointers to elements and returns neg if 1<2, 0 if
* 1=2, pos if 1>2.
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
static void shortsort (
char *lo,
char *hi,
unsigned width,
int ( *comp)(const void *, const void *)
)
{
char *p, *max;
/* Note: in assertions below, i and j are alway inside original bound of
array to sort. */
while (hi > lo) {
/* A[i] <= A[j] for i <= j, j > hi */
max = lo;
for (p = lo+width; p <= hi; p += width) {
/* A[i] <= A[max] for lo <= i < p */
if (comp(p, max) > 0) {
max = p;
}
/* A[i] <= A[max] for lo <= i <= p */
}
/* A[i] <= A[max] for lo <= i <= hi */
swap(max, hi, width);
/* A[i] <= A[hi] for i <= hi, so A[i] <= A[j] for i <= j, j >= hi */
hi -= width;
/* A[i] <= A[j] for i <= j, j > hi, loop top condition established */
}
/* A[i] <= A[j] for i <= j, j > lo, which implies A[i] <= A[j] for i < j,
so array is sorted */
}
/***
*swap(a, b, width) - swap two elements
*
*Purpose:
* swaps the two array elements of size width
*
*Entry:
* char *a, *b = pointer to two elements to swap
* unsigned width = width in bytes of each array element
*
*Exit:
* returns void
*
*Exceptions:
*
*******************************************************************************/
static void swap (
char *a,
char *b,
unsigned width
)
{
char tmp;
if ( a != b )
/* Do the swap one character at a time to avoid potential alignment
problems. */
while ( width-- ) {
tmp = *a;
*a++ = *b;
*b++ = tmp;
}
}
#endif /* XP_MAC */
#ifdef XP_MAC
#include <OSUtils.h>
static void MyReadLocation(MachineLocation * loc)
{
static MachineLocation storedLoc; // InsideMac, OSUtilities, page 4-20
static Boolean didReadLocation = FALSE;
if (!didReadLocation)
{
ReadLocation(&storedLoc);
didReadLocation = TRUE;
}
*loc = storedLoc;
}
// current local time = GMTDelta() + GMT
// GMT = local time - GMTDelta()
static long GMTDelta()
{
MachineLocation loc;
long gmtDelta;
MyReadLocation(&loc);
gmtDelta = loc.u.gmtDelta & 0x00FFFFFF;
if ((gmtDelta & 0x00800000) != 0)
gmtDelta |= 0xFF000000;
return gmtDelta;
}
// This routine simulates stdclib time(), time in seconds since 1.1.1970
// The time is in GMT
time_t GetTimeMac()
{
unsigned long maclocal;
// Get Mac local time
GetDateTime(&maclocal);
// Get Mac GMT
maclocal -= GMTDelta();
// return unix GMT
return (maclocal - UNIXMINUSMACTIME);
}
// Returns the GMT times
time_t Mactime(time_t *timer)
{
time_t t = GetTimeMac();
if (timer != NULL)
*timer = t;
return t;
}
#endif /* XP_MAC */
/* Allocate a new copy of a block of binary data, and returns it
*/
char *
NET_BACopy (char **destination, const char *source, size_t length)
{
if(*destination)
{
PR_FREEIF(*destination);
*destination = 0;
}
if (! source)
{
*destination = NULL;
}
else
{
*destination = (char *) PR_MALLOC (length);
if (*destination == NULL)
return(NULL);
XP_MEMCPY(*destination, source, length);
}
return *destination;
}
/* binary block Allocate and Concatenate
*
* destination_length is the length of the existing block
* source_length is the length of the block being added to the
* destination block
*/
char *
NET_BACat (char **destination,
size_t destination_length,
const char *source,
size_t source_length)
{
if (source)
{
if (*destination)
{
*destination = (char *) PR_REALLOC (*destination, destination_length + source_length);
if (*destination == NULL)
return(NULL);
XP_MEMMOVE (*destination + destination_length, source, source_length);
}
else
{
*destination = (char *) PR_MALLOC (source_length);
if (*destination == NULL)
return(NULL);
XP_MEMCPY(*destination, source, source_length);
}
}
return *destination;
}
/* Very similar to strdup except it free's too
*/
char *
NET_SACopy (char **destination, const char *source)
{
if(*destination)
{
PR_FREEIF(*destination);
*destination = 0;
}
if (! source)
{
*destination = NULL;
}
else
{
*destination = (char *) PR_MALLOC (PL_strlen(source) + 1);
if (*destination == NULL)
return(NULL);
PL_strcpy (*destination, source);
}
return *destination;
}
/* Again like strdup but it concatinates and free's and uses Realloc
*/
char *
NET_SACat (char **destination, const char *source)
{
if (source && *source)
{
if (*destination)
{
int length = PL_strlen (*destination);
*destination = (char *) PR_REALLOC (*destination, length + PL_strlen(source) + 1);
if (*destination == NULL)
return(NULL);
PL_strcpy (*destination + length, source);
}
else
{
*destination = (char *) PR_MALLOC (PL_strlen(source) + 1);
if (*destination == NULL)
return(NULL);
PL_strcpy (*destination, source);
}
}
return *destination;
}
NS_EXPORT void*
IL_SetTimeout(ilTimeoutCallbackFunction func, void * closure, uint32 msecs)
{
return il_ss->SetTimeout((ilTimeoutCallbackFunction)func,
closure, msecs);
}
NS_EXPORT void
IL_ClearTimeout(void *timer_id)
{
il_ss->ClearTimeout(timer_id);
}

Some files were not shown because too many files have changed in this diff Show More